[CalendarServer-changes] [3300] CalendarServer/trunk/calendarserver/tools/export.py

source_changes at macosforge.org source_changes at macosforge.org
Fri Oct 31 11:28:58 PDT 2008


Revision: 3300
          http://trac.macosforge.org/projects/calendarserver/changeset/3300
Author:   wsanchez at apple.com
Date:     2008-10-31 11:28:58 -0700 (Fri, 31 Oct 2008)
Log Message:
-----------
Add -u option.

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

Modified: CalendarServer/trunk/calendarserver/tools/export.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/export.py	2008-10-31 18:11:21 UTC (rev 3299)
+++ CalendarServer/trunk/calendarserver/tools/export.py	2008-10-31 18:28:58 UTC (rev 3300)
@@ -21,8 +21,9 @@
 from getopt import getopt, GetoptError
 from os.path import dirname, abspath
 
-from twistedcaldav.ical import Component as iComponent, Property as iProperty,\
-    iCalendarProductID
+from twisted.python.reflect import namedClass
+from twistedcaldav.ical import Component as iComponent, Property as iProperty
+from twistedcaldav.ical import iCalendarProductID
 from twistedcaldav.resource import isCalendarCollectionResource
 from twistedcaldav.static import CalDAVFile, CalendarHomeFile
 from twistedcaldav.directory.directory import DirectoryService, DirectoryRecord
@@ -36,15 +37,17 @@
         print ""
 
     name = os.path.basename(sys.argv[0])
-    print "usage: %s [-c collection_path] [-H calendar_home_path]" % (name,)
+    print "usage: %s [-f config] [-c collection_path] [-H calendar_home_path] [-u user]" % (name,)
     print ""
     print "Generate an iCalendar file containing the merged content of each calendar"
     print "collection read."
     print ""
     print "options:"
     print "  -h --help: print this help"
+    print "  -f --config: Specify caldavd.plist configuration path"
     print "  -c --collection: add a calendar collection"
     print "  -H --home: add a calendar home (and all calendars within it)"
+    print "  -u --user: add a user's calendar home (and all calendars within it)"
 
     if e:
         sys.exit(64)
@@ -54,16 +57,20 @@
 def main():
     try:
         (optargs, args) = getopt(
-            sys.argv[1:], "hc:H:", [
+            sys.argv[1:], "hf:c:H:u:", [
+                "config=",
                 "help",
-                "collection=", "home="
+                "collection=", "home=", "user=",
             ],
         )
     except GetoptError, e:
         usage(e)
 
+    configFileName = None
+
     collections = set()
     calendarHomes = set()
+    users = set()
 
     def checkExists(resource):
         if not resource.exists():
@@ -74,6 +81,9 @@
         if opt in ("-h", "--help"):
             usage()
 
+        elif opt in ("-f", "--config"):
+            configFileName = arg
+
         elif opt in ("-c", "--collection"):
             path = abspath(arg)
             collection = CalDAVFile(path)
@@ -90,9 +100,20 @@
             checkExists(calendarHome)
             calendarHomes.add(calendarHome)
 
+        elif opt in ("-u", "--user"):
+            users.add(arg)
+
     if args:
         usage("Too many arguments: %s" % (" ".join(args),))
 
+    if users:
+        config = getConfig(configFileName)
+        directory = getDirectory(config)
+
+    for user in users:
+        calendarHome = directory.calendarHomeForShortName(directory.recordType_users, user)
+        calendarHomes.add(calendarHome)
+
     for calendarHome in calendarHomes:
         for childName in calendarHome.listChildren():
             child = calendarHome.getChild(childName)
@@ -140,6 +161,7 @@
     except UsageError, e:
         usage(e)
 
+_dummyDirectoryRecord = None
 def dummyDirectoryRecord():
     global _dummyDirectoryRecord
     if _dummyDirectoryRecord is None:
@@ -163,7 +185,55 @@
             autoSchedule = False,
         )
     return _dummyDirectoryRecord
-_dummyDirectoryRecord = None
 
+_config = None
+def getConfig(configFileName):
+    global _config
+    if _config is None:
+        from twistedcaldav.config import config, defaultConfigFile
+
+        if configFileName is None:
+            configFileName = defaultConfigFile
+
+        if not os.path.isfile(configFileName):
+            sys.stderr.write("No config file: %s\n" % (configFileName,))
+            sys.exit(1)
+
+        config.loadConfig(configFileName)
+
+        _config = config
+
+    return _config
+
+_directory = None
+def getDirectory(config):
+    global _directory
+    if _directory is None:
+        BaseDirectoryService = namedClass(config.DirectoryService["type"])
+
+        class MyDirectoryService (BaseDirectoryService):
+            def principalCollection(self):
+                if not hasattr(self, "_principalCollection"):
+                    #
+                    # Instantiating a CalendarHomeProvisioningResource with a directory
+                    # will register it with the directory (still smells like a hack).
+                    #
+                    # We need that in order to locate calendar homes via the directory.
+                    #
+                    from twistedcaldav.static import CalendarHomeProvisioningFile
+                    CalendarHomeProvisioningFile(os.path.join(config.DocumentRoot, "calendars"), self, "/calendars/")
+
+                    from twistedcaldav.directory.principal import DirectoryPrincipalProvisioningResource
+                    self._principalCollection = DirectoryPrincipalProvisioningResource("/principals/", self)
+
+                return self._principalCollection
+
+            def calendarHomeForShortName(self, recordType, shortName):
+                return self.principalCollection().principalForShortName(recordType, shortName).calendarHome()
+
+        _directory = MyDirectoryService(**config.DirectoryService["params"])
+
+    return _directory
+
 if __name__ == "__main__":
     main()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20081031/b7840050/attachment.html>


More information about the calendarserver-changes mailing list