[CalendarServer-changes] [7676] CalendarServer/branches/users/glyph/uidexport/calendarserver/tools

source_changes at macosforge.org source_changes at macosforge.org
Mon Jun 27 13:34:43 PDT 2011


Revision: 7676
          http://trac.macosforge.org/projects/calendarserver/changeset/7676
Author:   glyph at apple.com
Date:     2011-06-27 13:34:43 -0700 (Mon, 27 Jun 2011)
Log Message:
-----------
Fix the test, add an option, improve the docstrings a little.

Modified Paths:
--------------
    CalendarServer/branches/users/glyph/uidexport/calendarserver/tools/export.py
    CalendarServer/branches/users/glyph/uidexport/calendarserver/tools/test/test_export.py

Modified: CalendarServer/branches/users/glyph/uidexport/calendarserver/tools/export.py
===================================================================
--- CalendarServer/branches/users/glyph/uidexport/calendarserver/tools/export.py	2011-06-27 20:34:32 UTC (rev 7675)
+++ CalendarServer/branches/users/glyph/uidexport/calendarserver/tools/export.py	2011-06-27 20:34:43 UTC (rev 7676)
@@ -94,6 +94,14 @@
         self.outputName = '-'
 
 
+    def opt_uid(self, uid):
+        """
+        Add a calendar home directly by its UID (which is usually a directory
+        service's GUID).
+        """
+        self.exporters.append(UIDExporter(uid))
+
+
     def opt_record(self, recordName):
         """
         Add a directory record's calendar home (format: 'recordType:shortName').
@@ -145,46 +153,36 @@
 
 
 
-class UIDExporter(object):
+class _ExporterBase(object):
     """
-    """
+    Base exporter implementation that works from a home UID.
 
-
-
-class DirectoryExporter(object):
-    """
-    An exporter that constructs a list of calendars based on the directory
-    services record ID of the home.
-
     @ivar collections: A list of the names of collections that this exporter
         should enumerate.
 
     @type collections: C{list} of C{str}
 
-    @ivar recordType: The directory record type to export.  For example:
-        'users'.
-
-    @type recordType: C{str}
-
-    @ivar shortName: The shortName of the directory record to export, according
-        to C{recordType}.
     """
 
-    def __init__(self, recordType, shortName):
+    def __init__(self):
         self.collections = []
-        self.recordType = recordType
-        self.shortName = shortName
 
 
+    def getHomeUID(self, exportService):
+        """
+        Subclasses must implement this.
+        """
+        raise NotImplementedError()
+
+
     @inlineCallbacks
     def listCalendars(self, txn, exportService):
         """
         Enumerate all calendars based on the directory record and/or calendars
         for this calendar home.
         """
-        directory = exportService.directoryService()
-        record = directory.recordWithShortName(self.recordType, self.shortName)
-        home = yield txn.calendarHomeWithUID(record.guid, True)
+        uid = self.getHomeUID(exportService)
+        home = yield txn.calendarHomeWithUID(uid, True)
         result = []
         if self.collections:
             for collection in self.collections:
@@ -197,6 +195,58 @@
 
 
 
+class UIDExporter(_ExporterBase):
+    """
+    An exporter that constructs a list of calendars based on the UID of the
+    home, and an optional list of calendar names.
+
+    @ivar uid: The UID of a calendar home to export.
+
+    @type uid: C{str}
+    """
+
+    def __init__(self, uid):
+        super(UIDExporter, self).__init__()
+        self.uid = uid
+
+
+    def getHomeUID(self, exportService):
+        return self.uid
+
+
+
+class DirectoryExporter(_ExporterBase):
+    """
+    An exporter that constructs a list of calendars based on the directory
+    services record ID of the home, and an optional list of calendar names.
+
+    @ivar recordType: The directory record type to export.  For example:
+        'users'.
+
+    @type recordType: C{str}
+
+    @ivar shortName: The shortName of the directory record to export, according
+        to C{recordType}.
+
+    @type shortName: C{str}
+    """
+
+    def __init__(self, recordType, shortName):
+        super(DirectoryExporter, self).__init__()
+        self.recordType = recordType
+        self.shortName = shortName
+
+
+    def getHomeUID(self, exportService):
+        """
+        Retrieve the home UID.
+        """
+        directory = exportService.directoryService()
+        record = directory.recordWithShortName(self.recordType, self.shortName)
+        return record.guid
+
+
+
 @inlineCallbacks
 def exportToFile(calendars, fileobj):
     """

Modified: CalendarServer/branches/users/glyph/uidexport/calendarserver/tools/test/test_export.py
===================================================================
--- CalendarServer/branches/users/glyph/uidexport/calendarserver/tools/test/test_export.py	2011-06-27 20:34:32 UTC (rev 7675)
+++ CalendarServer/branches/users/glyph/uidexport/calendarserver/tools/test/test_export.py	2011-06-27 20:34:43 UTC (rev 7676)
@@ -121,13 +121,13 @@
 
     def test_homeAndCollections(self):
         """
-        The --collection option adds calendars to the last calendar that was
-        exported.
+        The --collection option adds specific calendars to the last home that
+        was exported.
         """
         eo = ExportOptions()
         eo.parseOptions(["--record", "users:bob",
                          "--collection", "work stuff",
-                         "--record", "users:jethro",
+                         "--uid", "jethroUID",
                          "--collection=fun stuff"])
         self.assertEquals(len(eo.exporters), 2)
         exp = eo.exporters[0]
@@ -135,8 +135,7 @@
         self.assertEquals(exp.shortName, "bob")
         self.assertEquals(exp.collections, ["work stuff"])
         exp = eo.exporters[1]
-        self.assertEquals(exp.recordType, "users")
-        self.assertEquals(exp.shortName, "jethro")
+        self.assertEquals(exp.uid, "jethroUID")
         self.assertEquals(exp.collections, ["fun stuff"])
 
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20110627/8d0a4703/attachment-0001.html>


More information about the calendarserver-changes mailing list