[CalendarServer-changes] [4772] CalendarServer/trunk/calendarserver/tools/fixcalendardata.py
source_changes at macosforge.org
source_changes at macosforge.org
Wed Nov 18 12:35:34 PST 2009
Revision: 4772
http://trac.macosforge.org/projects/calendarserver/changeset/4772
Author: cdaboo at apple.com
Date: 2009-11-18 12:35:33 -0800 (Wed, 18 Nov 2009)
Log Message:
-----------
Fix broken multiple VALARM ics data.
Modified Paths:
--------------
CalendarServer/trunk/calendarserver/tools/fixcalendardata.py
Modified: CalendarServer/trunk/calendarserver/tools/fixcalendardata.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/fixcalendardata.py 2009-11-18 20:33:42 UTC (rev 4771)
+++ CalendarServer/trunk/calendarserver/tools/fixcalendardata.py 2009-11-18 20:35:33 UTC (rev 4772)
@@ -136,15 +136,25 @@
if f:
f.close()
- # See whether there is a \" that needs fixing.
- # NB Have to handle the case of a folded line...
- if testICSData_DoubleQuotes(icsData) or testICSData_TZIDs(icsData):
+ # See what needs fixing.
+ problems = []
+ fixQuotes = fixTZIDs = fixMultiVALARMs = False
+ if testICSData_DoubleQuotes(icsData):
+ problems.append("double quotes")
+ fixQuotes = True
+ if testICSData_TZIDs(icsData):
+ problems.append("tzids")
+ fixTZIDs = True
+ if testICSData_MultipleVALARMS(icsData):
+ problems.append("multi-valarms")
+ fixMultiVALARMs = True
+ if problems:
if doFix:
- if fixPath(icsPath, icsData):
+ if fixPath(icsPath, icsData, fixQuotes, fixTZIDs, fixMultiVALARMs):
didFix = True
- print "Problem fixed in: <BasePath>%s" % (icsPath[basePathLength:],)
+ print "Problems %s fixed in: <BasePath>%s" % (",".join(problems), icsPath[basePathLength:],)
else:
- print "Problem found in: <BasePath>%s" % (icsPath[basePathLength:],)
+ print "Problem %s found in: <BasePath>%s" % (",".join(problems), icsPath[basePathLength:],)
scanFile.write(icsPath + "\n")
totalProblems += 1
@@ -165,6 +175,10 @@
return tzidRESearch.search(icsData) != None
+def testICSData_MultipleVALARMS(icsData):
+
+ return icsData.find("END:VALARM\r\nBEGIN:VALARM") != -1
+
def fixData(basePath, scanPath):
global totalProblems
@@ -204,7 +218,7 @@
if didFix:
updateCtag(calendarPath)
-def fixPath(icsPath, icsData=None):
+def fixPath(icsPath, icsData=None, doQuotes=True, doTZIDs=True, doMultiVALARMs=True):
global totalProblems
global totalErrors
@@ -224,21 +238,35 @@
f.close()
# Fix by continuously replacing \" with " until no more replacements occur
- while True:
- newIcsData = icsData.replace('\\"', '"').replace('\\\r\n "', '\r\n "').replace('\r\n \r\n "', '\r\n "')
- if newIcsData == icsData:
- break
- else:
- icsData = newIcsData
+ if doQuotes:
+ while True:
+ newIcsData = icsData.replace('\\"', '"').replace('\\\r\n "', '\r\n "').replace('\r\n \r\n "', '\r\n "')
+ if newIcsData == icsData:
+ break
+ 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
+ if doTZIDs:
+ while True:
+ icsMatch = tzidREReplace.search(icsData)
+ if icsMatch is not None:
+ icsData = icsMatch.expand("\\1\\2")
+ else:
+ break
+ if doMultiVALARMs:
+ lines = icsData.split("BEGIN:")
+ newlines = []
+ lastalarm = False
+ for line in lines:
+ isalarm = line.startswith("VALARM")
+ if lastalarm and isalarm:
+ newlines.pop()
+ newlines.append(line)
+ lastalarm = isalarm
+ icsData = "BEGIN:".join(newlines)
+
try:
f = None
f = open(icsPath, "w")
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20091118/ab8f2d14/attachment.html>
More information about the calendarserver-changes
mailing list