X-Git-Url: http://git.onelab.eu/?p=sface.git;a=blobdiff_plain;f=sface%2Fsfiprocess.py;h=a9ac7692e7ae78f2c67faeb34e04a4fe64cd2939;hp=ba9a5c832636ae9073fc47f02fcdf022ac70bf31;hb=6a0d39ba688df2efbbf1d21d367200378f09f4a3;hpb=e095c7423002644d129cef273f3a63646903b788 diff --git a/sface/sfiprocess.py b/sface/sfiprocess.py index ba9a5c8..a9ac769 100644 --- a/sface/sfiprocess.py +++ b/sface/sfiprocess.py @@ -1,6 +1,10 @@ +import os +import sys +import time + from PyQt4.QtCore import * -from sface.sficonfig import config +from sface.config import config def find_executable(exec_name): """find the given executable in $PATH""" @@ -16,17 +20,56 @@ class SfiProcess(QObject): def __init__(self, parent=None): QObject.__init__(self, parent) - def __init_command(self, args) + env = QProcess.systemEnvironment() + env << "PYTHONPATH=%s" % ":".join(sys.path) + self.process = QProcess() + self.process.setEnvironment(env) + self.connect(self.process, SIGNAL("finished(int, QProcess::ExitStatus)"), + self.processFinished) + self.connect(self.process, SIGNAL("readyReadStandardOutput()"), + self.processStandardOutput) + self.connect(self.process, SIGNAL("readyReadStandardError()"), + self.processStandardError) + + def __init_command(self, args): self.args = QStringList() for arg in args: self.args << QString(arg) self.exe = find_executable("sfi.py") - self.process = QProcess() + if not self.exe: + print "FATAL.. Could not locate binary sfi.py - not much we can do without that" - finished = pyqtSignal() - self.connect(self.process, SIGNAL("finished(int, QProcess::ExitStatus)"), - self.finished) + def isRunning(self): + return self.process.state() != QProcess.NotRunning + + def processStandardOutput(self): + output = self.process.readAllStandardOutput() + if config.debug: + print output + + def processStandardError(self): + print self.process.readAllStandardError() + + def processFinished(self): + if self.process.exitStatus() == QProcess.CrashExit: + print self.readOutput() + print "Process exited with errors:", + err = self.process.error() + if err == QProcess.FailedToStart: + print "FailedToStart" + elif err == QProcess.Crashed: + print "Crashed" + elif err == QProcess.Timedout: + print "Timedout" + elif err == QProcess.WriteError: + print "WriteError" + elif err == QProcess.ReadError: + print "ReadError" + elif err == QProcess.UnknownError: + print "UnknownError" + self.trace_end() + self.emit(SIGNAL("finished()")) def __getRSpec(self, mgr): slice = config.getSlice() @@ -37,7 +80,7 @@ class SfiProcess(QObject): except: pass args = ["-u", config.getUser(), "-a", config.getAuthority(), - "-r", config.registry(), "-s", mgr, "resources", + "-r", config.getRegistry(), "-s", mgr, "resources", "-o", filename, slice] self.__init_command(args) @@ -45,21 +88,42 @@ class SfiProcess(QObject): return filename def getRSpecFromSM(self): - return self.__getRSpec(config.slicemgr()) + return self.__getRSpec(config.getSlicemgr()) def getRSpecFromAM(self): - return self.__getRSpec(config.aggmgr()) + return self.__getRSpec(config.getAggmgr()) def getRecord(self, hrn): args = ["-u", config.getUser(), "-a", config.getAuthority(), - "-r", config.registry(), "-s", config.slicemgr(), "show", hrn] + "-r", config.getRegistry(), "-s", config.getSlicemgr(), "show", hrn] self.__init_command(args) self.start() + def applyRSpec(self, rspec): + filename = config.getSliceRSpecFile() + "_new" + rspec.save(filename) + args = ["-u", config.getUser(), "-a", config.getAuthority(), + "-r", config.getRegistry(), "-s", config.getSlicemgr(), "create", + config.getSlice(), filename] + self.__init_command(args) + self.start() + return filename + def start(self): - self.process(self.exe, self.args) + self.trace_command() + self.process.start(self.exe, self.args) def readOutput(self): if self.process.state() == QProcess.NotRunning: return self.process.readAll() + def trace_command (self): + if config.verbose: + self._trace=time.time() + command = "%s %s" % (self.exe, self.args.join(" ")) + print time.strftime('%M:%S'),'Invoking',command + + def trace_end (self): + if config.verbose: + command = "%s %s" % (self.exe, self.args.join(" ")) + print time.strftime('%M:%S'),"[%.3f s]"%(time.time()-self._trace),command,'Done'