From: Barış Metin Date: Tue, 14 Sep 2010 13:26:01 +0000 (+0200) Subject: use a single sfiprocess object for all commands. X-Git-Tag: sface-0.1-1~38 X-Git-Url: http://git.onelab.eu/?p=sface.git;a=commitdiff_plain;h=4500c984c3e61d357e4d10a66f1ac135cf4f14c3 use a single sfiprocess object for all commands. --- diff --git a/sface/screens/mainscreen.py b/sface/screens/mainscreen.py index 41deacd..e2e90e6 100644 --- a/sface/screens/mainscreen.py +++ b/sface/screens/mainscreen.py @@ -273,7 +273,7 @@ class SliceWidget(QWidget): QWidget.__init__(self, parent) self.network_names = [] - self.process = None + self.process = SfiProcess(self) slicename = QLabel ("Slice : %s"%(config.getSlice() or "None"),self) slicename.setScaledContents(False) @@ -314,9 +314,38 @@ class SliceWidget(QWidget): self.connect(refresh, SIGNAL('clicked()'), self.refresh) self.connect(submit, SIGNAL('clicked()'), self.submit) self.connect(searchbox, SIGNAL('textChanged(QString)'), self.filter) + self.connect(self.process, SIGNAL('readyReadStandardOutput()'), self.processOutputReady) + self.connect(self.process, SIGNAL('readyReadStandardError()'), self.processOutputReady) self.updateView() + def processOutputReady(self): + self.parent().logWindow.setText(self.process.readOutput()) + + def submitFinished(self): + self.setStatus("Slice data submitted.") + QTimer.singleShot(1000, self.refresh) + + def refreshFinished(self): + self.setStatus("Slice data updated.", timeout=5000) + self.updateView() + + def readSliceRSpec(self): + rspec_file = config.getSliceRSpecFile() + if os.path.exists(rspec_file): + xml = open(rspec_file).read() + return xml + return None + + def setStatus(self, msg, timeout=None): + self.parent().setStatus(msg, timeout) + + def checkRunningProcess(self): + if self.process.isRunning(): + self.setStatus("There is already a process running. Please wait.") + return True + return False + def filter(self, filter_string): # for hierarchical models QSortFilterProxyModel applies the # sort recursively. if the parent doesn't match the criteria @@ -327,13 +356,10 @@ class SliceWidget(QWidget): self.filterModel.setFilterRegExp(QRegExp('|'.join(filters))) def submit(self): - xml = self.readSliceRSpec() - rspec = RSpec(xml) - - if self.process: - self.parent().setStatus("There is already a process running. Please wait.", - timeout=None) + if self.checkRunningProcess(): return + + rspec = RSpec(self.readSliceRSpec()) no_change = True all_child = self.nodeModel.rootItem.allChildItems() @@ -349,47 +375,31 @@ class SliceWidget(QWidget): rspec.remove_sliver(hostname) no_change = False - - self.process = SfiProcess() - outfile = self.process.applyRSpec(rspec) - self.parent().setStatus("Sending slice data (RSpec). This may take some time...", timeout=None) - - self.connect(self.process, SIGNAL('finished()'), self.submitFinished) + if no_change: + self.setStatus("No change in slice data. Not submitting!", timeout=3000) + return - def submitFinished(self): - del self.process - self.process = None - self.parent().setStatus("Slice data submitted.", timeout=None) - QTimer.singleShot(1000, self.refresh) + self.disconnect(self.process, SIGNAL('finished()'), self.refreshFinished) + self.connect(self.process, SIGNAL('finished()'), self.submitFinished) - def readSliceRSpec(self): - rspec_file = config.getSliceRSpecFile() - if os.path.exists(rspec_file): - xml = open(rspec_file).read() - return xml - return None + self.process.applyRSpec(rspec) + self.setStatus("Sending slice data (RSpec). This may take some time...") + def refresh(self): if not config.getSlice(): - self.parent().setStatus("Slice not set yet!", timeout=None) + self.setStatus("Slice not set yet!") return - if self.process: - self.parent().setStatus("There is already a process running. Please wait.", - timeout=None) + if self.process.isRunning(): + self.setStatus("There is already a process running. Please wait.") return - self.process = SfiProcess() - outfile = self.process.getRSpecFromSM() - self.parent().setStatus("Updating slice data. This may take some time...", timeout=None) - + self.disconnect(self.process, SIGNAL('finished()'), self.submitFinished) self.connect(self.process, SIGNAL('finished()'), self.refreshFinished) - def refreshFinished(self): - del self.process - self.process = None - self.parent().setStatus("Slice data updated.", timeout=5000) - self.updateView() + self.process.getRSpecFromSM() + self.setStatus("Updating slice data. This may take some time...") def updateView(self): global already_in_nodes