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

source_changes at macosforge.org source_changes at macosforge.org
Fri Oct 31 12:08:36 PDT 2008


Revision: 3303
          http://trac.macosforge.org/projects/calendarserver/changeset/3303
Author:   wsanchez at apple.com
Date:     2008-10-31 12:08:36 -0700 (Fri, 31 Oct 2008)
Log Message:
-----------
Add -r 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:59:46 UTC (rev 3302)
+++ CalendarServer/trunk/calendarserver/tools/export.py	2008-10-31 19:08:36 UTC (rev 3303)
@@ -50,7 +50,8 @@
     print "input specifiers:"
     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)"
+    print "  -r --record: add a directory record's calendar home (format: 'recordType:shortName')"
+    print "  -u --user: add a user's calendar home (shorthand for '-r users:shortName')"
 
     if e:
         sys.exit(64)
@@ -60,11 +61,11 @@
 def main():
     try:
         (optargs, args) = getopt(
-            sys.argv[1:], "hf:o:c:H:u:", [
+            sys.argv[1:], "hf:o:c:H:r:u:", [
                 "config=",
                 "output=",
                 "help",
-                "collection=", "home=", "user=",
+                "collection=", "home=", "record=", "user=",
             ],
         )
     except GetoptError, e:
@@ -75,7 +76,7 @@
 
     collections = set()
     calendarHomes = set()
-    users = set()
+    records = set()
 
     def checkExists(resource):
         if not resource.exists():
@@ -111,18 +112,33 @@
             checkExists(calendarHome)
             calendarHomes.add(calendarHome)
 
+        elif opt in ("-r", "--record"):
+            try:
+                recordType, shortName = arg.split(":", 1)
+                if not recordType or not shortName:
+                    raise ValueError()
+            except ValueError:
+                sys.stderr.write("Invalid record identifier: %r\n" % (arg,))
+                sys.exit(1)
+
+            records.add((recordType, shortName))
+
         elif opt in ("-u", "--user"):
-            users.add(arg)
+            records.add((DirectoryService.recordType_users, arg))
 
     if args:
         usage("Too many arguments: %s" % (" ".join(args),))
 
-    if users:
+    if records:
         config = getConfig(configFileName)
         directory = getDirectory(config)
 
-    for user in users:
-        calendarHome = directory.calendarHomeForShortName(directory.recordType_users, user)
+    for record in records:
+        recordType, shortName = record
+        calendarHome = directory.calendarHomeForShortName(recordType, shortName)
+        if not calendarHome:
+            sys.stderr.write("No calendar home found for record: (%s)%s\n" % (recordType, shortName))
+            sys.exit(1)
         calendarHomes.add(calendarHome)
 
     for calendarHome in calendarHomes:
@@ -251,7 +267,10 @@
                 return self._principalCollection
 
             def calendarHomeForShortName(self, recordType, shortName):
-                return self.principalCollection().principalForShortName(recordType, shortName).calendarHome()
+                principal = self.principalCollection().principalForShortName(recordType, shortName)
+                if principal:
+                    return principal.calendarHome()
+                return None
 
         _directory = MyDirectoryService(**config.DirectoryService["params"])
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20081031/c207886d/attachment.html>


More information about the calendarserver-changes mailing list