Package linspector :: Package lib :: Package core :: Module command
[hide private]
[frames] | no frames]

Source Code for Module linspector.lib.core.command

 1  import subprocess as sp 
 2  from subprocess import Popen 
 3  from subprocess import CalledProcessError 
 4  from datetime import datetime as dt 
 5   
 6   
7 -class Command:
8 - def __init__(self, command, log):
9 self.command = command 10 self.log = log 11 self.output = None 12 self.error = None 13 self.retcode = 0 14 self.commandStart = 0
15
16 - def __str__(self):
17 return self.command
18
19 - def call(self):
20 21 # self.commandStart = dt.now() 22 # "called at: " 23 # process = sp.Popen(stdout=PIPE, *popenargs, **kwargs) 24 # self.output, self.error = process.communicate() 25 # self.retcode = process.poll() 26 27 try: 28 self.commandStart = dt.now() 29 self.log.i("calling command " + str(self.command) + " at " + str(self.commandStart)) 30 #self.output=sp.check_output(self.command.split()) 31 process = Popen(self.command, stdout=sp.PIPE, stderr=sp.PIPE, shell=True) 32 self.output, self.error = process.communicate() 33 self.log.d(str(self.output)) 34 self.log.d(str(self.error)) 35 self.retcode = process.poll() 36 except CalledProcessError: 37 self.error = CalledProcessError.output 38 self.retcode = CalledProcessError.returncode
39
40 - def getOutput(self):
41 return self.output
42
43 - def getError(self):
44 return self.error
45
46 - def getAllOutput(self):
47 return str(self.output) + str(self.error) + str(self.retcode)
48
49 - def getReturnCode(self):
50 return self.retcode
51