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