3 from PyQt4.QtCore import *
4 from sface.sficonfig import config
6 def find_executable(exec_name):
7 """find the given executable in $PATH"""
8 paths = os.getenv("PATH").split(':')
10 exec_path = os.path.join(p, exec_name)
11 if os.path.exists(exec_path):
16 class SfiProcess(QObject):
17 def __init__(self, parent=None):
18 QObject.__init__(self, parent)
20 def __init_command(self, args):
21 self.args = QStringList()
23 self.args << QString(arg)
25 self.exe = find_executable("sfi.py")
26 self.process = QProcess()
28 self.connect(self.process, SIGNAL("finished(int, QProcess::ExitStatus)"),
31 def processFinished(self):
32 self.emit(SIGNAL("finished()"))
34 def __getRSpec(self, mgr):
35 slice = config.getSlice()
36 # Write RSpec to file for testing.
37 filename = os.path.expanduser("~/.sfi/" + slice + ".rspec")
42 args = ["-u", config.getUser(), "-a", config.getAuthority(),
43 "-r", config.registry(), "-s", mgr, "resources",
44 "-o", filename, slice]
46 self.__init_command(args)
50 def getRSpecFromSM(self):
51 return self.__getRSpec(config.slicemgr())
53 def getRSpecFromAM(self):
54 return self.__getRSpec(config.aggmgr())
56 def getRecord(self, hrn):
57 args = ["-u", config.getUser(), "-a", config.getAuthority(),
58 "-r", config.registry(), "-s", config.slicemgr(), "show", hrn]
59 self.__init_command(args)
63 self.process.start(self.exe, self.args)
66 if self.process.state() == QProcess.NotRunning:
67 return self.process.readAll()