[CalendarServer-changes] [4177] CalendarServer/trunk/calendarserver/tools/fixcalendardata.py

source_changes at macosforge.org source_changes at macosforge.org
Tue May 5 12:42:01 PDT 2009


Revision: 4177
          http://trac.macosforge.org/projects/calendarserver/changeset/4177
Author:   cdaboo at apple.com
Date:     2009-05-05 12:42:00 -0700 (Tue, 05 May 2009)
Log Message:
-----------
Add fix for TZIDs present on a VALUE=DATE property.

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

Modified: CalendarServer/trunk/calendarserver/tools/fixcalendardata.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/fixcalendardata.py	2009-05-05 15:35:53 UTC (rev 4176)
+++ CalendarServer/trunk/calendarserver/tools/fixcalendardata.py	2009-05-05 19:42:00 UTC (rev 4177)
@@ -15,14 +15,15 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 ##
+
 from plistlib import readPlist
-import time
-
+import re
 import datetime
 import getopt
 import hashlib
 import os
 import sys
+import time
 import xattr
 
 PLIST_FILE = "/etc/caldavd/caldavd.plist"
@@ -41,6 +42,7 @@
     print "usage: %s [options]" % (name,)
     print ""
     print "Fix double-quote/escape bugs in iCalendar data."
+    print "Fix incorrect use of TZID in iCalendar data."
     print ""
     print "options:"
     print "  -h --help: print this help and exit"
@@ -82,12 +84,12 @@
 def scanData(basePath, scanFile, doFix):
     
     uidsPath = os.path.join(basePath, "calendars", "__uids__")
-    for i in range(256):
-        level1Path = os.path.join(uidsPath, "%02X" % (i,))
-        if os.path.exists(level1Path):
-            for j in range(256):
-                level2Path = os.path.join(level1Path, "%02X" % (j,))
-                if os.path.exists(level2Path):
+    for item1 in os.listdir(uidsPath):
+        if len(item1) == 2:
+            level1Path = os.path.join(uidsPath, item1)
+            for item2 in os.listdir(level1Path):
+                if len(item2) == 2:
+                    level2Path = os.path.join(level1Path, item2)
                     for item in os.listdir(level2Path):
                         calendarHome = os.path.join(level2Path, item)
                         if os.path.isdir(calendarHome):
@@ -136,7 +138,7 @@
 
         # See whether there is a \" that needs fixing.
         # NB Have to handle the case of a folded line... 
-        if icsData.find('\\"') != -1 or icsData.find('\\\r\n "') != -1 or icsData.find('\r\n \r\n "') != -1:
+        if testICSData_DoubleQuotes(icsData) or testICSData_TZIDs(icsData):
             if doFix:
                 if fixPath(icsPath, icsData):
                     didFix = True
@@ -150,6 +152,19 @@
     if didFix:
         updateCtag(calendarPath)
 
+def testICSData_DoubleQuotes(icsData):
+
+    # See whether there is a \" that needs fixing.
+    # NB Have to handle the case of a folded line... 
+    return icsData.find('\\"') != -1 or icsData.find('\\\r\n "') != -1 or icsData.find('\r\n \r\n "') != -1
+
+tzidRESearch = re.compile("(.*)TZID=[^;:]+;(VALUE=DATE.*)")
+tzidREReplace = re.compile("(.*)TZID=[^;:]+;(VALUE=DATE.*)", flags=re.S)
+
+def testICSData_TZIDs(icsData):
+    
+    return tzidRESearch.search(icsData) != None
+
 def fixData(basePath, scanPath):
     
     global totalProblems
@@ -216,6 +231,14 @@
         else:
             icsData = newIcsData
     
+    # Fix the TZID problem
+    while True:
+        icsMatch = tzidREReplace.search(icsData)
+        if icsMatch is not None:
+            icsData = icsMatch.expand("\\1\\2")
+        else:
+            break
+
     try:
         f = None
         f = open(icsPath, "w")
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20090505/b2f10e84/attachment-0001.html>


More information about the calendarserver-changes mailing list