Doh! Correct silly mistake regarding exception constructor!
[hgct.git] / ctcore.py
blobf6c6a3fc5502bf847192a626fc6b4c84d7073caa
1 import sys
2 DEBUG = 0
4 # PyQt3 and python 2.4 isn't currently available together on
5 # Debian/testing we do therefore use the following quite ugly work
6 # around. The module 'mysubprocess' is just a copy of the 'subprocess'
7 # module from the Python 2.4 distribution.
8 ver = sys.version_info
9 if ver[0] < 2 or (ver[0] == 2 and ver[1] <= 3):
10 import mysubprocess
11 subprocess = mysubprocess
12 else:
13 import subprocess
15 class File:
16 pass
18 class ProgramError(Exception):
19 def __init__(self, program, err):
20 Exception.__init__(self)
21 self.program = program
22 self.error = err
24 def runProgram(prog, input=None):
25 debug('runProgram prog: ' + str(prog) + " input: " + str(input))
26 if type(prog) is str:
27 progStr = prog
28 else:
29 progStr = ' '.join(prog)
31 try:
32 pop = subprocess.Popen(prog,
33 shell = type(prog) is str,
34 stderr=subprocess.STDOUT,
35 stdout=subprocess.PIPE,
36 stdin=subprocess.PIPE)
37 except OSError, e:
38 debug("strerror: " + e.strerror)
39 raise ProgramError(progStr, e.strerror)
41 if input != None:
42 pop.stdin.write(input)
43 pop.stdin.close()
45 out = pop.stdout.read()
46 code = pop.wait()
47 if code != 0:
48 debug("error output: " + out)
49 raise ProgramError(progStr, out)
50 debug("output: " + out.replace('\0', '\n'))
51 return out
53 def debug(str):
54 if DEBUG:
55 print str