[CalendarServer-changes] [7461] CalendarServer/branches/users/glyph/new-export/calendarserver/tools
source_changes at macosforge.org
source_changes at macosforge.org
Mon May 16 07:43:20 PDT 2011
Revision: 7461
http://trac.macosforge.org/projects/calendarserver/changeset/7461
Author: glyph at apple.com
Date: 2011-05-16 07:43:19 -0700 (Mon, 16 May 2011)
Log Message:
-----------
basic option-parsing object & tests
Modified Paths:
--------------
CalendarServer/branches/users/glyph/new-export/calendarserver/tools/export.py
CalendarServer/branches/users/glyph/new-export/calendarserver/tools/test/test_export.py
Modified: CalendarServer/branches/users/glyph/new-export/calendarserver/tools/export.py
===================================================================
--- CalendarServer/branches/users/glyph/new-export/calendarserver/tools/export.py 2011-05-16 14:43:07 UTC (rev 7460)
+++ CalendarServer/branches/users/glyph/new-export/calendarserver/tools/export.py 2011-05-16 14:43:19 UTC (rev 7461)
@@ -41,6 +41,7 @@
from getopt import getopt, GetoptError
from os.path import dirname, abspath
+from twisted.python.usage import Options
from twisted.internet.defer import inlineCallbacks
#from twisted.internet.defer import returnValue
@@ -95,6 +96,45 @@
+class ExportOptions(Options):
+
+ def __init__(self):
+ super(ExportOptions, self).__init__()
+ self.exporters = []
+
+
+ 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))
+
+
+ def opt_collection(self, collectionName):
+ """
+ add a calendar collection. must be passed after --record (or a synonym,
+ like --user). for example, to export user1's calendars called
+ 'meetings' and 'team', invoke 'calendarserver_export --user=user1
+ --collection=meetings --collection=team'.
+ """
+ self.exporters[-1].collections.append(collectionName)
+
+
+
+class HomeExporter(object):
+ """
+ An exporter that constructs a list of calendars based on the UID or
+ directory services record ID of the home.
+ """
+
+ def __init__(self, recordType, shortName):
+ self.collections = []
+ self.recordType = recordType
+ self.shortName = shortName
+
+
+
@inlineCallbacks
def exportToFile(calendars, exporterUID, fileobj):
"""
Modified: CalendarServer/branches/users/glyph/new-export/calendarserver/tools/test/test_export.py
===================================================================
--- CalendarServer/branches/users/glyph/new-export/calendarserver/tools/test/test_export.py 2011-05-16 14:43:07 UTC (rev 7460)
+++ CalendarServer/branches/users/glyph/new-export/calendarserver/tools/test/test_export.py 2011-05-16 14:43:19 UTC (rev 7461)
@@ -31,6 +31,8 @@
from twext.enterprise.ienterprise import AlreadyFinishedError
from twistedcaldav.ical import Component
+from calendarserver.tools.export import ExportOptions
+from calendarserver.tools.export import HomeExporter
from txdav.common.datastore.test.util import buildStore
from txdav.common.datastore.test.util import populateCalendarsFrom
@@ -73,7 +75,43 @@
self.assertEquals(len(err.getvalue()), 0)
+ def test_oneHome(self):
+ """
+ One '--record' option will result in a single HomeExporter 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.assertEquals(exp.recordType, "users")
+ self.assertEquals(exp.shortName, "bob")
+ self.assertEquals(exp.collections, [])
+
+ def test_homeAndCollections(self):
+ """
+ The --collection option adds calendars to the last calendar that was
+ exported.
+ """
+ eo = ExportOptions()
+ eo.parseOptions(["--record", "users:bob",
+ "--collection", "work stuff",
+ "--record", "users:jethro",
+ "--collection=fun stuff"])
+ self.assertEquals(len(eo.exporters), 2)
+ exp = eo.exporters[0]
+ self.assertEquals(exp.recordType, "users")
+ 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.collections, ["fun stuff"])
+
+
+
class IntegrationTests(TestCase):
"""
Tests for exporting data from a live store.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20110516/d1434d47/attachment.html>
More information about the calendarserver-changes
mailing list