Changeset 2056

Show
Ignore:
Timestamp:
05/27/07 06:39:02 (19 months ago)
Author:
abaumann
Message:

make sure all XML data is sorted by tag name
the new merger code requires this :(

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • plugins/moto-sync/motosync.py

    r2055 r2056  
    4444SUPPORTED_OBJTYPES = ['event', 'contact'] 
    4545 
    46 CAPABILITIES = """<?xml version="1.0"?> 
     46CAPABILITIES = """<?xml version="1.0" encoding="UTF-8" standalone="yes"?> 
    4747<capabilities> 
    4848    <contact> 
     
    5757    </contact> 
    5858    <event> 
     59        <Alarm /> 
     60        <DateEnd /> 
     61        <DateStarted /> 
     62        <Duration /> 
     63        <ExceptionDateTime /> 
     64        <RecurrenceRule /> 
    5965        <Summary /> 
    60         <DateStarted /> 
    61         <DateEnd /> 
    62         <Duration /> 
    63         <Alarm /> 
    64         <RecurrenceRule /> 
    65         <ExceptionDateTime /> 
    6666    </event> 
    6767</capabilities> 
     
    919919        top = doc.documentElement 
    920920 
    921         e = doc.createElement('Summary') 
    922         appendXMLChild(doc, e, 'Content', self.name) 
    923         top.appendChild(e) 
    924  
    925         e = doc.createElement('DateStarted') 
    926         if isinstance(self.eventdt, datetime): 
    927             dtstart = self.eventdt.strftime(VCAL_DATETIME) 
    928         else: 
    929             dtstart = self.eventdt.strftime(VCAL_DATE) 
    930             e.setAttribute('Value', 'DATE') 
    931         appendXMLChild(doc, e, 'Content', dtstart) 
    932         top.appendChild(e) 
    933  
    934         e = doc.createElement('DateEnd') 
    935         endtime = self.eventdt + self.duration 
    936         if isinstance(self.eventdt, datetime): 
    937             dtend = endtime.strftime(VCAL_DATETIME) 
    938         else: 
    939             dtend = endtime.strftime(VCAL_DATE) 
    940             e.setAttribute('Value', 'DATE') 
    941         appendXMLChild(doc, e, 'Content', dtend) 
    942         top.appendChild(e) 
    943  
    944921        if self.alarmdt: 
    945922            alarm = doc.createElement('Alarm') 
     
    951928            appendXMLChild(doc, alarm, 'AlarmTrigger', alarmtime) 
    952929            top.appendChild(alarm) 
     930 
     931        e = doc.createElement('DateEnd') 
     932        endtime = self.eventdt + self.duration 
     933        if isinstance(self.eventdt, datetime): 
     934            dtend = endtime.strftime(VCAL_DATETIME) 
     935        else: 
     936            dtend = endtime.strftime(VCAL_DATE) 
     937            e.setAttribute('Value', 'DATE') 
     938        appendXMLChild(doc, e, 'Content', dtend) 
     939        top.appendChild(e) 
     940 
     941        e = doc.createElement('DateStarted') 
     942        if isinstance(self.eventdt, datetime): 
     943            dtstart = self.eventdt.strftime(VCAL_DATETIME) 
     944        else: 
     945            dtstart = self.eventdt.strftime(VCAL_DATE) 
     946            e.setAttribute('Value', 'DATE') 
     947        appendXMLChild(doc, e, 'Content', dtstart) 
     948        top.appendChild(e) 
     949 
     950        if self.exceptions != []: 
     951            assert(self.repeat_type != MOTO_REPEAT_NONE) 
     952 
     953            # create an rrule object for this recurrence 
     954            if self.repeat_type == MOTO_REPEAT_MONTHLY_DATE: 
     955                rrule = dateutil.rrule.rrule(dateutil.rrule.MONTHLY, 
     956                                             bymonthday=self.eventdt.day, 
     957                                             dtstart=self.eventdt) 
     958            elif self.repeat_type == MOTO_REPEAT_MONTHLY_DAY: 
     959                weekday = dateutil.rrule.weekdays[self.eventdt.weekday()] 
     960                # weeknum is calculated above in the XML generation 
     961                rrule = dateutil.rrule.rrule(dateutil.rrule.MONTHLY, 
     962                                             byweekday=weekday(+weeknum), 
     963                                             dtstart=self.eventdt) 
     964            else: 
     965                if self.repeat_type == MOTO_REPEAT_DAILY: 
     966                    freq = dateutil.rrule.DAILY 
     967                elif self.repeat_type == MOTO_REPEAT_WEEKLY: 
     968                    freq = dateutil.rrule.WEEKLY 
     969                elif self.repeat_type == MOTO_REPEAT_YEARLY: 
     970                    freq = dateutil.rrule.YEARLY 
     971                rrule = dateutil.rrule.rrule(freq, dtstart=self.eventdt) 
     972 
     973            # work out which dates the exceptions correspond to and 
     974            # generate ExceptionDate nodes for them 
     975            e = doc.createElement('ExceptionDateTime') 
     976            e.setAttribute('Value', 'DATE') 
     977            for exnum in self.exceptions: 
     978                appendXMLChild(doc, e, 'Content', format_time(rrule[exnum], VCAL_DATE)) 
     979            if e.hasChildNodes(): 
     980                top.appendChild(e) 
    953981 
    954982        e = doc.createElement('RecurrenceRule') 
     
    9771005            top.appendChild(e) 
    9781006 
    979         if self.exceptions != []: 
    980             assert(self.repeat_type != MOTO_REPEAT_NONE) 
    981  
    982             # create an rrule object for this recurrence 
    983             if self.repeat_type == MOTO_REPEAT_MONTHLY_DATE: 
    984                 rrule = dateutil.rrule.rrule(dateutil.rrule.MONTHLY, 
    985                                              bymonthday=self.eventdt.day, 
    986                                              dtstart=self.eventdt) 
    987             elif self.repeat_type == MOTO_REPEAT_MONTHLY_DAY: 
    988                 weekday = dateutil.rrule.weekdays[self.eventdt.weekday()] 
    989                 # weeknum is calculated above in the XML generation 
    990                 rrule = dateutil.rrule.rrule(dateutil.rrule.MONTHLY, 
    991                                              byweekday=weekday(+weeknum), 
    992                                              dtstart=self.eventdt) 
    993             else: 
    994                 if self.repeat_type == MOTO_REPEAT_DAILY: 
    995                     freq = dateutil.rrule.DAILY 
    996                 elif self.repeat_type == MOTO_REPEAT_WEEKLY: 
    997                     freq = dateutil.rrule.WEEKLY 
    998                 elif self.repeat_type == MOTO_REPEAT_YEARLY: 
    999                     freq = dateutil.rrule.YEARLY 
    1000                 rrule = dateutil.rrule.rrule(freq, dtstart=self.eventdt) 
    1001  
    1002             # work out which dates the exceptions correspond to and 
    1003             # generate ExceptionDate nodes for them 
    1004             e = doc.createElement('ExceptionDateTime') 
    1005             e.setAttribute('Value', 'DATE') 
    1006             for exnum in self.exceptions: 
    1007                 appendXMLChild(doc, e, 'Content', format_time(rrule[exnum], VCAL_DATE)) 
    1008             if e.hasChildNodes(): 
    1009                 top.appendChild(e) 
     1007        e = doc.createElement('Summary') 
     1008        appendXMLChild(doc, e, 'Content', self.name) 
     1009        top.appendChild(e) 
    10101010 
    10111011        return doc.toxml() 
     
    12301230        top = doc.documentElement 
    12311231 
     1232        if self.birthday: 
     1233            bdaystr = format_time(self.birthday, VCAL_DATE) 
     1234            e = doc.createElement('Birthday') 
     1235            appendXMLChild(doc, e, 'Content', bdaystr) 
     1236            top.appendChild(e) 
     1237 
     1238        e = doc.createElement('Categories') 
     1239        appendXMLChild(doc, e, 'Category', categories[self.categorynum]) 
     1240        top.appendChild(e) 
     1241 
    12321242        e = doc.createElement('FormattedName') 
    12331243        appendXMLChild(doc, e, 'Content', self.name) 
     
    12541264            top.appendChild(e) 
    12551265 
    1256         if self.birthday: 
    1257             bdaystr = format_time(self.birthday, VCAL_DATE) 
    1258             e = doc.createElement('Birthday') 
    1259             appendXMLChild(doc, e, 'Content', bdaystr) 
    1260             top.appendChild(e) 
    1261  
    1262         e = doc.createElement('Categories') 
    1263         appendXMLChild(doc, e, 'Category', categories[self.categorynum]) 
    1264         top.appendChild(e) 
    1265  
    12661266        for child in self.children: 
    1267             for node in child.child_xml(doc): 
    1268                 top.appendChild(node) 
     1267            for newnode in child.child_xml(doc): 
     1268                # insert the child to maintain alphabetic order of the nodes 
     1269                # unfortunately the merger code requires this order 
     1270                for node in top.childNodes: 
     1271                    if newnode.nodeName < node.nodeName: 
     1272                        top.insertBefore(newnode, node) 
     1273                        break 
     1274                else: 
     1275                    top.appendChild(newnode) 
    12691276 
    12701277        return doc.toxml() 
     
    14721479        ret = [] 
    14731480 
     1481        if self.address: 
     1482            e = doc.createElement('Address') 
     1483            for (part, val) in zip(XML_ADDRESS_PARTS, self.address): 
     1484                appendXMLChild(doc, e, part, val) 
     1485            if e.hasChildNodes(): 
     1486                if MOTO_ADDRESS_TYPES.has_key(self.contacttype): 
     1487                    e.setAttribute('Location', MOTO_ADDRESS_TYPES[self.contacttype].upper()) 
     1488                ret.append(e) 
     1489 
    14741490        if self.contacttype == MOTO_CONTACT_EMAIL: 
    14751491            e = doc.createElement('EMail') 
     
    14871503        appendXMLChild(doc, e, 'Content', self.contact) 
    14881504        ret.append(e) 
    1489  
    1490         if self.address: 
    1491             e = doc.createElement('Address') 
    1492             for (part, val) in zip(XML_ADDRESS_PARTS, self.address): 
    1493                 appendXMLChild(doc, e, part, val) 
    1494             if e.hasChildNodes(): 
    1495                 if MOTO_ADDRESS_TYPES.has_key(self.contacttype): 
    1496                     e.setAttribute('Location', MOTO_ADDRESS_TYPES[self.contacttype].upper()) 
    1497                 ret.append(e) 
    14981505 
    14991506        return ret