settings.py is a module now, make sure we "compile" it.
[hgct.git] / ctcore.py
blob7365ea818e28f9b8ffdc94d7a872beb3fd72de5c
1 import sys
3 applicationName = 'Commit Tool'
4 shortName = 'ct'
5 version = 'v0.1'
7 DEBUG = 0
9 # PyQt3 and python 2.4 isn't currently available together on
10 # Debian/testing we do therefore use the following quite ugly work
11 # around. The module 'mysubprocess' is just a copy of the 'subprocess'
12 # module from the Python 2.4 distribution.
13 ver = sys.version_info
14 if ver[0] < 2 or (ver[0] == 2 and ver[1] <= 3):
15 import mysubprocess
16 subprocess = mysubprocess
17 else:
18 import subprocess
20 class File:
21 pass
23 class ProgramError(Exception):
24 def __init__(self, program, err):
25 Exception.__init__(self)
26 self.program = program
27 self.error = err
29 def runProgram(prog, input=None):
30 debug('runProgram prog: ' + str(prog) + " input: " + str(input))
31 if type(prog) is str:
32 progStr = prog
33 else:
34 progStr = ' '.join(prog)
36 try:
37 pop = subprocess.Popen(prog,
38 shell = type(prog) is str,
39 stderr=subprocess.STDOUT,
40 stdout=subprocess.PIPE,
41 stdin=subprocess.PIPE)
42 except OSError, e:
43 debug("strerror: " + e.strerror)
44 raise ProgramError(progStr, e.strerror)
46 if input != None:
47 pop.stdin.write(input)
48 pop.stdin.close()
50 out = pop.stdout.read()
51 code = pop.wait()
52 if code != 0:
53 debug("error output: " + out)
54 raise ProgramError(progStr, out)
55 debug("output: " + out.replace('\0', '\n'))
56 return out
58 def debug(str):
59 if DEBUG:
60 print str