Changeset 1807

Show
Ignore:
Timestamp:
02/24/07 06:31:43 (22 months ago)
Author:
abaumann
Message:

fix a bug writing where changes were rejected due to an invalid
objformat, even though the format was actually fine

strangely, this didn't prevent the sync from reporting success, even
though the commit function returned FALSE and reported an OSyncError?

also do some cleanup, white-space / line length changes

Files:
1 modified

Legend:

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

    r1797 r1807  
    166166# logical order of the fields in structured XML data 
    167167XML_NAME_PARTS = 'Prefix FirstName Additional LastName Suffix'.split() 
    168 XML_ADDRESS_PARTS = ('Street ExtendedAddress' 
    169                      + ' Locality Region PostalCode Country').split() 
     168XML_ADDRESS_PARTS = ('Street ExtendedAddress Locality Region PostalCode Country').split() 
    170169 
    171170# legal characters in telephone numbers 
     
    189188    """Like DOM's getElementsByTagName, but allow multiple tag names.""" 
    190189    for node in parent.childNodes: 
    191         if (node.nodeType == xml.dom.minidom.Node.ELEMENT_NODE 
    192             and node.tagName in tagnames): 
     190        if (node.nodeType == xml.dom.minidom.Node.ELEMENT_NODE and node.tagName in tagnames): 
    193191            ret.append(node) 
    194192        getElementsByTagNames(node, tagnames, ret) 
     
    241239DATETIME_PART = '(?:%s)?(?:%s)?' % (DATE_PART, TIME_PART) 
    242240WEEKS_PART = r'(\d+)W' 
    243 DURATION_REGEX = re.compile(r'([-+]?)P(?:%s|%s)$' 
    244                             % (WEEKS_PART, DATETIME_PART)) 
     241DURATION_REGEX = re.compile(r'([-+]?)P(?:%s|%s)$' % (WEEKS_PART, DATETIME_PART)) 
    245242 
    246243def parse_ical_duration(duratstr): 
     
    444441            # search for the port to use on the device 
    445442            port = BT_DEFAULT_CHANNEL 
    446             found = bluetooth.find_service(name=BT_SERVICE_NAME, 
    447                                            address=self.devstr) 
     443            found = bluetooth.find_service(name=BT_SERVICE_NAME, address=self.devstr) 
    448444            if found: 
    449445                assert(found[0]['protocol'] == 'RFCOMM') 
     
    562558            for (expos, exnum, extype) in self.__parse_results('MDBRE', data): 
    563559                if extype != 1: # haven't seen anything else 
    564                     raise opensync.Error('unexpected exception type %d'%extype) 
     560                    raise opensync.Error('unexpected exception type %d' % extype) 
    565561                if not exceptions.has_key(expos): 
    566562                    exceptions[expos] = [] 
     
    691687        debug('<-- ' + ret) 
    692688        if c == '': # EOF, shouldn't happen 
    693             raise opensync.Error('Unexpected EOF talking to phone', 
    694                                  opensync.ERROR_IO_ERROR) 
     689            raise opensync.Error('Unexpected EOF talking to phone', opensync.ERROR_IO_ERROR) 
    695690        return ret 
    696691 
     
    718713            return ret 
    719714        else: 
    720             raise opensync.Error("Error in phone command '%s'" % cmd, 
    721                                  opensync.ERROR_IO_ERROR) 
     715            raise opensync.Error("Error in phone command '%s'" % cmd, opensync.ERROR_IO_ERROR) 
    722716 
    723717    def __parse_results(self, restype, lines): 
     
    779773                return '%d' 
    780774            else: 
    781                 assert(t == types.StringType or t == types.UnicodeType, 
    782                        'unexpected type %s' % str(t)) 
     775                assert(t == types.StringType or t == types.UnicodeType, 'unexpected type %s' % str(t)) 
    783776                return '"%s"' 
    784777 
     
    1002995            e.setAttribute('DateValue', 'DATE') 
    1003996            for exnum in self.exceptions: 
    1004                 appendXMLChild(doc, e, 'Content', 
    1005                                format_time(rrule[exnum], VCAL_DATE)) 
     997                appendXMLChild(doc, e, 'Content', format_time(rrule[exnum], VCAL_DATE)) 
    1006998            if e.hasChildNodes(): 
    1007999                top.appendChild(e) 
     
    10661058        if event.getElementsByTagName('Duration') != []: 
    10671059            duration = event.getElementsByTagName('Duration')[0] 
    1068             def tryint(s): 
    1069                 if s == '': 
     1060            def toint(numstr): 
     1061                """Convert a string to an integer, unless it's empty, in which case return 0.""" 
     1062                if numstr == '': 
    10701063                    return 0 
    10711064                else: 
    1072                     return int(s) 
    1073             weeks = tryint(getXMLField(duration, 'Weeks')) 
    1074             days = tryint(getXMLField(duration, 'Days')) 
    1075             hours = tryint(getXMLField(duration, 'Hours')) 
    1076             mins = tryint(getXMLField(duration, 'Minutes')) 
    1077             secs = tryint(getXMLField(duration, 'Seconds')) 
    1078             self.duration = datetime.timedelta(weeks * 7 + days, (hours * 60 + mins) * 60 + secs) 
     1065                    return int(numstr) 
     1066            weeks = toint(getXMLField(duration, 'Weeks')) 
     1067            days = toint(getXMLField(duration, 'Days')) 
     1068            hours = toint(getXMLField(duration, 'Hours')) 
     1069            mins = toint(getXMLField(duration, 'Minutes')) 
     1070            secs = toint(getXMLField(duration, 'Seconds')) 
     1071            self.duration = timedelta(weeks * 7 + days, (hours * 60 + mins) * 60 + secs) 
    10791072        else: 
    10801073            endstr = getField('DateEnd') 
     
    11081101        exdates = event.getElementsByTagName('ExceptionDateTime') 
    11091102        exrules = event.getElementsByTagName('ExceptionRule') 
    1110         (self.repeat_type, self.exceptions) = convert_rrule(rrules, exdates, 
    1111                                                           exrules, self.eventdt) 
     1103        (self.repeat_type, self.exceptions) = convert_rrule(rrules, exdates, exrules, self.eventdt) 
    11121104 
    11131105        if len(rrules) > 0 and self.repeat_type == MOTO_REPEAT_NONE: 
     
    14741466        elif self.contacttype == MOTO_CONTACT_MAILINGLIST: 
    14751467            # the 'contact' is a space-separated list of other contact positions 
    1476             assert(False, "mailing lists aren't handled yet, sorry") # FIXME 
     1468            assert(False, "mailing lists aren't handled yet, sorry") # FIXME: implement mailing lists 
    14771469        else: 
    14781470            e = doc.createElement('Telephone') 
     
    14921484            if e.hasChildNodes(): 
    14931485                if MOTO_ADDRESS_TYPES.has_key(self.contacttype): 
    1494                     e.setAttribute('Location', 
    1495                                    MOTO_ADDRESS_TYPES[self.contacttype].upper()) 
     1486                    e.setAttribute('Location', MOTO_ADDRESS_TYPES[self.contacttype].upper()) 
    14961487                ret.append(e) 
    14971488 
     
    15811572        for (bit, desc) in REQUIRED_FEATURES: 
    15821573            if not features[bit]: 
    1583                 raise opensync.Error(desc + ' feature not present', 
    1584                                      opensync.ERROR_NOT_SUPPORTED) 
     1574                raise opensync.Error(desc + ' feature not present', opensync.ERROR_NOT_SUPPORTED) 
    15851575 
    15861576        # read current time on the phone, check if it matches our local time 
     
    15951585 
    15961586        # initialise the position allocators 
    1597         self.positions['event'] = PosAllocator('event', 0, 
    1598                                                self.comms.max_events - 1) 
     1587        self.positions['event'] = PosAllocator('event', 0, self.comms.max_events - 1) 
    15991588        min_contact = max(self.comms.min_contact_pos, MOTO_QUICKDIAL_ENTRIES) 
    1600         self.positions['contact'] = PosAllocator('contact', min_contact, 
    1601                                                  self.comms.max_contact_pos) 
     1589        self.positions['contact'] = PosAllocator('contact', min_contact, self.comms.max_contact_pos) 
    16021590 
    16031591        # initialise the category mappings 
     
    16321620            else: 
    16331621                xmldata = entry.to_xml() 
    1634             print xmldata 
    16351622            data = opensync.Data(xmldata, self.objformats[objtype]) 
    16361623            data.objtype = objtype 
     
    16631650        """ 
    16641651        objtype = change.objtype 
    1665         if change.objformat != self.objformats[objtype]: 
    1666             raise opensync.Error("unhandled data format "+change.objformat.name, 
    1667                                  opensync.ERROR_NOT_SUPPORTED) 
     1652        if change.objformat.name != self.objformats[objtype].name: 
     1653            raise opensync.Error("unhandled data format " + change.objformat.name, opensync.ERROR_NOT_SUPPORTED) 
    16681654        try: 
    16691655            if objtype == 'event': 
     
    16761662            # if its modified and we've seen it before, delete it 
    16771663            # otherwise just ignore it 
    1678             if (change.changetype == opensync.CHANGE_TYPE_MODIFIED 
    1679                 and self.uid_seen(change.uid)): 
     1664            if (change.changetype == opensync.CHANGE_TYPE_MODIFIED and self.uid_seen(change.uid)): 
    16801665                change.changetype = opensync.CHANGE_TYPE_DELETED 
    16811666                change.data = None 
     
    16831668            else: 
    16841669                return False 
    1685          
    16861670        if change.changetype == opensync.CHANGE_TYPE_ADDED: 
    16871671            # allocate positions for the new entry 
     
    17051689                self.positions[objtype].mark_free(free_positions) 
    17061690            entry.set_pos(positions) 
    1707          
    17081691        entry.write(self.comms) 
    17091692        change.uid = self.__generate_uid(entry) 
     
    17401723        Uses the last 8 digit's of the phone's IMEI to do so. 
    17411724        """ 
    1742         return ("moto-%s-%s@%s" 
    1743                 % (entry.get_objtype(), entry.generate_uid(), self.serial[-8:])) 
     1725        return ("moto-%s-%s@%s" % (entry.get_objtype(), entry.generate_uid(), self.serial[-8:])) 
    17441726 
    17451727    def __uid_to_pos(self, uid): 
     
    17491731        """ 
    17501732        moto, objtype, lastpart = uid.split('-', 2) 
    1751         assert(moto == "moto" and objtype in SUPPORTED_OBJTYPES, 
    1752                'Invalid UID: %s' % uid) 
     1733        assert(moto == "moto" and objtype in SUPPORTED_OBJTYPES, 'Invalid UID: %s' % uid) 
    17531734        lastpos = lastpart.rindex('@') 
    1754         assert(lastpart[lastpos + 1:] == self.serial[-8:], 
    1755                'Entry not created on this phone') 
     1735        assert(lastpart[lastpos + 1:] == self.serial[-8:], 'Entry not created on this phone') 
    17561736         
    17571737        if objtype == "event": 
     
    17831763        for change in self.access.list_changes(self.objtype): 
    17841764            self.hashtable.report(change.uid) 
    1785             change.changetype = self.hashtable.get_changetype(change.uid, 
    1786                                                               change.hash) 
     1765            change.changetype = self.hashtable.get_changetype(change.uid, change.hash) 
    17871766            if change.changetype != opensync.CHANGE_TYPE_UNMODIFIED: 
    1788                 self.hashtable.update_hash(change.changetype, change.uid, 
    1789                                            change.hash) 
     1767                self.hashtable.update_hash(change.changetype, change.uid, change.hash) 
    17901768                ctx.report_change(change) 
    17911769        for uid in self.hashtable.get_deleted(): 
     
    17991777        """Write a change to the phone.""" 
    18001778        if change.objtype != self.objtype: 
    1801             raise opensync.Error('unsupported objtype %s' % change.objtype, 
    1802                                  opensync.ERROR_NOT_SUPPORTED) 
    1803         if change.changetype != opensync.CHANGE_TYPE_DELETED: 
    1804             print "\nOpenSync wants me to write:\n", change.data.data 
     1779            raise opensync.Error('unsupported objtype %s' % change.objtype, opensync.ERROR_NOT_SUPPORTED) 
    18051780        if change.changetype == opensync.CHANGE_TYPE_DELETED: 
    1806             success = (self.access.uid_seen(change.uid) 
    1807                        and self.access.delete_entry(change.uid)) 
     1781            success = (self.access.uid_seen(change.uid) and self.access.delete_entry(change.uid)) 
    18081782        elif change.changetype == opensync.CHANGE_TYPE_MODIFIED: 
    18091783            old_uid = change.uid 
     
    18121786            # the old one was deleted, to keep it consistent 
    18131787            if (success and old_uid != change.uid): 
    1814                 self.hashtable.update_hash(opensync.CHANGE_TYPE_DELETED, 
    1815                                            old_uid, None) 
     1788                self.hashtable.update_hash(opensync.CHANGE_TYPE_DELETED, old_uid, None) 
    18161789        else: 
    18171790            success = self.access.update_entry(change) 
    18181791        if success: 
    1819             self.hashtable.update_hash(change.changetype, change.uid, 
    1820                                        change.hash) 
     1792            self.hashtable.update_hash(change.changetype, change.uid, change.hash) 
    18211793 
    18221794    def disconnect(self, info, ctx): 
     
    18301802        doc = xml.dom.minidom.parseString(configstr) 
    18311803    except: 
    1832         raise opensync.Error('failed to parse config data', 
    1833                              opensync.ERROR_MISCONFIGURATION) 
     1804        raise opensync.Error('failed to parse config data', opensync.ERROR_MISCONFIGURATION) 
    18341805 
    18351806    ret = getXMLField(doc, 'device').strip() 
    18361807    if ret == '': 
    1837         raise opensync.Error('device not specified in config file', 
    1838                              opensync.ERROR_MISCONFIGURATION) 
     1808        raise opensync.Error('device not specified in config file', opensync.ERROR_MISCONFIGURATION) 
    18391809    return ret 
    18401810