2012-02-23 23:19:06 +01:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
2012-02-24 02:51:29 +01:00
|
|
|
try:
|
2012-02-25 23:16:23 +01:00
|
|
|
import json
|
2012-02-24 02:51:29 +01:00
|
|
|
except ImportError:
|
2012-02-25 23:16:23 +01:00
|
|
|
import simplejson as json
|
2012-02-24 10:35:51 +01:00
|
|
|
|
2012-02-23 23:19:06 +01:00
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
import datetime
|
2012-02-24 10:35:51 +01:00
|
|
|
import traceback
|
2012-02-23 23:19:06 +01:00
|
|
|
|
|
|
|
args = sys.argv[1:]
|
|
|
|
startd = datetime.datetime.now()
|
|
|
|
|
2012-02-24 10:35:51 +01:00
|
|
|
try:
|
|
|
|
cmd = subprocess.Popen(args, shell=False,
|
|
|
|
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
|
|
out, err = cmd.communicate()
|
2012-02-27 23:53:02 +01:00
|
|
|
except (OSError, IOError), e:
|
|
|
|
print json.dumps({
|
|
|
|
"failed": 1,
|
|
|
|
"error": str(e),
|
|
|
|
})
|
|
|
|
sys.exit(1)
|
2012-02-24 10:35:51 +01:00
|
|
|
except:
|
|
|
|
print json.dumps({
|
|
|
|
"failed" : 1,
|
|
|
|
"traceback" : traceback.format_exc()
|
|
|
|
})
|
|
|
|
sys.exit(1)
|
2012-02-23 23:19:06 +01:00
|
|
|
|
|
|
|
endd = datetime.datetime.now()
|
|
|
|
delta = endd - startd
|
|
|
|
|
|
|
|
result = {
|
|
|
|
"stdout" : out,
|
|
|
|
"stderr" : err,
|
|
|
|
"rc" : cmd.returncode,
|
|
|
|
"start" : str(startd),
|
|
|
|
"end" : str(endd),
|
|
|
|
"delta" : str(delta),
|
|
|
|
}
|
|
|
|
|
|
|
|
print json.dumps(result)
|