[CalendarServer-changes] [6394] CalendarServer/trunk/contrib/tools/sortrecurrences.py
source_changes at macosforge.org
source_changes at macosforge.org
Thu Sep 30 13:03:14 PDT 2010
Revision: 6394
http://trac.macosforge.org/projects/calendarserver/changeset/6394
Author: cdaboo at apple.com
Date: 2010-09-30 13:03:12 -0700 (Thu, 30 Sep 2010)
Log Message:
-----------
Utility to sort iCalendar VEVENT components by recurrence-id to make it easier to compare multiple .ics's.
Added Paths:
-----------
CalendarServer/trunk/contrib/tools/sortrecurrences.py
Added: CalendarServer/trunk/contrib/tools/sortrecurrences.py
===================================================================
--- CalendarServer/trunk/contrib/tools/sortrecurrences.py (rev 0)
+++ CalendarServer/trunk/contrib/tools/sortrecurrences.py 2010-09-30 20:03:12 UTC (rev 6394)
@@ -0,0 +1,80 @@
+#!/usr/bin/env python
+##
+# Copyright (c) 2010 Apple Inc. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+##
+
+import getopt
+import os
+import sys
+import traceback
+import vobject
+
+def usage(error_msg=None):
+ if error_msg:
+ print error_msg
+
+ print """Usage: sortrecurrences FILE
+Options:
+ -h Print this help and exit
+
+Arguments:
+ FILE File name for the calendar data to sort
+
+Description:
+ This utility will output a sorted iCalendar component.
+
+"""
+
+ if error_msg:
+ raise ValueError(error_msg)
+ else:
+ sys.exit(0)
+
+if __name__ == "__main__":
+
+ try:
+
+ options, args = getopt.getopt(sys.argv[1:], "h", [])
+
+ for option, value in options:
+ if option == "-h":
+ usage()
+ else:
+ usage("Unrecognized option: %s" % (option,))
+
+ # Process arguments
+ if len(args) != 1:
+ usage("Must have one argument")
+
+ pwd = os.getcwd()
+
+ analyzers = []
+ for arg in args:
+ arg = os.path.expanduser(arg)
+ if not arg.startswith("/"):
+ arg = os.path.join(pwd, arg)
+ if arg.endswith("/"):
+ arg = arg[:-1]
+ if not os.path.exists(arg):
+ print "Path does not exist: '%s'. Ignoring." % (arg,)
+ continue
+
+ cal = vobject.base.readOne(open(arg))
+ cal.contents['vevent'].sort(key=lambda x:str(x.contents.get('recurrence-id', (vobject.base.ContentLine("recurrence-id", {}, ""),)[0].value)))
+ print cal.serialize()
+
+ except Exception, e:
+ sys.exit(str(e))
+ print traceback.print_exc()
Property changes on: CalendarServer/trunk/contrib/tools/sortrecurrences.py
___________________________________________________________________
Added: svn:executable
+ *
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20100930/45b271a3/attachment-0001.html>
More information about the calendarserver-changes
mailing list