The broken fix for A instead of N on new files got lost in the hgct merge.
[hgct.git] / ctcore.py
blob20208b33c50573129fe75d0caa352fd97127ebde
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 self.program = program
21 self.error = err
23 def runProgram(prog, input=None):
24 if type(prog) is str:
25 progStr = prog
26 else:
27 progStr = ' '.join(prog)
28 try:
29 pop = subprocess.Popen(progStr,
30 shell = 1,
31 stderr=subprocess.STDOUT,
32 stdout=subprocess.PIPE,
33 stdin=subprocess.PIPE)
34 except OSError, e:
35 debug("strerror: " + e.strerror)
36 raise ProgramError(progStr, e.strerror)
38 if input != None:
39 pop.stdin.write(input)
40 pop.stdin.close()
42 out = pop.stdout.read()
43 code = pop.wait()
44 if code != 0:
45 debug("error output: " + out)
46 raise ProgramError(progStr, out)
47 debug("output: " + out.replace('\0', '\n'))
48 return out
50 def debug(str):
51 if DEBUG:
52 print str