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'
28 from settings
import Settings
29 _settings
= Settings()
34 # PyQt3 and python 2.4 isn't currently available together on
35 # Debian/testing we do therefore use the following quite ugly work
36 # around. The module 'mysubprocess' is just a copy of the 'subprocess'
37 # module from the Python 2.4 distribution.
38 ver
= sys
.version_info
39 if ver
[0] < 2 or (ver
[0] == 2 and ver
[1] <= 3):
41 subprocess
= mysubprocess
47 self
.listViewItem
= None
49 class ProgramError(Exception):
50 def __init__(self
, progStr
, error
):
51 self
.progStr
= progStr
55 return self
.progStr
+ ': ' + self
.error
57 def runProgram(prog
, input=None, expectedexits
=[0]):
58 debug('runProgram prog: ' + str(prog
) + " input: " + str(input))
62 progStr
= ' '.join(prog
)
65 pop
= subprocess
.Popen(prog
,
66 shell
= type(prog
) is str,
67 stderr
=subprocess
.STDOUT
,
68 stdout
=subprocess
.PIPE
,
69 stdin
=subprocess
.PIPE
)
71 debug("strerror: " + e
.strerror
)
72 raise ProgramError(progStr
, e
.strerror
)
75 pop
.stdin
.write(input)
78 out
= pop
.stdout
.read()
80 if code
not in expectedexits
:
81 debug("error output: " + out
)
82 raise ProgramError(progStr
, out
)
83 debug("output: " + out
.replace('\0', '\n'))