initial commit
authorBarış Metin <Talip-Baris.Metin@sophia.inria.fr>
Wed, 8 Sep 2010 14:02:58 +0000 (16:02 +0200)
committerBarış Metin <Talip-Baris.Metin@sophia.inria.fr>
Wed, 8 Sep 2010 14:02:58 +0000 (16:02 +0200)
sface.bin [new file with mode: 0755]
sface.py [new file with mode: 0644]
sfaconfigscreen.py [new file with mode: 0644]
sfadata.py [new file with mode: 0644]
sfamainscreen.py [new file with mode: 0644]
sfascreen.py [new file with mode: 0644]
sfawindow.py [new file with mode: 0644]

diff --git a/sface.bin b/sface.bin
new file mode 100755 (executable)
index 0000000..f88969d
--- /dev/null
+++ b/sface.bin
@@ -0,0 +1,4 @@
+#!/bin/bash
+
+export PYTHONPATH=/opt/local/lib/python2.5/site-packages/
+exec python sface.py
diff --git a/sface.py b/sface.py
new file mode 100644 (file)
index 0000000..216a217
--- /dev/null
+++ b/sface.py
@@ -0,0 +1,18 @@
+import sys
+
+from PyQt4.QtGui import QApplication
+
+from sfawindow import SfaWindow
+
+
+def main(args):
+    app = QApplication(args)
+
+    win = SfaWindow()
+    win.show()
+
+    sys.exit(app.exec_())
+
+
+if __name__ == "__main__":
+    main(sys.argv)
diff --git a/sfaconfigscreen.py b/sfaconfigscreen.py
new file mode 100644 (file)
index 0000000..c176e22
--- /dev/null
@@ -0,0 +1,17 @@
+
+from PyQt4.QtGui import QWidget, QLabel
+
+from sfadata import SfaData
+from sfascreen import SfaScreen
+
+class ConfigWidget(QWidget):
+    def __init__(self, parent=None):
+        QWidget.__init__(self, parent)
+        label = QLabel("config widget", self)
+
+
+class SfaConfigScreen(SfaScreen):
+    def __init__(self, parent=None):
+        SfaScreen.__init__(self, parent)
+        config = ConfigWidget(self)
+        self.init(config, "Configure", "Configure the PlanetLab Federation GUI")
diff --git a/sfadata.py b/sfadata.py
new file mode 100644 (file)
index 0000000..433868e
--- /dev/null
@@ -0,0 +1,168 @@
+import os
+import re
+import time
+import subprocess
+from sfa.util.rspecHelper import RSpec
+
+class SfaData:
+    defaults = { 'SFI_AUTH' : None,
+                 'SFI_USER' : None,
+                 'SFI_SLICE' : None,
+                 'SFI_REGISTRY' : "http://www.planet-lab.org:12345",
+                 'SFI_SM' : "http://www.planet-lab.org:12346",
+                 'SFAUI_VERBOSE' : False,
+                 }
+
+    def __init__(self):
+        filename = os.path.expanduser("~/.sfi/sfi_config")
+        execfile(filename, SfaData.__dict__)
+        for (k,v) in SfaData.defaults.items():
+            if not hasattr(SfaData,k): setattr(SfaData,k,v)
+        if SfaData.SFAUI_VERBOSE:
+            print "After reading config from %s"%filename
+            for (k,v) in SfaData.defaults.items():
+                print "%-20s: %r"%(k,getattr(SfaData,k))
+
+    def getAuthority(self):
+        return SfaData.SFI_AUTH
+
+    def getUser(self):
+        return SfaData.SFI_USER
+
+    def setUser(self, user):
+        SfaData.SFI_USER = user
+
+        # Should probably get authority from user record instead...
+        a = user.split('.')
+        SfaData.SFI_AUTH = '.'.join(a[:len(a)-1])
+
+    def getSlice(self):
+        return SfaData.SFI_SLICE
+
+    def setSlice(self, slice):
+        SfaData.SFI_SLICE = slice
+
+    def registry(self):
+        return SfaData.SFI_REGISTRY
+
+    def slicemgr(self):
+        return SfaData.SFI_SM
+
+    def trace_command (self, command):
+        self._trace=time.time()
+        if self.SFAUI_VERBOSE:
+            print time.strftime('%M:%S'),'Invoking',' '.join(command)
+    def trace_end (self):
+        if self.SFAUI_VERBOSE:
+            print time.strftime('%M:%S'),"[%.3f s]"%(time.time()-self._trace),'Done'
+
+    def getRecord(self, hrn):
+        command = ["sfi.py", "-u", self.getUser(), "-a", self.getAuthority(), 
+                   "-r", self.registry(), "-s", self.slicemgr(), "show", hrn]
+        self.trace_command(command)
+        text = subprocess.Popen(command, stdout=subprocess.PIPE).communicate()[0]
+        self.trace_end()
+        return text
+
+    def listChildren(self, hrn):
+        children = []
+        command=["sfi.py", "-u", self.getUser(), "-a", self.getAuthority(), 
+                 "-r", self.registry(), "-s", self.slicemgr(), "list", hrn]
+        self.trace_command(command)
+        text = subprocess.Popen(command, stdout=subprocess.PIPE).communicate()[0]
+        self.trace_end()
+        lines = text.split('\n')
+        for line in lines:
+            if line:
+                (hrn, kind) = line.split() 
+                children.append((hrn, kind))
+                
+        return children
+
+    def getRSpec(self):
+        slice = self.getSlice()
+        # Write RSpec to file for testing.
+        filename = os.path.expanduser("~/.sfi/" + slice + ".rspec")
+        try:
+            os.remove(filename)
+        except:
+            pass
+        command=["sfi.py", "-u", self.getUser(), "-a", self.getAuthority(), 
+                 "-r", self.registry(), "-s", self.slicemgr(), "resources", 
+                 "-o", filename, slice]
+        self.trace_command(command)
+        subprocess.call(command)
+        self.trace_end()
+        f = open(filename, "r")
+        xml = f.read()
+        f.close()
+        return xml
+
+    def applyRSpec(self, xml):
+        slice = self.getSlice()
+        filename = os.path.expanduser("~/.sfi/" + slice + ".rspec")
+        f = open(filename, "w")
+        f.write(xml)
+        f.close()
+        command=["sfi.py", "-u", self.getUser(), "-a", self.getAuthority(), 
+                 "-r", self.registry(), "-s", self.slicemgr(), "create", slice, filename]
+        self.trace_command(command)
+        subprocess.call(command)
+        self.trace_end()
+
+class PlanetLabData(SfaData):
+    def __init__(self):
+        SfaData.__init__(self)
+        self.rspec = None
+
+    def refreshRSpec(self):
+        xml = SfaData.getRSpec(self)
+        self.rspec = RSpec(xml)
+
+    def getRSpec(self):
+        if self.rspec is None:
+            self.refreshRSpec()
+        return self.rspec
+    
+    def applyRSpec(self):
+        xml = self.rspec.toxml()
+        SfaData.applyRSpec(self, xml)
+
+class PLEData(PlanetLabData):
+    def __init__(self):
+        PlanetLabData.__init__(self)
+        self.SFI_SM = "http://www.planet-lab.eu:12346"
+
+class PLJData(PlanetLabData):
+    def __init__(self):
+        PlanetLabData.__init__(self)
+        self.SFI_SM = "http://www.planet-lab.jp:12346"
+
+class ViniData(PlanetLabData):
+    def __init__(self):
+        PlanetLabData.__init__(self)
+        self.SFI_SM = "http://www.vini-veritas.net:12346"
+
+class GpENIData(PlanetLabData):
+    def __init__(self):
+        PlanetLabData.__init__(self)
+        self.SFI_SM = "http://198.248.241.100:12346"
+
+class OpenCirrusData(SfaData):
+    def __init__(self):
+        SfaData.__init__(self)
+        self.SFI_REGISTRY = "http://198.55.37.29:12345"
+        self.SFI_SM = "http://198.55.37.29:12346"
+
+    def refreshRSpec(self):
+        xml = SfaData.getRSpec(self)
+        self.rspec = xml
+
+    def getRSpec(self):
+        if self.rspec is None:
+            self.refreshRSpec()
+        return self.rspec
+    
+    def applyRSpec(self):
+        xml = self.rspec
+        SfaData.applyRSpec(self, xml)
diff --git a/sfamainscreen.py b/sfamainscreen.py
new file mode 100644 (file)
index 0000000..3d1f1ef
--- /dev/null
@@ -0,0 +1,18 @@
+
+from PyQt4.QtGui import QWidget, QLabel
+
+from sfadata import SfaData
+from sfascreen import SfaScreen
+
+
+class SliceWidget(QWidget):
+    def __init__(self, parent=None):
+        QWidget.__init__(self, parent)
+        label = QLabel("slice widget", self)
+
+
+class SfaMainScreen(SfaScreen):
+    def __init__(self, parent=None):
+        SfaScreen.__init__(self, parent)
+        slice = SliceWidget(self)
+        self.init(slice, "Main Window", "PlanetLab Federation GUI")
diff --git a/sfascreen.py b/sfascreen.py
new file mode 100644 (file)
index 0000000..4a0899c
--- /dev/null
@@ -0,0 +1,27 @@
+import sys
+
+from PyQt4.QtGui import QWidget, QLabel, QVBoxLayout
+
+class SfaScreen(QWidget):
+    def __init__(self, parent):
+        QWidget.__init__(self, parent)
+        self.name = self.title = self.widget = None
+
+    def init(self, widget, name, title):
+        if self.widget:
+            sys.stderr.write("Screen is already initialized\n")
+            return
+
+        self.name = name
+        self.title = title
+        self.widget = widget
+        self.label = QLabel(self.title, self)
+
+        layout = QVBoxLayout(self)
+        layout.addWidget(self.label)
+        layout.addWidget(self.widget)
+
+        self.setLayout(layout)
+
+    def getLabelText(self):
+        return "<a href='%s'>%s</a>" % (self.name, self.name)
diff --git a/sfawindow.py b/sfawindow.py
new file mode 100644 (file)
index 0000000..38ec167
--- /dev/null
@@ -0,0 +1,49 @@
+
+from PyQt4.QtCore import SIGNAL
+from PyQt4.QtGui import QWidget, QStackedWidget, \
+    QVBoxLayout, QLabel
+
+from sfaconfigscreen import SfaConfigScreen
+from sfamainscreen import SfaMainScreen
+
+
+class SfaWindow(QWidget):
+    
+    def __init__(self, parent=None):
+        QWidget.__init__(self, parent)
+
+        self.config_screen = SfaConfigScreen(self)
+        self.main_screen = SfaMainScreen(self)
+
+        self.screens = QStackedWidget(self)
+        self.screens.addWidget(self.main_screen)
+        self.screens.addWidget(self.config_screen)
+
+        self.switch = QLabel(self.config_screen.getLabelText(), self)
+        
+        layout = QVBoxLayout()
+        layout.addWidget(self.switch)
+        layout.addWidget(self.screens)
+        self.setLayout(layout)
+        self.adjustSize()
+
+        self.connect(self.switch, SIGNAL('linkActivated(QString)'),
+                     self.toScreen)
+
+    def toScreen(self, link):
+        print link
+        if link == self.config_screen.name:
+            self.toConfigScreen()
+        elif link == self.main_screen.name:
+            self.toMainScreen()
+
+    def toConfigScreen(self):
+        self.screens.setCurrentWidget(self.config_screen)
+        self.switch.setText(self.main_screen.getLabelText())
+
+    def toMainScreen(self):
+        self.screens.setCurrentWidget(self.main_screen)
+        self.switch.setText(self.config_screen.getLabelText())
+
+        
+