[CalendarServer-changes] [7677] CalendarServer/trunk

source_changes at macosforge.org source_changes at macosforge.org
Mon Jun 27 13:38:03 PDT 2011


Revision: 7677
          http://trac.macosforge.org/projects/calendarserver/changeset/7677
Author:   glyph at apple.com
Date:     2011-06-27 13:38:02 -0700 (Mon, 27 Jun 2011)
Log Message:
-----------
Allow exporting based on calendar home UID, rather than directory ID.

Modified Paths:
--------------
    CalendarServer/trunk/calendarserver/tools/export.py
    CalendarServer/trunk/calendarserver/tools/test/test_export.py

Property Changed:
----------------
    CalendarServer/trunk/


Property changes on: CalendarServer/trunk
___________________________________________________________________
Modified: svn:mergeinfo
   - /CalendarServer/branches/config-separation:4379-4443
/CalendarServer/branches/egg-info-351:4589-4625
/CalendarServer/branches/generic-sqlstore:6167-6191
/CalendarServer/branches/new-store:5594-5934
/CalendarServer/branches/new-store-no-caldavfile:5911-5935
/CalendarServer/branches/new-store-no-caldavfile-2:5936-5981
/CalendarServer/branches/users/cdaboo/batchupload-6699:6700-7198
/CalendarServer/branches/users/cdaboo/cached-subscription-calendars-5692:5693-5702
/CalendarServer/branches/users/cdaboo/directory-cache-on-demand-3627:3628-3644
/CalendarServer/branches/users/cdaboo/more-sharing-5591:5592-5601
/CalendarServer/branches/users/cdaboo/partition-4464:4465-4957
/CalendarServer/branches/users/cdaboo/pods:7297-7377
/CalendarServer/branches/users/cdaboo/pycalendar:7085-7206
/CalendarServer/branches/users/cdaboo/pycard:7227-7237
/CalendarServer/branches/users/cdaboo/relative-config-paths-5070:5071-5105
/CalendarServer/branches/users/cdaboo/shared-calendars-5187:5188-5440
/CalendarServer/branches/users/glyph/conn-limit:6574-6577
/CalendarServer/branches/users/glyph/contacts-server-merge:4971-5080
/CalendarServer/branches/users/glyph/dalify:6932-7023
/CalendarServer/branches/users/glyph/db-reconnect:6824-6876
/CalendarServer/branches/users/glyph/deploybuild:7563-7572
/CalendarServer/branches/users/glyph/dont-start-postgres:6592-6614
/CalendarServer/branches/users/glyph/linux-tests:6893-6900
/CalendarServer/branches/users/glyph/misc-portability-fixes:7365-7374
/CalendarServer/branches/users/glyph/more-deferreds-6:6322-6368
/CalendarServer/branches/users/glyph/more-deferreds-7:6369-6445
/CalendarServer/branches/users/glyph/new-export:7444-7485
/CalendarServer/branches/users/glyph/oracle:7106-7155
/CalendarServer/branches/users/glyph/oracle-nulls:7340-7351
/CalendarServer/branches/users/glyph/quota:7604-7637
/CalendarServer/branches/users/glyph/sendfdport:5388-5424
/CalendarServer/branches/users/glyph/sharedpool:6490-6550
/CalendarServer/branches/users/glyph/sql-store:5929-6073
/CalendarServer/branches/users/glyph/subtransactions:7248-7258
/CalendarServer/branches/users/glyph/use-system-twisted:5084-5149
/CalendarServer/branches/users/sagen/inboxitems:7380-7381
/CalendarServer/branches/users/sagen/locations-resources:5032-5051
/CalendarServer/branches/users/sagen/locations-resources-2:5052-5061
/CalendarServer/branches/users/sagen/purge_old_events:6735-6746
/CalendarServer/branches/users/sagen/resource-delegates-4038:4040-4067
/CalendarServer/branches/users/sagen/resource-delegates-4066:4068-4075
/CalendarServer/branches/users/sagen/resources-2:5084-5093
/CalendarServer/branches/users/wsanchez/transations:5515-5593
   + /CalendarServer/branches/config-separation:4379-4443
