Create the 'hgct' symlink when we build the target 'all'.
[hgct.git] / ctcore.py
blobcdc90dab9fd6b2a58ec9a4904c8e44ba960ccfb1
1 # Copyright (c) 2005 Fredrik Kuivinen <freku045@student.liu.se>
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License version 2 as
5 # published by the Free Software Foundation.
6 #
7 # This program is distributed in the hope that it will be useful,
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 # GNU General Public License for more details.
12 # You should have received a copy of the GNU General Public License
13 # along with this program; if not, write to the Free Software
14 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 import sys
18 applicationName = 'Commit Tool'
19 shortName = 'ct'
20 version = 'v0.1'
22 DEBUG = 0
24 # PyQt3 and python 2.4 isn't currently available together on
25 # Debian/testing we do therefore use the following quite ugly work
26 # around. The module 'mysubprocess' is just a copy of the 'subprocess'
27 # module from the Python 2.4 distribution.
28 ver = sys.version_info
29 if ver[0] < 2 or (ver[0] == 2 and ver[1] <= 3):
30 import mysubprocess
31 subprocess = mysubprocess
32 else:
33 import subprocess
35 class File:
36 pass
38 class ProgramError(Exception):
39 def __init__(self, program, err):
40 Exception.__init__(self)
41 self.program = program
42 self.error = err
44 def runProgram(prog, input=None):
45 debug('runProgram prog: ' + str(prog) + " input: " + str(input))
46 if type(prog) is str:
47 progStr = prog
48 else:
49 progStr = ' '.join(prog)
51 try:
52 pop = subprocess.Popen(prog,
53 shell = type(prog) is str,
54 stderr=subprocess.STDOUT,
55 stdout=subprocess.PIPE,
56 stdin=subprocess.PIPE)
57 except OSError, e:
58 debug("strerror: " + e.strerror)
59 raise ProgramError(progStr, e.strerror)
61 if input != None:
62 pop.stdin.write(input)
63 pop.stdin.close()
65 out = pop.stdout.read()
66 code = pop.wait()
67 if code != 0:
68 debug("error output: " + out)
69 raise ProgramError(progStr, out)
70 debug("output: " + out.replace('\0', '\n'))
71 return out
73 def debug(str):
74 if DEBUG:
75 print str