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

source_changes at macosforge.org source_changes at macosforge.org
Fri Oct 31 11:44:38 PDT 2008


Revision: 3301
          http://trac.macosforge.org/projects/calendarserver/changeset/3301
Author:   wsanchez at apple.com
Date:     2008-10-31 11:44:38 -0700 (Fri, 31 Oct 2008)
Log Message:
-----------
Add -o 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:28:58 UTC (rev 3300)
+++ CalendarServer/trunk/calendarserver/tools/export.py	2008-10-31 18:44:38 UTC (rev 3301)
@@ -37,14 +37,17 @@
         print ""
 
     name = os.path.basename(sys.argv[0])
-    print "usage: %s [-f config] [-c collection_path] [-H calendar_home_path] [-u user]" % (name,)
+    print "usage: %s [options] [input_specifiers]" % (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 "  -h --help: print this help and exit"
     print "  -f --config: Specify caldavd.plist configuration path"
+    print "  -o --output: Specify output file path (default: '-', meaning stdout)"
+    print ""
+    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)"
@@ -57,8 +60,9 @@
 def main():
     try:
         (optargs, args) = getopt(
-            sys.argv[1:], "hf:c:H:u:", [
+            sys.argv[1:], "hf:o:c:H:u:", [
                 "config=",
+                "output=",
                 "help",
                 "collection=", "home=", "user=",
             ],
@@ -67,6 +71,7 @@
         usage(e)
 
     configFileName = None
+    outputFileName = None
 
     collections = set()
     calendarHomes = set()
@@ -84,6 +89,12 @@
         elif opt in ("-f", "--config"):
             configFileName = arg
 
+        elif opt in ("-o", "--output"):
+            if arg == "-":
+                outputFileName = None
+            else:
+                outputFileName = arg
+
         elif opt in ("-c", "--collection"):
             path = abspath(arg)
             collection = CalDAVFile(path)
@@ -156,8 +167,19 @@
 
                     calendar.addComponent(component)
 
-        print calendar
+        calendarData = str(calendar)
 
+        if outputFileName:
+            try:
+                output = open(outputFileName, "w")
+            except IOError, e:
+                sys.stderr.write("Unable to open output file for writing %s: %s\n" % (outputFileName, e))
+                sys.exit(1)
+        else:
+            output = sys.stdout
+
+        output.write(calendarData)
+
     except UsageError, e:
         usage(e)
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20081031/0a028f35/attachment-0001.html>


More information about the calendarserver-changes mailing list