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.
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
18 applicationName
= 'Commit Tool'
27 from settings
import Settings
28 _settings
= Settings()
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):
40 subprocess
= mysubprocess
46 self
.listViewItem
= None
48 class ProgramError(Exception):
49 def __init__(self
, program
, err
):
50 Exception.__init
__(self
)
51 self
.program
= program
54 def runProgram(prog
, input=None, expectedexits
=[0]):
55 debug('runProgram prog: ' + str(prog
) + " input: " + str(input))
59 progStr
= ' '.join(prog
)
62 pop
= subprocess
.Popen(prog
,
63 shell
= type(prog
) is str,
64 stderr
=subprocess
.STDOUT
,
65 stdout
=subprocess
.PIPE
,
66 stdin
=subprocess
.PIPE
)
68 debug("strerror: " + e
.strerror
)
69 raise ProgramError(progStr
, e
.strerror
)
72 pop
.stdin
.write(input)
75 out
= pop
.stdout
.read()
77 if code
not in expectedexits
:
78 debug("error output: " + out
)
79 raise ProgramError(progStr
, out
)
80 debug("output: " + out
.replace('\0', '\n'))