SFA browser basic functionality
Andy Bavier [Wed, 9 Jun 2010 21:48:42 +0000 (17:48 -0400)]
SfaBrowser.py
SfaData.py
SubmitPanel.py
public/tree_closed.gif [new file with mode: 0644]
public/tree_open.gif [new file with mode: 0644]
public/tree_white.gif [new file with mode: 0644]

index 778b448..14e8fc0 100644 (file)
@@ -1,13 +1,70 @@
 from Sink import Sink, SinkInfo
+from pyjamas.ui.Tree import Tree, TreeItem
+from pyjamas.ui.PopupPanel import PopupPanel
 from pyjamas.ui.HTML import HTML
+from SfaData import PlanetLabData
+
+class PopupRecord(PopupPanel):
+    def __init__(self, record):
+        PopupPanel.__init__(self, True)
+        contents = HTML("<pre>" + record + "</pre>")
+        self.setWidget(contents)
+        
+        self.setStyleName("ks-popups-Popup")
+
+class SfaItem(TreeItem):
+    def __init__(self, hrn, authority = False):
+        self.isAuthority = authority
+        self.hrn = hrn
+        last = hrn.split('.')[-1]
+        self.label = last
+        TreeItem.__init__(self, self.label)
+
+        if self.isAuthority:
+            self.addItem(PendingItem())
+
+class PendingItem(TreeItem):
+    def __init__(self):
+        TreeItem.__init__(self, "Please wait...")
+
+    def isPendingItem(self):
+        return True
 
 class SfaBrowser(Sink):
     def __init__(self):
 
         Sink.__init__(self)
 
-        text="Not implemented yet"
-        self.initWidget(HTML(text, True))
+        self.data = PlanetLabData()
+
+        self.tree = Tree()
+        
+        item = SfaItem("plc", True)
+        self.tree.addItem(item)
+
+        item = SfaItem("ple", True)
+        self.tree.addItem(item)
+
+        self.tree.addTreeListener(self)
+
+        self.initWidget(self.tree)
+
+
+    def onTreeItemSelected(self, item):
+        record = self.data.getRecord(item.hrn)
+        p = PopupRecord(record)
+        left = item.getAbsoluteLeft() + 10
+        top = item.getAbsoluteTop() + 10
+        p.setPopupPosition(left, top)
+        p.show()
+
+    def onTreeItemStateChanged(self, item):
+        child = item.getChild(0)
+        if hasattr(child, "isPendingItem"):
+            item.removeItem(child)
+            hrns = self.data.listChildren(item.hrn)
+            for (hrn, kind) in hrns:
+                item.addItem(SfaItem(hrn, (kind=="(authority)")))
 
     def onShow(self):
         pass
index 049b0d3..b99c56e 100644 (file)
@@ -1,5 +1,6 @@
 import os
-from subprocess import call
+import re
+from subprocess import *
 from sfa.util.rspecHelper import RSpec
 
 class SfaData:
@@ -30,8 +31,26 @@ class SfaData:
     def setSlice(self, slice):
         SfaData.slice = slice
 
-    def getRecord(self):
-        pass
+    def getRecord(self, hrn):
+        text = Popen(["sfi.py", "-u", self.getUser(), "-a", 
+                      self.getAuthority(), "-r", self.registry, 
+                      "-s", self.slicemgr, "show", hrn], 
+                     stdout=PIPE).communicate()[0]
+        return text
+
+    def listChildren(self, hrn):
+        children = []
+        text = Popen(["sfi.py", "-u", self.getUser(), "-a", 
+                      self.getAuthority(), "-r", self.registry, 
+                      "-s", self.slicemgr, "list", hrn], 
+                     stdout=PIPE).communicate()[0]
+        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()
index f3c10a9..8fa8fa6 100644 (file)
@@ -33,7 +33,7 @@ class SubmitPanel(VerticalPanel):
     def apply(self, sender):
         self.sfadata.applyRSpec()
 
-    def reset(self):
+    def reset(self, sender):
         self.sfadata.refreshRSpec()
         
 
diff --git a/public/tree_closed.gif b/public/tree_closed.gif
new file mode 100644 (file)
index 0000000..1348f45
Binary files /dev/null and b/public/tree_closed.gif differ
diff --git a/public/tree_open.gif b/public/tree_open.gif
new file mode 100644 (file)
index 0000000..c1ff81f
Binary files /dev/null and b/public/tree_open.gif differ
diff --git a/public/tree_white.gif b/public/tree_white.gif
new file mode 100644 (file)
index 0000000..ce4881f
Binary files /dev/null and b/public/tree_white.gif differ