add status label to mainscreen.
authorBarış Metin <Talip-Baris.Metin@sophia.inria.fr>
Thu, 9 Sep 2010 18:19:42 +0000 (20:19 +0200)
committerBarış Metin <Talip-Baris.Metin@sophia.inria.fr>
Thu, 9 Sep 2010 18:19:42 +0000 (20:19 +0200)
start running processes in background and update status accordingly.

sface/screens/mainscreen.py
sface/sfahelper.py
sface/sfiprocess.py

index 6d32a80..9b834fa 100644 (file)
@@ -1,9 +1,12 @@
 
 
+import os
 from PyQt4.QtCore import *
 from PyQt4.QtGui import *
 
 from PyQt4.QtCore import *
 from PyQt4.QtGui import *
 
+from sfa.util.rspecHelper import RSpec
 from sface.sfahelper import *
 from sface.sficonfig import config
 from sface.sfahelper import *
 from sface.sficonfig import config
+from sface.sfiprocess import SfiProcess
 from sface.screens.sfascreen import SfaScreen
 
 
 from sface.screens.sfascreen import SfaScreen
 
 
@@ -28,6 +31,8 @@ class SliceWidget(QWidget):
         slicename = QLabel ("Slice : %s"%(config.getSlice() or "None"),self)
         slicename.setScaledContents(False)
 
         slicename = QLabel ("Slice : %s"%(config.getSlice() or "None"),self)
         slicename.setScaledContents(False)
 
+        self.status = QLabel("")
+
         hlayout = QHBoxLayout()
         hlayout.addWidget(slicename)
         hlayout.addStretch()
         hlayout = QHBoxLayout()
         hlayout.addWidget(slicename)
         hlayout.addStretch()
@@ -36,25 +41,40 @@ class SliceWidget(QWidget):
         layout = QVBoxLayout()
         layout.addLayout(hlayout)
         layout.addWidget(self.nodeView)
         layout = QVBoxLayout()
         layout.addLayout(hlayout)
         layout.addWidget(self.nodeView)
+        layout.addWidget(self.status)
         self.setLayout(layout)
         self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
 
         self.connect(refresh, SIGNAL('linkActivated(QString)'), self.refresh)
         self.setLayout(layout)
         self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
 
         self.connect(refresh, SIGNAL('linkActivated(QString)'), self.refresh)
+
+        rspec_file = os.path.expanduser("~/.sfi/%s.rspec" % config.getSlice())
+        if os.path.exists(rspec_file):
+            self.updateView()
         
         
+    def readSliceRSpec(self):
+        rspec_file = os.path.expanduser("~/.sfi/%s.rspec" % config.getSlice())
+        xml = open(rspec_file).read()
+        return xml
 
     def refresh(self, link=None):
 
     def refresh(self, link=None):
-        data = SfaData()
-        if not data.getSlice(): 
-            print 'slice not set yet'
+        if not config.getSlice():
+            self.status.setText("Slice not set yet!")
             return
             return
-        if not data.SFACE_DEBUG:
-            rspec_string = data.getRSpecFromSM()
-        else:
-            print 'SFACE_DEBUG : using local file'
-            import os
-            rspec_string = open(os.path.expanduser("~/.sfi/%s.rspec"%data.getSlice())).read()
-
-        networks = self.rspec_get_networks(rspec_string)
+
+        self.process = SfiProcess()
+        outfile = self.process.getRSpecFromSM()
+        self.status.setText("Updating slice data. This may take some time...")
+        
+        self.connect(self.process, SIGNAL('finished()'), self.refreshFinished)
+
+    def refreshFinished(self):
+        del self.process
+        self.status.setText("Slice data updated.")
+        self.updateView()
+
+    def updateView(self):
+        rspec_string = self.readSliceRSpec()
+        networks = rspec_get_networks(rspec_string)
         networks.reverse()
 
         for network in networks:
         networks.reverse()
 
         for network in networks:
@@ -63,15 +83,15 @@ class SliceWidget(QWidget):
 #            nodes = self.rspec_get_other_nodes_from_network(rspec_string, network)
 #            for node in nodes: self.addNode(network, node, False)
             # hacky - i'm just gettin used to this xml navigation stuff
 #            nodes = self.rspec_get_other_nodes_from_network(rspec_string, network)
 #            for node in nodes: self.addNode(network, node, False)
             # hacky - i'm just gettin used to this xml navigation stuff
-            xml_nodes = self.rspec_get_xml_nodes_from_network(rspec_string, network)
+            xml_nodes = rspec_get_xml_nodes_from_network(rspec_string, network)
             from lxml import etree
             # addNode inserts before, so let's start with the ones that are not in
             for xml_node in xml_nodes:
                 if not xml_node.xpath('sliver'): 
             from lxml import etree
             # addNode inserts before, so let's start with the ones that are not in
             for xml_node in xml_nodes:
                 if not xml_node.xpath('sliver'): 
