]> begriffs open source - cmsis/blob - CMSIS/CoreValidation/Tests/buildutils/buildcmd.py
CoreValidation: Enhanced automated build with rtebuild.
[cmsis] / CMSIS / CoreValidation / Tests / buildutils / buildcmd.py
1 #! python
2
3 import os
4 import shutil
5 from subprocess import call, Popen
6 from tempfile import TemporaryFile
7
8 class BuildCmd:
9   def __init__(self):
10     self._result = -1
11     self._output = TemporaryFile(mode="r+")
12   
13   def getCommand(self):
14     raise NotImplementedError
15     
16   def getArguments(self):
17     return []
18     
19   def needsShell(self):
20     return False
21     
22   def getOutput(self):
23     return self._output
24
25   def getLog(self):
26     return None
27     
28   def isSuccess(self):
29     return self._output == 0
30
31   def run(self):  
32     cmd = [ os.path.normpath(shutil.which(self.getCommand())) ] + self.getArguments()
33     print("Running: " + ' '.join(cmd))
34     try:
35       with Popen(cmd, stdout = self._output, stderr = self._output, shell=self.needsShell()) as proc:
36         self._result = proc.wait()
37     except:
38       print("Fatal error!")
39     self._output.seek(0)
40     print(self._output.read())
41     
42     logfile = self.getLog()
43     if logfile != None:
44       print(logfile.read())
45       
46     print("Command returned: {0}".format(self._result))
47       
48     return self._result
49     
50   def skip(self):
51     self._result = 0
52