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.finished = pyqtSignal()
29 self.connect(self.process, SIGNAL("finished(int, QProcess::ExitStatus)"),
32 def __getRSpec(self, mgr):
33 slice = config.getSlice()
34 # Write RSpec to file for testing.
35 filename = os.path.expanduser("~/.sfi/" + slice + ".rspec")
40 args = ["-u", config.getUser(), "-a", config.getAuthority(),
41 "-r", config.registry(), "-s", mgr, "resources",
42 "-o", filename, slice]
44 self.__init_command(args)
48 def getRSpecFromSM(self):
49 return self.__getRSpec(config.slicemgr())
51 def getRSpecFromAM(self):
52 return self.__getRSpec(config.aggmgr())
54 def getRecord(self, hrn):
55 args = ["-u", config.getUser(), "-a", config.getAuthority(),
56 "-r", config.registry(), "-s", config.slicemgr(), "show", hrn]
57 self.__init_command(args)
61 self.process.start(self.exe, self.args)
64 if self.process.state() == QProcess.NotRunning:
65 return self.process.readAll()