-                    self.addNode(network,xml_node.xpath('hostname/text()')[0],False)
+                    self.addNode(network, xml_node.xpath('hostname/text()')[0],False)
             for xml_node in xml_nodes:
                 if xml_node.xpath('sliver'): 
             for xml_node in xml_nodes:
                 if xml_node.xpath('sliver'): 
-                    self.addNode(network,xml_node.xpath('hostname/text()')[0],True)
+                    self.addNode(network, xml_node.xpath('hostname/text()')[0],True)
                 
 
     def addNode(self, testbed, hostname, mark):
                 
 
     def addNode(self, testbed, hostname, mark):
index 53cf351..dd26f74 100644 (file)
@@ -6,22 +6,22 @@ from sfa.util.rspecHelper import RSpec
 
     
 # TODO: already merged in sfa-trunk. Use the one there
 
     
 # TODO: already merged in sfa-trunk. Use the one there
-def rspec_get_networks(self, rspec_string):
+def rspec_get_networks(rspec_string):
     rspec = RSpec (rspec_string)
     return rspec.rspec.xpath("./network[@name]/@name")
 
 
 # TODO: already merged in sfa-trunk. Use the one there
     rspec = RSpec (rspec_string)
     return rspec.rspec.xpath("./network[@name]/@name")
 
 
 # TODO: already merged in sfa-trunk. Use the one there
-def rspec_get_xml_nodes_from_network(self, rspec_string, network):
+def rspec_get_xml_nodes_from_network(rspec_string, network):
     rspec = RSpec (rspec_string)
     return rspec.rspec.xpath("./network[@name='%s']/site/node" % network)
 
 
     rspec = RSpec (rspec_string)
     return rspec.rspec.xpath("./network[@name='%s']/site/node" % network)
 
 
-def rspec_get_sliver_nodes_from_network(self, rspec_string, network):
+def rspec_get_sliver_nodes_from_network(rspec_string, network):
     rspec = RSpec (rspec_string)
     return rspec.rspec.xpath("./network[@name='%s']/site/node[sliver]/hostname/text()" % network)
 
     rspec = RSpec (rspec_string)
     return rspec.rspec.xpath("./network[@name='%s']/site/node[sliver]/hostname/text()" % network)
 
-def rspec_get_other_nodes_from_network(self, rspec_string, network):
+def rspec_get_other_nodes_from_network(rspec_string, network):
     rspec = RSpec (rspec_string)
     # xxx todo - could not find the xpath syntax for 'does not have the sliver attribute'
     return rspec.rspec.xpath("./network[@name='%s']/site/node[~sliver]/hostname/text()" % network)
     rspec = RSpec (rspec_string)
     # xxx todo - could not find the xpath syntax for 'does not have the sliver attribute'
     return rspec.rspec.xpath("./network[@name='%s']/site/node[~sliver]/hostname/text()" % network)
index ba9a5c8..9fd56a9 100644 (file)
@@ -1,4 +1,5 @@
 
 
+import os
 from PyQt4.QtCore import *
 from sface.sficonfig import config
 
 from PyQt4.QtCore import *
 from sface.sficonfig import config
 
@@ -16,7 +17,7 @@ class SfiProcess(QObject):
     def __init__(self, parent=None):
         QObject.__init__(self, parent)
 
     def __init__(self, parent=None):
         QObject.__init__(self, parent)
 
-    def __init_command(self, args)
+    def __init_command(self, args):
         self.args = QStringList()
         for arg in args:
             self.args << QString(arg)
         self.args = QStringList()
         for arg in args:
             self.args << QString(arg)
@@ -24,7 +25,7 @@ class SfiProcess(QObject):
         self.exe = find_executable("sfi.py")
         self.process = QProcess()
 
         self.exe = find_executable("sfi.py")
         self.process = QProcess()
 
-        finished = pyqtSignal()
+        self.finished = pyqtSignal()
         self.connect(self.process, SIGNAL("finished(int, QProcess::ExitStatus)"),
                      self.finished)
 
         self.connect(self.process, SIGNAL("finished(int, QProcess::ExitStatus)"),
                      self.finished)
 
@@ -57,7 +58,7 @@ class SfiProcess(QObject):
         self.start()
 
     def start(self):
         self.start()
 
     def start(self):
-        self.process(self.exe, self.args)
+        self.process.start(self.exe, self.args)
 
     def readOutput(self):
         if self.process.state() == QProcess.NotRunning:
 
     def readOutput(self):
         if self.process.state() == QProcess.NotRunning: