[CalendarServer-changes] [7475] CalendarServer/branches/users/glyph/new-export/calendarserver/tools
source_changes at macosforge.org
source_changes at macosforge.org
Mon May 16 07:46:13 PDT 2011
Revision: 7475
http://trac.macosforge.org/projects/calendarserver/changeset/7475
Author: glyph at apple.com
Date: 2011-05-16 07:46:13 -0700 (Mon, 16 May 2011)
Log Message:
-----------
Get rid of exporterUID argument, since we always want to export as the owner.
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:46:01 UTC (rev 7474)
+++ CalendarServer/branches/users/glyph/new-export/calendarserver/tools/export.py 2011-05-16 14:46:13 UTC (rev 7475)
@@ -37,6 +37,8 @@
"""
import sys
+import itertools
+
from getopt import getopt, GetoptError
from os.path import dirname, abspath
@@ -158,18 +160,13 @@
@inlineCallbacks
-def exportToFile(calendars, exporterUID, fileobj):
+def exportToFile(calendars, fileobj):
"""
Export some calendars to a file as a particular UID.
@param calendars: an iterable of L{ICalendar} providers (or L{Deferred}s of
same).
- @param exporterUID: the calendar data-store UID of the user (i.e. of their
- calendar home, not of anything in the directory) to export the per-user
- data of for the given calendars.
- @type exporterUID: C{str}
-
@param fileobj: an object with a C{write} method that will accept some
iCalendar data.
@@ -181,7 +178,8 @@
for calendar in calendars:
calendar = yield calendar
for obj in (yield calendar.calendarObjects()):
- evt = yield obj.filteredComponent(exporterUID, True)
+ evt = yield obj.filteredComponent(
+ calendar.ownerCalendarHome().uid(), True)
for sub in evt.subcomponents():
if sub.name() != 'VTIMEZONE':
# Omit all VTIMEZONE components, since PyCalendar will
@@ -307,8 +305,12 @@
Service which runs, exports the appropriate records, then stops the reactor.
"""
- def __init__(self):
+ def __init__(self, store, options, output, reactor):
super(ExporterService, self).__init__()
+ self.store = store
+ self.options = options
+ self.output = output
+ self.reactor = reactor
def startService(self):
@@ -316,8 +318,22 @@
Start the service.
"""
super(ExporterService, self).startService()
+ self.doExport()
+ @inlineCallbacks
+ def doExport(self):
+ """
+ Do the export, stopping the reactor when done.
+ """
+ allCalendars = itertools.chain(
+ [exporter.listCalendars(self) for exporter in
+ self.options.exporters]
+ )
+ yield exportToFile(allCalendars, self.output)
+ self.reactor.stop()
+
+
def stopService(self):
"""
Stop the service. Nothing to do; everything should be finished by this
@@ -329,6 +345,7 @@
# anyway).
+
def main(argv=sys.argv, stderr=sys.stderr, reactor=None):
"""
Do the export.
@@ -343,7 +360,9 @@
stderr.write("Unable to open output file for writing: %s\n" %
(e))
sys.exit(1)
- utilityMain(options['config'], lambda store: Service(), reactor)
+ utilityMain(options['config'],
+ lambda store: ExporterService(store, options, output, reactor),
+ reactor)
output #pyflakes
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:46:01 UTC (rev 7474)
+++ CalendarServer/branches/users/glyph/new-export/calendarserver/tools/test/test_export.py 2011-05-16 14:46:13 UTC (rev 7475)
@@ -31,12 +31,16 @@
from twext.enterprise.ienterprise import AlreadyFinishedError
from twistedcaldav.ical import Component
+#from twistedcaldav.directory import augment
+from twistedcaldav.datafilters.test.test_peruserdata import dataForTwoUsers
+from twistedcaldav.datafilters.test.test_peruserdata import resultForUser2
+
from calendarserver.tools import export
from calendarserver.tools.export import ExportOptions, main
from calendarserver.tools.export import HomeExporter
-from twistedcaldav.datafilters.test.test_peruserdata import dataForTwoUsers
-from twistedcaldav.datafilters.test.test_peruserdata import resultForUser2
+
from twisted.internet.defer import Deferred
+#from twistedcaldav.directory.xmlfile import XMLDirectoryService
from txdav.common.datastore.test.util import buildStore
from txdav.common.datastore.test.util import populateCalendarsFrom
@@ -175,6 +179,18 @@
"""
self.mainCalled = False
self.patch(export, "utilityMain", self.fakeUtilityMain)
+
+ # In lieu of a configuration file, patch up the augment service and make
+ # it so directoryFromConfig will return something useful.
+
+# self.patch(augment, "AugmentService",
+# augment.AugmentXMLDB(xmlFiles=(self.augmentsFile().path,)))
+#
+# self.patch(export, "directoryFromConfig",
+# XMLDirectoryService({'xmlFile' : self.xmlFile()},
+# alwaysStat=True))
+
+
self.store = yield buildStore(self, None)
self.waitToStop = Deferred()
@@ -202,16 +218,21 @@
self.addCleanup(self.exportService.stopService)
- def test_configFile(self):
+ @inlineCallbacks
+ def test_serviceState(self):
"""
export.main() invokes utilityMain with the configuration file specified
- on the command line.
+ on the command line, and creates an L{ExporterService} pointed at the
+ appropriate store.
"""
tempConfig = self.mktemp()
- main(['calendarserver_export', '--config', tempConfig], reactor=self)
+ main(['calendarserver_export', '--config', tempConfig, '--output',
+ self.mktemp()], reactor=self)
self.assertEquals(self.mainCalled, True, "Main not called.")
self.assertEquals(self.usedConfigFile, tempConfig)
self.assertEquals(self.usedReactor, self)
+ self.assertEquals(self.exportService.store, self.store)
+ yield self.waitToStop
@inlineCallbacks
@@ -220,7 +241,7 @@
Exporting an empty calendar results in an empty calendar.
"""
io = StringIO()
- value = yield exportToFile([], "nobody", io)
+ value = yield exportToFile([], io)
# it doesn't return anything, it writes to the file.
self.assertEquals(value, None)
# but it should write a valid component to the file.
@@ -267,8 +288,7 @@
io = StringIO()
yield exportToFile(
[(yield self.txn().calendarHomeWithUID("home1"))
- .calendarWithName("calendar1")],
- "nobody", io
+ .calendarWithName("calendar1")], io
)
self.assertEquals(Component.fromString(io.getvalue()),
expected)
@@ -301,8 +321,7 @@
io = StringIO()
yield exportToFile(
[(yield self.txn().calendarHomeWithUID("home1"))
- .calendarWithName("calendar1")],
- "nobody", io
+ .calendarWithName("calendar1")], io
)
self.assertEquals(Component.fromString(io.getvalue()),
expected)
@@ -332,8 +351,7 @@
io = StringIO()
yield exportToFile(
[(yield self.txn().calendarHomeWithUID("home1"))
- .calendarWithName("calendar1")],
- "nobody", io
+ .calendarWithName("calendar1")], io
)
result = Component.fromString(io.getvalue())
@@ -359,12 +377,12 @@
@inlineCallbacks
def test_perUserFiltering(self):
"""
- L{exportToFile} performs per-user component filtering based on its
- C{exporterUID} parameter.
+ L{exportToFile} performs per-user component filtering based on the owner
+ of that calendar.
"""
yield populateCalendarsFrom(
{
- "home1": {
+ "user02": {
"calendar1": {
"peruser.ics": (dataForTwoUsers, {}), # EST
}
@@ -373,8 +391,8 @@
)
io = StringIO()
yield exportToFile(
- [(yield self.txn().calendarHomeWithUID("home1"))
- .calendarWithName("calendar1")], "user02", io
+ [(yield self.txn().calendarHomeWithUID("user02"))
+ .calendarWithName("calendar1")], io
)
self.assertEquals(
Component.fromString(resultForUser2),
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20110516/020fdb9e/attachment.html>
More information about the calendarserver-changes
mailing list