5 from PyQt4.QtCore import *
6 from sface.config 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)
68 def applyRSpec(self, rspec):
69 filename = config.getSliceRSpecFile() + "_new"
71 args = ["-u", config.getUser(), "-a", config.getAuthority(),
72 "-r", config.getRegistry(), "-s", config.getSlicemgr(), "create",
73 config.getSlice(), filename]
74 self.__init_command(args)
80 self.process.start(self.exe, self.args)
83 if self.process.state() == QProcess.NotRunning:
84 return self.process.readAll()
86 def trace_command (self):
88 self._trace=time.time()
89 command = "%s %s" % (self.exe, self.args.join(" "))
90 print time.strftime('%M:%S'),'Invoking',command
94 command = "%s %s" % (self.exe, self.args.join(" "))
95 print time.strftime('%M:%S'),"[%.3f s]"%(time.time()-self._trace),command,'Done'