[CalendarServer-changes] [7689] CalendarServer/trunk/calendarserver/tools/shell.py

source_changes at macosforge.org source_changes at macosforge.org
Wed Jun 29 12:00:06 PDT 2011


Revision: 7689
          http://trac.macosforge.org/projects/calendarserver/changeset/7689
Author:   wsanchez at apple.com
Date:     2011-06-29 12:00:06 -0700 (Wed, 29 Jun 2011)
Log Message:
-----------
Add HomeDirectory

Modified Paths:
--------------
    CalendarServer/trunk/calendarserver/tools/shell.py

Modified: CalendarServer/trunk/calendarserver/tools/shell.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/shell.py	2011-06-29 15:30:25 UTC (rev 7688)
+++ CalendarServer/trunk/calendarserver/tools/shell.py	2011-06-29 19:00:06 UTC (rev 7689)
@@ -86,7 +86,7 @@
         Start the service.
         """
         super(ShellService, self).startService()
-        shellWithProtocol(ShellProtocol)
+        shellWithProtocol(lambda: ShellProtocol(self.store))
         self.reactor.stop()
 
     def stopService(self):
@@ -106,6 +106,10 @@
 
     ps = ("ds% ", "... ")
 
+    def __init__(self, store):
+        HistoricRecvLine.__init__(self)
+        self.wd = RootDirectory(store)
+
     def connectionMade(self):
         HistoricRecvLine.connectionMade(self)
 
@@ -119,8 +123,6 @@
         self.keyHandlers[CTRL_L        ] = self.handle_FF
         self.keyHandlers[CTRL_BACKSLASH] = self.handle_QUIT
 
-        self.wd = RootDirectory()
-
     def handle_INT(self):
         """
         Handle ^C as an interrupt keystroke by resetting the current input
@@ -219,9 +221,10 @@
     """
     Location in virtual data hierarchy.
     """
-    def __init__(self, path):
+    def __init__(self, store, path):
         assert type(path) is tuple
 
+        self.store = store
         self.path = path
 
     def __str__(self):
@@ -229,13 +232,13 @@
 
     def locate(self, path):
         if not path:
-            return RootDirectory()
+            return RootDirectory(self.store)
 
         path = list(path)
 
         if path[0].startswith("/"):
             path[0] = path[0][1:]
-            subdir = RootDirectory()
+            subdir = RootDirectory(self.store)
         else:
             name = path.pop(0)
             subdir = self.subdir(name)
@@ -259,33 +262,25 @@
         return ()
 
 
-class UIDDirectory(Directory):
-    """
-    Directory containing all principals by UID.
-    """
-    def subdir(self, name):
-        return Directory.subdir(self, name)
-
-
 class RootDirectory(Directory):
     """
     Root of virtual data hierarchy.
     """
-    _childClasses = {
-        "uids": UIDDirectory,
-    }
+    def __init__(self, store):
+        Directory.__init__(self, store, ())
 
-    def __init__(self):
-        Directory.__init__(self, ())
-
         self._children = {}
 
+        self._childClasses = {
+            "uids": UIDDirectory,
+        }
+
     def subdir(self, name):
         if name in self._children:
             return self._children[name]
 
         if name in self._childClasses:
-            self._children[name] = self._childClasses[name](self.path + (name,))
+            self._children[name] = self._childClasses[name](self.store, self.path + (name,))
             return self._children[name]
 
         return Directory.subdir(self, name)
@@ -294,6 +289,34 @@
         return ("%s/" % (n,) for n in self._childClasses)
 
 
+class UIDDirectory(Directory):
+    """
+    Directory containing all principals by UID.
+    """
+    def subdir(self, name):
+        txn = self.store.newTransaction()
+        home = txn.calendarHomeWithUID(name)
+
+        if home:
+            return HomeDirectory(self.store, self.path + (name,), name)
+
+        return Directory.subdir(self, name)
+
+    def list(self):
+        for (txn, home) in self.store.eachCalendarHome():
+            yield home.uid()
+
+
+class HomeDirectory(Directory):
+    """
+    Home directory.
+    """
+    def __init__(self, store, path, home):
+        Directory.__init__(self, store, path)
+
+        self.home = home
+
+
 def main(argv=sys.argv, stderr=sys.stderr, reactor=None):
     """
     Do the export.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20110629/0a3c4ad5/attachment.html>


More information about the calendarserver-changes mailing list