[bonfiredemokit] Annotation of /virt-cluster/vc/vcutil.py
Annotation of /virt-cluster/vc/vcutil.py
Parent Directory
| Revision Log
Revision 1 -
(view)
(download)
(as text)
1 : |
agomez |
1 |
import subprocess
|
2 : |
|
|
|
3 : |
|
|
class CommandError(subprocess.CalledProcessError):
|
4 : |
|
|
def __init__(self,retcode,command,output):
|
5 : |
|
|
subprocess.CalledProcessError.__init__(self,retcode,command)
|
6 : |
|
|
self.output=output
|
7 : |
|
|
def __str__(self):
|
8 : |
|
|
return "Command '%s' returned non-zero exit status %d:\n%s" % (self.cmd, self.returncode,self.output)
|
9 : |
|
|
|
10 : |
|
|
def execute(command, ignore_error = False, fork = False ):
|
11 : |
|
|
stdout = subprocess.PIPE
|
12 : |
|
|
stderr = subprocess.STDOUT
|
13 : |
|
|
if fork:
|
14 : |
|
|
stdout = None
|
15 : |
|
|
stderr = None
|
16 : |
|
|
process=subprocess.Popen(command,stdout=stdout,stderr=stderr,shell=True, universal_newlines = True,executable="/bin/bash")
|
17 : |
|
|
if fork:
|
18 : |
|
|
return None
|
19 : |
|
|
output = process.communicate()
|
20 : |
|
|
retcode = process.poll()
|
21 : |
|
|
if retcode and not ignore_error:
|
22 : |
|
|
raise CommandError(retcode, command, output[0])
|
23 : |
|
|
return output
|
|