X-Git-Url: http://git.onelab.eu/?p=sface.git;a=blobdiff_plain;f=sface%2Fsfiprocess.py;h=00f9df374e1e5c4d3c150d3b28dca48a83a494d6;hp=fac19db9192e6beb7241096326c6c55efca53151;hb=44743e4122a7a015518988f8b5ef07aca9a5f01e;hpb=b4479edcd8022bc11805758a575f7ca96dcdfc04 diff --git a/sface/sfiprocess.py b/sface/sfiprocess.py index fac19db..00f9df3 100644 --- a/sface/sfiprocess.py +++ b/sface/sfiprocess.py @@ -1,7 +1,9 @@ import os +import json import pickle import sys +import tempfile import time from PyQt4.QtCore import * @@ -13,7 +15,7 @@ def find_executable(exec_name): paths = os.getenv("PATH").split(':') for p in paths: exec_path = os.path.join(p, exec_name) - if os.path.exists(exec_path): + if os.path.exists(exec_path) and os.access(exec_path,os.X_OK): return exec_path return None @@ -35,6 +37,8 @@ class SfiProcess(QObject): # tracker. self.output = "" + self.do_raw = True # xxx should check version of sfa + self.connect(self.process, SIGNAL("readyReadStandardOutput()"), self.processStandardOutput) self.connect(self.process, SIGNAL("readyReadStandardError()"), @@ -50,6 +54,15 @@ class SfiProcess(QObject): # then to the users. self.args << QString('-D') + if self.do_raw: + self.raw_filename = tempfile.mktemp(suffix=".raw") + self.args << QString('-R') + self.args << QString(self.raw_filename) + self.args << QString('--rawformat') + self.args << QString('json') + else: + self.raw_filename = None + for arg in args: self.args << QString(arg) @@ -64,7 +77,15 @@ class SfiProcess(QObject): output = self.process.readAllStandardOutput() self.output = self.output + output if config.debug: - print output + try: + print output + except IOError, e: + if (e.errno == 4): + # XXX why is this happening?? + print "*** caught EINTR" + else: + raise + def processStandardError(self): print self.process.readAllStandardError() @@ -87,6 +108,22 @@ class SfiProcess(QObject): elif err == QProcess.UnknownError: print "UnknownError" + self.raw_data = None + if (self.raw_filename != None) and os.path.exists(self.raw_filename): + if hasattr(json, "loads"): + self.raw_data = json.loads(open(self.raw_filename,"r").read()) + else: + self.raw_data = json.read(open(self.raw_filename,"r").read()) + + os.remove(self.raw_filename) + + self.geni_code=None + self.geni_output=None + if (self.raw_data!=None) and (type(self.raw_data)==dict): + code = self.raw_data.get("code",{}) + self.geni_code = code.get("geni_code",None) + self.geni_output = self.raw_data.get("output","") + # extract any faults from the XMLRPC response(s) self.xmlrpcreader.responses = [] self.xmlrpcreader.store(self.output) @@ -94,6 +131,16 @@ class SfiProcess(QObject): self.responses = self.xmlrpcreader.responses self.faults = [x for x in self.responses if (x["kind"]=="fault")] + # if we got a nonzero + if (self.geni_code!=None) and (self.geni_code!=0): + x = {"kind": "bad_geni_code"} + x["faultCode"] = str(self.geni_code) + faultString = "Nonzero geni_code: " + str(self.geni_code) + if self.geni_output: + faultString = faultString + " output: " + str(self.geni_output) + x["faultString"] = faultString + self.faults.append(x) + self.trace_end() self.emit(SIGNAL("finished()"))