5 from PyQt4.QtCore import *
6 from sface.sficonfig import config
8 def find_executable(exec_name):
9 """find the given executable in $PATH"""
10 paths = os.getenv("PATH").split(':')
12 exec_path = os.path.join(p, exec_name)
13 if os.path.exists(exec_path):
18 class SfiProcess(QObject):
19 def __init__(self, parent=None):
20 QObject.__init__(self, parent)
22 def __init_command(self, args):
23 self.args = QStringList()
25 self.args << QString(arg)
27 self.exe = find_executable("sfi.py")
29 print "FATAL.. Could not locate binary sfi.py - not much we can do without that"
31 self.process = QProcess()
33 self.connect(self.process, SIGNAL("finished(int, QProcess::ExitStatus)"),
36 def processFinished(self):
38 self.emit(SIGNAL("finished()"))
40 def __getRSpec(self, mgr):
41 slice = config.getSlice()
42 # Write RSpec to file for testing.
43 filename = os.path.expanduser("~/.sfi/" + slice + ".rspec")
48 args = ["-u", config.getUser(), "-a", config.getAuthority(),
49 "-r", config.getRegistry(), "-s", mgr, "resources",
50 "-o", filename, slice]
52 self.__init_command(args)
56 def getRSpecFromSM(self):
57 return self.__getRSpec(config.getSlicemgr())
59 def getRSpecFromAM(self):
60 return self.__getRSpec(config.getAggmgr())
62 def getRecord(self, hrn):
63 args = ["-u", config.getUser(), "-a", config.getAuthority(),
64 "-r", config.getRegistry(), "-s", config.getSlicemgr(), "show", hrn]
65 self.__init_command(args)
70 self.process.start(self.exe, self.args)
73 if self.process.state() == QProcess.NotRunning:
74 return self.process.readAll()
76 def trace_command (self):
78 self._trace=time.time()
79 command = "%s %s" % (self.exe, self.args.join(" "))
80 print time.strftime('%M:%S'),'Invoking',command
84 command = "%s %s" % (self.exe, self.args.join(" "))
85 print time.strftime('%M:%S'),"[%.3f s]"%(time.time()-self._trace),command,'Done'