citool.py is no more
[hgct.git] / ctcore.py
blob2b96dbbd41b9af8ffb2b8abdd835a67c98a87840
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.3'
22 _settings = None
24 def settings():
25 global _settings
26 if not _settings:
27 from settings import Settings
28 _settings = Settings()
29 return _settings
31 DEBUG = 0
33 # PyQt3 and python 2.4 isn't currently available together on
34 # Debian/testing we do therefore use the following quite ugly work
35 # around. The module 'mysubprocess' is just a copy of the 'subprocess'
36 # module from the Python 2.4 distribution.
37 ver = sys.version_info
38 if ver[0] < 2 or (ver[0] == 2 and ver[1] <= 3):
39 import mysubprocess
40 subprocess = mysubprocess
41 else:
42 import subprocess
44 class File:
45 def __init__(self):
46 self.listViewItem = None
48 class ProgramError(Exception):
49 def __init__(self, program, err):
50 Exception.__init__(self)
51 self.program = program
52 self.error = err
54 def runProgram(prog, input=None, expectedexits=[0]):
55 debug('runProgram prog: ' + str(prog) + " input: " + str(input))
56 if type(prog) is str:
57 progStr = prog
58 else:
59 progStr = ' '.join(prog)
61 try:
62 pop = subprocess.Popen(prog,
63 shell = type(prog) is str,
64 stderr=subprocess.STDOUT,
65 stdout=subprocess.PIPE,
66 stdin=subprocess.PIPE)
67 except OSError, e:
68 debug("strerror: " + e.strerror)
69 raise ProgramError(progStr, e.strerror)
71 if input != None:
72 pop.stdin.write(input)
73 pop.stdin.close()
75 out = pop.stdout.read()
76 code = pop.wait()
77 if code not in expectedexits:
78 debug("error output: " + out)
79 raise ProgramError(progStr, out)
80 debug("output: " + out.replace('\0', '\n'))
81 return out
83 def debug(str):
84 if DEBUG:
85 print str