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")
28 self.process = QProcess()
30 self.connect(self.process, SIGNAL("finished(int, QProcess::ExitStatus)"),
33 def processFinished(self):
35 self.emit(SIGNAL("finished()"))
37 def __getRSpec(self, mgr):
38 slice = config.getSlice()
39 # Write RSpec to file for testing.
40 filename = os.path.expanduser("~/.sfi/" + slice + ".rspec")
45 args = ["-u", config.getUser(), "-a", config.getAuthority(),
46 "-r", config.registry(), "-s", mgr, "resources",
47 "-o", filename, slice]
49 self.__init_command(args)
53 def getRSpecFromSM(self):
54 return self.__getRSpec(config.slicemgr())
56 def getRSpecFromAM(self):
57 return self.__getRSpec(config.aggmgr())
59 def getRecord(self, hrn):
60 args = ["-u", config.getUser(), "-a", config.getAuthority(),
61 "-r", config.registry(), "-s", config.slicemgr(), "show", hrn]
62 self.__init_command(args)
67 self.process.start(self.exe, self.args)
70 if self.process.state() == QProcess.NotRunning:
71 return self.process.readAll()
73 def trace_command (self):
74 if config.SFACE_VERBOSE:
75 self._trace=time.time()
76 command = "%s %s" % (self.exe, self.args.join(" "))
77 print time.strftime('%M:%S'),'Invoking',command
80 if config.SFACE_VERBOSE:
81 command = "%s %s" % (self.exe, self.args.join(" "))
82 print time.strftime('%M:%S'),"[%.3f s]"%(time.time()-self._trace),command,'Done'