[CalendarServer-changes] [3691] CalendarServer/branches/users/sagen/migration-3686/twistedcaldav
source_changes at macosforge.org
source_changes at macosforge.org
Thu Feb 19 13:45:43 PST 2009
Revision: 3691
http://trac.macosforge.org/projects/calendarserver/changeset/3691
Author: sagen at apple.com
Date: 2009-02-19 13:45:42 -0800 (Thu, 19 Feb 2009)
Log Message:
-----------
Make the CUAddr normalization code reusable
Modified Paths:
--------------
CalendarServer/branches/users/sagen/migration-3686/twistedcaldav/ical.py
CalendarServer/branches/users/sagen/migration-3686/twistedcaldav/resource.py
CalendarServer/branches/users/sagen/migration-3686/twistedcaldav/upgrade.py
Modified: CalendarServer/branches/users/sagen/migration-3686/twistedcaldav/ical.py
===================================================================
--- CalendarServer/branches/users/sagen/migration-3686/twistedcaldav/ical.py 2009-02-19 20:50:04 UTC (rev 3690)
+++ CalendarServer/branches/users/sagen/migration-3686/twistedcaldav/ical.py 2009-02-19 21:45:42 UTC (rev 3691)
@@ -45,6 +45,7 @@
import cStringIO as StringIO
import datetime
import heapq
+import itertools
log = Logger()
@@ -1808,6 +1809,66 @@
if dataValue.find(dropboxPrefix) != -1:
component.removeProperty(attachment)
+ def normalizeCalendarUserAddresses(self, lookupFunction):
+ """
+ Do the ORGANIZER/ATTENDEE property normalization.
+
+ @param lookupFunction: function returning full name, guid, CUAs for a given CUA
+ @type lookupFunction: L{Function}
+ """
+ for component in self.subcomponents():
+ if component.name() == "VTIMEZONE":
+ continue
+ for prop in itertools.chain(
+ component.properties("ORGANIZER"),
+ component.properties("ATTENDEE")
+ ):
+
+ # Check that we can lookup this calendar user address - if not
+ # we cannot do anything with it
+ cuaddr = normalizeCUAddr(prop.value())
+ name, guid, cuaddrs = lookupFunction(cuaddr)
+ if guid is None:
+ continue
+
+ # Always re-write value to urn:uuid
+ prop.setValue("urn:uuid:%s" % (guid,))
+
+ # Always re-write the CN parameter
+ if name:
+ prop.params()["CN"] = [name,]
+ else:
+ try:
+ del prop.params()["CN"]
+ except KeyError:
+ pass
+
+ # Re-write the X-CALENDARSERVER-EMAIL if its value no longer
+ # matches
+ oldemail = prop.params().get("X-CALENDARSERVER-EMAIL",
+ (None,))[0]
+ if oldemail:
+ oldemail = "mailto:%s" % (oldemail,)
+ if oldemail is None or oldemail not in cuaddrs:
+ if cuaddr.startswith("mailto:") and cuaddr in cuaddrs:
+ email = cuaddr[7:]
+ else:
+ for addr in cuaddrs:
+ if addr.startswith("mailto:"):
+ email = addr[7:]
+ break
+ else:
+ email = None
+
+ if email:
+ prop.params()["X-CALENDARSERVER-EMAIL"] = [email,]
+ else:
+ try:
+ del prop.params()["X-CALENDARSERVER-EMAIL"]
+ except KeyError:
+ pass
+
+
##
# Dates and date-times
##
Modified: CalendarServer/branches/users/sagen/migration-3686/twistedcaldav/resource.py
===================================================================
--- CalendarServer/branches/users/sagen/migration-3686/twistedcaldav/resource.py 2009-02-19 20:50:04 UTC (rev 3690)
+++ CalendarServer/branches/users/sagen/migration-3686/twistedcaldav/resource.py 2009-02-19 21:45:42 UTC (rev 3691)
@@ -652,64 +652,17 @@
@param ical: calendar object to normalize.
@type ical: L{Component}
"""
-
- def normalizeCalendarUserAddress(prop):
- """
- Do the ORGANIZER/ATTENDEE property normalization.
- @param prop: organizer/attendee property
- @type prop: L{Property}
- """
-
- # Check that we have a principal for this calendar user address - if not we
- # cannot do anything with it
- cuaddr = normalizeCUAddr(prop.value())
+ def lookupFunction(cuaddr):
principal = self.principalForCalendarUserAddress(cuaddr)
if principal is None:
- return
-
- # Always re-write value to urn:uuid
- prop.setValue("urn:uuid:%s" % (principal.record.guid,))
-
- # Always re-write the CN parameter
- if principal.record.fullName:
- prop.params()["CN"] = [principal.record.fullName,]
+ return (None, None, None)
else:
- try:
- del prop.params()["CN"]
- except KeyError:
- pass
+ return (principal.record.fullName, principal.record.guid,
+ principal.record.calendarUserAddresses)
- # Re-write the X-CALENDARSERVER-EMAIL if its value no longer matches
- oldemail = prop.params().get("X-CALENDARSERVER-EMAIL", (None,))[0]
- if oldemail:
- oldemail = "mailto:%s" % (oldemail,)
- if oldemail is None or oldemail not in principal.record.calendarUserAddresses:
- if cuaddr.startswith("mailto:") and cuaddr in principal.record.calendarUserAddresses:
- email = cuaddr[7:]
- else:
- for addr in principal.record.calendarUserAddresses:
- if addr.startswith("mailto:"):
- email = addr[7:]
- break
- else:
- email = None
-
- if email:
- prop.params()["X-CALENDARSERVER-EMAIL"] = [email,]
- else:
- try:
- del prop.params()["X-CALENDARSERVER-EMAIL"]
- except KeyError:
- pass
+ ical.normalizeCalendarUserAddresses(lookupFunction)
- for component in ical.subcomponents():
- if component.name() != "VTIMEZONE":
- for prop in itertools.chain(
- component.properties("ORGANIZER"),
- component.properties("ATTENDEE")
- ):
- normalizeCalendarUserAddress(prop)
def principalForCalendarUserAddress(self, address):
for principalCollection in self.principalCollections():
Modified: CalendarServer/branches/users/sagen/migration-3686/twistedcaldav/upgrade.py
===================================================================
--- CalendarServer/branches/users/sagen/migration-3686/twistedcaldav/upgrade.py 2009-02-19 20:50:04 UTC (rev 3690)
+++ CalendarServer/branches/users/sagen/migration-3686/twistedcaldav/upgrade.py 2009-02-19 21:45:42 UTC (rev 3691)
@@ -55,55 +55,22 @@
def normalizeCUAddrs(data, directory):
cal = Component.fromString(data)
- print cal
- for component in cal.subcomponents():
- if component.name() != "VTIMEZONE":
- for prop in itertools.chain(
- component.properties("ORGANIZER"),
- component.properties("ATTENDEE"),
- ):
- cua = normalizeCUAddr(prop.value())
- try:
- principal = directory.principalForCalendarUserAddress(cua)
- except Exception, e:
- # lookup failed
- log.debug("Lookup of %s failed: %s" % (cua, e))
- principal = None
- if principal is not None:
- prop.setValue("urn:uuid:%s" % (principal.record.guid,))
- if principal.record.fullName:
- prop.params()["CN"] = [principal.record.fullName,]
- else:
- try:
- del prop.params()["CN"]
- except KeyError:
- pass
+ def lookupFunction(cuaddr):
+ try:
+ principal = directory.principalForCalendarUserAddress(cuaddr)
+ except Exception, e:
+ log.debug("Lookup of %s failed: %s" % (cuaddr, e))
+ principal = None
- # Re-write the X-CALENDARSERVER-EMAIL if its value no longer matches
- oldEmail = prop.params().get("X-CALENDARSERVER-EMAIL", (None,))[0]
- if oldEmail:
- oldEmail = "mailto:%s" % (oldEmail,)
+ if principal is None:
+ return (None, None, None)
+ else:
+ return (principal.record.fullName, principal.record.guid,
+ principal.record.calendarUserAddresses)
- if oldEmail is None or oldEmail not in principal.record.calendarUserAddresses:
- if cua.startswith("mailto:") and cua in principal.record.calendarUserAddresses:
- email = cua[7:]
- else:
- for addr in principal.record.calendarUserAddresses:
- if addr.startswith("mailto:"):
- email = addr[7:]
- break
- else:
- email = None
+ cal.normalizeCalendarUserAddresses(lookupFunction)
- if email:
- prop.params()["X-CALENDARSERVER-EMAIL"] = [email,]
- else:
- try:
- del prop.params()["X-CALENDARSERVER-EMAIL"]
- except KeyError:
- pass
-
newData = str(cal)
return newData, not newData == data
@@ -112,29 +79,35 @@
os.rename(oldCal, newCal)
for resource in os.listdir(newCal):
- resourcePath = os.path.join(newCal, resource)
- # MOR: Is this the proper way to tell we have a caldav resource?
- # (".ics" extension-checking doesn't seem safe)
- xattrs = xattr.xattr(resourcePath)
- if not xattrs.has_key("WebDAV:{DAV:}getcontenttype"):
+ if resource.startswith("."):
continue
+ resourcePath = os.path.join(newCal, resource)
+
log.info("Processing: %s" % (resourcePath,))
needsRewrite = False
with open(resourcePath) as res:
data = res.read()
- data, fixed = fixBadQuotes(data)
- if fixed:
- needsRewrite = True
- log.info("Fixing bad quotes in %s" % (resourcePath,))
+ try:
+ data, fixed = fixBadQuotes(data)
+ if fixed:
+ needsRewrite = True
+ log.info("Fixing bad quotes in %s" % (resourcePath,))
+ except Exception, e:
+ log.error("Error while fixing bad quotes in %s: %s" %
+ (resourcePath, e))
- data, fixed = normalizeCUAddrs(data, directory)
- if fixed:
- needsRewrite = True
- log.info("Normalized CUAddrs in %s" % (resourcePath,))
- print "NORMALIZED TO:\n%s" % (data,)
+ try:
+ data, fixed = normalizeCUAddrs(data, directory)
+ if fixed:
+ needsRewrite = True
+ log.info("Normalized CUAddrs in %s" % (resourcePath,))
+ print "NORMALIZED TO:\n%s" % (data,)
+ except Exception, e:
+ log.error("Error while normalizing %s: %s" %
+ (resourcePath, e))
if needsRewrite:
with open(resourcePath, "w") as res:
@@ -226,7 +199,7 @@
# methods 3 through 5 (using 0-based array indexing) will be executed in
# order.
upgradeMethods = [
- upgradeLeopardToSnowLeopard,
+ upgrade_to_1,
]
@staticmethod
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20090219/a5d5f85d/attachment-0001.html>
More information about the calendarserver-changes
mailing list