/CalendarServer/branches/egg-info-351:4589-4625
/CalendarServer/branches/generic-sqlstore:6167-6191
/CalendarServer/branches/new-store:5594-5934
/CalendarServer/branches/new-store-no-caldavfile:5911-5935
/CalendarServer/branches/new-store-no-caldavfile-2:5936-5981
/CalendarServer/branches/users/cdaboo/batchupload-6699:6700-7198
/CalendarServer/branches/users/cdaboo/cached-subscription-calendars-5692:5693-5702
/CalendarServer/branches/users/cdaboo/directory-cache-on-demand-3627:3628-3644
/CalendarServer/branches/users/cdaboo/more-sharing-5591:5592-5601
/CalendarServer/branches/users/cdaboo/partition-4464:4465-4957
/CalendarServer/branches/users/cdaboo/pods:7297-7377
/CalendarServer/branches/users/cdaboo/pycalendar:7085-7206
/CalendarServer/branches/users/cdaboo/pycard:7227-7237
/CalendarServer/branches/users/cdaboo/relative-config-paths-5070:5071-5105
/CalendarServer/branches/users/cdaboo/shared-calendars-5187:5188-5440
/CalendarServer/branches/users/glyph/conn-limit:6574-6577
/CalendarServer/branches/users/glyph/contacts-server-merge:4971-5080
/CalendarServer/branches/users/glyph/dalify:6932-7023
/CalendarServer/branches/users/glyph/db-reconnect:6824-6876
/CalendarServer/branches/users/glyph/deploybuild:7563-7572
/CalendarServer/branches/users/glyph/dont-start-postgres:6592-6614
/CalendarServer/branches/users/glyph/linux-tests:6893-6900
/CalendarServer/branches/users/glyph/misc-portability-fixes:7365-7374
/CalendarServer/branches/users/glyph/more-deferreds-6:6322-6368
/CalendarServer/branches/users/glyph/more-deferreds-7:6369-6445
/CalendarServer/branches/users/glyph/new-export:7444-7485
/CalendarServer/branches/users/glyph/oracle:7106-7155
/CalendarServer/branches/users/glyph/oracle-nulls:7340-7351
/CalendarServer/branches/users/glyph/quota:7604-7637
/CalendarServer/branches/users/glyph/sendfdport:5388-5424
/CalendarServer/branches/users/glyph/sharedpool:6490-6550
/CalendarServer/branches/users/glyph/sql-store:5929-6073
/CalendarServer/branches/users/glyph/subtransactions:7248-7258
/CalendarServer/branches/users/glyph/uidexport:7673-7676
/CalendarServer/branches/users/glyph/use-system-twisted:5084-5149
/CalendarServer/branches/users/sagen/inboxitems:7380-7381
/CalendarServer/branches/users/sagen/locations-resources:5032-5051
/CalendarServer/branches/users/sagen/locations-resources-2:5052-5061
/CalendarServer/branches/users/sagen/purge_old_events:6735-6746
/CalendarServer/branches/users/sagen/resource-delegates-4038:4040-4067
/CalendarServer/branches/users/sagen/resource-delegates-4066:4068-4075
/CalendarServer/branches/users/sagen/resources-2:5084-5093
/CalendarServer/branches/users/wsanchez/transations:5515-5593

Modified: CalendarServer/trunk/calendarserver/tools/export.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/export.py	2011-06-27 20:34:43 UTC (rev 7676)
+++ CalendarServer/trunk/calendarserver/tools/export.py	2011-06-27 20:38:02 UTC (rev 7677)
@@ -78,7 +78,7 @@
     """
     Command-line options for 'calendarserver_export'
 
-    @ivar exporters: a list of L{HomeExporter} objects which can identify the
+    @ivar exporters: a list of L{DirectoryExporter} objects which can identify the
         calendars to export, given a directory service.  This list is built by
         parsing --record and --collection options.
     """
@@ -94,12 +94,20 @@
         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').
         """
         recordType, shortName = recordName.split(":", 1)
-        self.exporters.append(HomeExporter(recordType, shortName))
+        self.exporters.append(DirectoryExporter(recordType, shortName))
 
     opt_r = opt_record
 
@@ -145,40 +153,36 @@
 
 
 
-class HomeExporter(object):
+class _ExporterBase(object):
     """
-    An exporter that constructs a list of calendars based on the UID or
-    directory services record ID of the home.
+    Base exporter implementation that works from a home UID.
 
     @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:
@@ -191,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/trunk/calendarserver/tools/test/test_export.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/test/test_export.py	2011-06-27 20:34:43 UTC (rev 7676)
+++ CalendarServer/trunk/calendarserver/tools/test/test_export.py	2011-06-27 20:38:02 UTC (rev 7677)
@@ -35,7 +35,7 @@
 
 from calendarserver.tools import export
 from calendarserver.tools.export import ExportOptions, main
-from calendarserver.tools.export import HomeExporter
+from calendarserver.tools.export import DirectoryExporter, UIDExporter
 
 from twisted.python.filepath import FilePath
 from twistedcaldav.test.util import patchConfig
@@ -91,30 +91,43 @@
         self.assertEquals(len(err.getvalue()), 0)
 
 
-    def test_oneHome(self):
+    def test_oneRecord(self):
         """
-        One '--record' option will result in a single HomeExporter object with
-        no calendars in its list.
+        One '--record' option will result in a single L{DirectoryExporter}
+        object with no calendars in its list.
         """
         eo = ExportOptions()
         eo.parseOptions(["--record", "users:bob"])
         self.assertEquals(len(eo.exporters), 1)
         exp = eo.exporters[0]
-        self.assertIsInstance(exp, HomeExporter)
+        self.assertIsInstance(exp, DirectoryExporter)
         self.assertEquals(exp.recordType, "users")
         self.assertEquals(exp.shortName, "bob")
         self.assertEquals(exp.collections, [])
 
 
+    def test_oneUID(self):
+        """
+        One '--uid' option will result in a single L{UIDExporter} object with no
+        calendars in its list.
+        """
+        eo = ExportOptions()
+        eo.parseOptions(["--uid", "bob's your guid"])
+        self.assertEquals(len(eo.exporters), 1)
+        exp = eo.exporters[0]
+        self.assertIsInstance(exp, UIDExporter)
+        self.assertEquals(exp.uid, "bob's your guid")
+
+
     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]
@@ -122,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/6322d456/attachment-0001.html>


More information about the calendarserver-changes mailing list