Changeset 1793

Show
Ignore:
Timestamp:
02/21/07 11:05:18 (2 years ago)
Author:
abaumann
Message:

* protect against multiple calls to connect()
* add code to read mobile version/model information and report it
* use new xmlformat-*-doc formats

still broken, but now it doesn't crash! next, I need to update the XML

Files:

Legend:

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

    r1785 r1793  
    396396 
    397397    def connect(self): 
    398         """Connect to the phone and initiate communication.""" 
     398        """Connect to the phone and initiate communication. 
     399         
     400        Returns True on success, False if already connected. 
     401        """ 
     402        if (self.__fd or self.__btsock): 
     403            return False # already connected 
     404 
    399405        if BT_MAC_RE.match(self.devstr): 
    400406            assert(USE_BLUETOOTH_MODULE, 
     
    437443        self.contact_data_len = contactlen 
    438444        self.contact_name_len = namelen 
     445         
     446        return True 
    439447 
    440448    def disconnect(self): 
     
    452460        data = self.__do_cmd('AT+CGSN') 
    453461        return self.__parse_results('CGSN', data)[0][0] 
     462 
     463    def read_version(self): 
     464        """read the phone's software version number""" 
     465        data = self.__do_cmd('AT+CGMR') 
     466        return self.__parse_results('CGMR', data)[0][0] 
     467 
     468    def read_model(self): 
     469        """read the phone's hardware model number""" 
     470        data = self.__do_cmd('AT+CGMM') 
     471        for s in self.__parse_results('CGMM', data)[0]: 
     472            if s.startswith("MODEL="): 
     473                return s.split("=", 1)[1] 
     474        return None 
    454475 
    455476    def read_time(self): 
     
    14921513        self.categories = {} 
    14931514        self.revcategories = {} 
     1515        self.objformats = {} 
    14941516 
    14951517        # find ObjFormat objects for our types 
    1496         self.objformats = {} 
    14971518        for objtype in SUPPORTED_OBJTYPES: 
    1498             formatstr = "xml-%s-doc" % objtype 
    1499             self.objformats[objtype] = info.format_env.find_objformat(formatstr) 
     1519            formatstr = "xmlformat-%s-doc" % objtype 
     1520            formatobj = info.format_env.find_objformat(formatstr) 
     1521            if not formatobj: 
     1522                raise opensync.Error('object format %s unknown' % formatstr) 
     1523            self.objformats[objtype] = formatobj 
    15001524 
    15011525    def connect(self): 
    15021526        """Connect to the phone and setup our data structures.""" 
    1503         self.comms.connect() 
     1527        if not self.comms.connect(): 
     1528            return # already connected 
    15041529        self.serial = self.comms.read_serial() 
    15051530 
     
    16941719        opensync.ObjTypeSinkCallbacks.__init__(self, objtype) 
    16951720        self.objtype = objtype 
    1696         self.sink.add_objformat("xml-%s-doc" % objtype) 
     1721        self.sink.add_objformat("xmlformat-%s-doc" % objtype) 
    16971722        self.access = access 
    16981723        hashpath = os.path.join(info.configdir, "%s-hash.db" % objtype) 
     
    17661791    """Called by python-module plugin wrapper, registers sync classes.""" 
    17671792    comms = PhoneComms(parse_config(info.config)) 
    1768     access = PhoneAccess(comms
     1793    access = PhoneAccess(comms, info
    17691794    for objtype in SUPPORTED_OBJTYPES: 
    17701795        info.add_objtype(MotoSink(objtype, info, access).sink) 
     
    17721797def discover(info): 
    17731798    """Called by python-module wrapper, discovers capabilities of device.""" 
     1799    # HACK HACK, grab the comms object out of the initialised sink 
     1800    comms = info.nth_objtype(0).callback_obj.access.comms 
     1801    comms.connect() 
     1802    version = opensync.Version() 
     1803    version.plugin = "moto-sync" 
     1804    version.softwareversion = str(comms.read_version()) 
     1805    version.modelversion = str(comms.read_model()) 
     1806    version.identifier = str(comms.read_serial()) 
     1807    # FIXME: discover and set capabilities 
     1808    comms.disconnect() 
     1809    info.version = version 
     1810 
     1811    # for now, all objtypes are supported on all devices 
    17741812    for sink in info.objtypes: 
    17751813        sink.available = True 
    1776     info.version = opensync.Version() 
    1777     info.version.plugin = "moto-sync" 
    17781814 
    17791815def get_sync_info(plugin):