Jonatan Antoni | 8105ff9 | 2017-09-12 13:54:40 +0200 | [diff] [blame] | 1 | #! python |
| 2 | |
| 3 | from subprocess import call, Popen |
| 4 | from tempfile import TemporaryFile |
| 5 | |
| 6 | class BuildCmd: |
| 7 | def __init__(self): |
| 8 | self._result = -1 |
| 9 | self._output = TemporaryFile(mode="r+") |
| 10 | |
| 11 | def getCommand(self): |
| 12 | raise NotImplementedError |
| 13 | |
| 14 | def getArguments(self): |
| 15 | return [] |
| 16 | |
| 17 | def getOutput(self): |
| 18 | return self._output |
| 19 | |
| 20 | def getLog(self): |
| 21 | return None |
| 22 | |
| 23 | def isSuccess(self): |
| 24 | return self._output == 0 |
| 25 | |
| 26 | def run(self): |
| 27 | cmd = [ self.getCommand() ] + self.getArguments() |
| 28 | print "Running: " + ' '.join(cmd) |
| 29 | try: |
| 30 | self._result = call(cmd, stdout = self._output) |
| 31 | except: |
| 32 | print "Fatal error!" |
| 33 | self._output.seek(0) |
| 34 | print self._output.read() |
| 35 | |
| 36 | logfile = self.getLog() |
| 37 | if logfile != None: |
| 38 | print logfile.read() |
| 39 | |
| 40 | print "Command returned: {0}".format(self._result) |
| 41 | |
| 42 | return self._result |
| 43 | |