def _makeAdapter(self):
self._callHooks('<STR_LIT>')<EOL>context = pysyncml.Context(storage='<STR_LIT>' % (self.dataDir,),<EOL>owner=None, autoCommit=True)<EOL>self._callHooks('<STR_LIT>', context)<EOL>adapter = context.Adapter()<EOL>if hasattr(self, '<STR_LIT>') and self.serverConf.policy is not None:<EOL><INDENT>adapter.conflictPolicy = self.serverConf.policy<EOL><DEDENT>if self.options.name is not None or self.appDisplay is not None:<EOL><INDENT>adapter.name = self.options.name or self.appDisplay<EOL><DEDENT>if adapter.devinfo is None:<EOL><INDENT>log.info('<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>if self.options.devid is not None and self.options.devid != adapter.devinfo.devID:<EOL><INDENT>log.info('<STR_LIT>')<EOL>adapter.devinfo = None<EOL><DEDENT><DEDENT>if adapter.devinfo is None:<EOL><INDENT>devinfoParams = dict(<EOL>devID             = self.options.devid or self.defaultDevID,<EOL>devType           = pysyncml.DEVTYPE_SERVER if self.options.server elsepysyncml.DEVTYPE_WORKSTATION,<EOL>manufacturerName  = '<STR_LIT>',<EOL>modelName         = self.appLabel,<EOL>softwareVersion   = pysyncml.version,<EOL>hierarchicalSync  = self.agent.hierarchicalSync if self.agent is not None else False,<EOL>)<EOL>if self.devinfoParams is not None:<EOL><INDENT>devinfoParams.update(self.devinfoParams)<EOL><DEDENT>adapter.devinfo = context.DeviceInfo(**devinfoParams)<EOL><DEDENT>self._callHooks('<STR_LIT>', context, adapter)<EOL>if not self.options.server:<EOL><INDENT>if adapter.peer is None:<EOL><INDENT>if self.options.remote is None:<EOL><INDENT>self.options.remote = input('<STR_LIT>')<EOL>if self.options.username is None:<EOL><INDENT>self.options.username = input('<STR_LIT>')<EOL>if len(self.options.username) <= <NUM_LIT:0>:<EOL><INDENT>self.options.username = None<EOL><DEDENT><DEDENT><DEDENT>log.info('<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>if self.options.remote is not None:<EOL><INDENT>if self.options.remote != adapter.peer.urlor self.options.username != adapter.peer.usernameor self.options.password != adapter.peer.password:<EOL><INDENT>log.info('<STR_LIT>')<EOL>adapter.peer = None<EOL><DEDENT><DEDENT><DEDENT>if adapter.peer is None:<EOL><INDENT>auth = None<EOL>if self.options.username is not None:<EOL><INDENT>auth = pysyncml.NAMESPACE_AUTH_BASIC<EOL>if self.options.password is None:<EOL><INDENT>self.options.password = getpass.getpass('<STR_LIT>')<EOL><DEDENT><DEDENT>adapter.peer = context.RemoteAdapter(<EOL>url      = self.options.remote,<EOL>auth     = auth,<EOL>username = self.options.username,<EOL>password = self.options.password,<EOL>)<EOL><DEDENT>self._callHooks('<STR_LIT>', context, adapter, adapter.peer)<EOL><DEDENT>uri = self.storeParams.get('<STR_LIT>', self.appLabel)<EOL>if uri in adapter.stores:<EOL><INDENT>store = adapter.stores[uri]<EOL>store.agent = self.agent<EOL><DEDENT>else:<EOL><INDENT>storeParams = dict(<EOL>uri         = uri,<EOL>displayName = self.options.name or self.appDisplay,<EOL>agent       = self.agent,<EOL>maxObjSize  = None)<EOL>if self.storeParams is not None:<EOL><INDENT>storeParams.update(self.storeParams)<EOL><DEDENT>store = adapter.addStore(context.Store(**storeParams))<EOL><DEDENT>self._callHooks('<STR_LIT>', context, adapter, store)<EOL>if self.options.local:<EOL><INDENT>def locprint(msg):<EOL><INDENT>print(msg)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>locprint = log.info<EOL><DEDENT>def showChanges(changes, prefix):<EOL><INDENT>for c in changes:<EOL><INDENT>if c.state != pysyncml.ITEM_DELETED:<EOL><INDENT>item = self.agent.getItem(c.itemID)<EOL><DEDENT>else:<EOL><INDENT>item = '<STR_LIT>' % (c.itemID,)<EOL><DEDENT>locprint('<STR_LIT>' % (prefix, item, pysyncml.state2string(c.state)))<EOL><DEDENT><DEDENT>if self.options.server:<EOL><INDENT>peers = adapter.getKnownPeers()<EOL>if len(peers) > <NUM_LIT:0>:<EOL><INDENT>locprint('<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>locprint('<STR_LIT>')<EOL><DEDENT>for peer in peers:<EOL><INDENT>for puri, pstore in list(peer.stores.items()):<EOL><INDENT>if pstore.binding is None or pstore.binding.uri != store.uri:<EOL><INDENT>continue<EOL><DEDENT>changes = list(pstore.getRegisteredChanges())<EOL>if len(changes) <= <NUM_LIT:0>:<EOL><INDENT>locprint('<STR_LIT>' % (peer.devID, puri))<EOL><DEDENT>else:<EOL><INDENT>locprint('<STR_LIT>' % (peer.devID, puri))<EOL><DEDENT>showChanges(changes, '<STR_LIT:U+0020>')<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>if store.peer is None:<EOL><INDENT>locprint('<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>changes = list(store.peer.getRegisteredChanges())<EOL>if len(changes) <= <NUM_LIT:0>:<EOL><INDENT>locprint('<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>locprint('<STR_LIT>')<EOL><DEDENT>showChanges(changes, '<STR_LIT>')<EOL><DEDENT><DEDENT>self._callHooks('<STR_LIT>', context, adapter)<EOL>return (context, adapter)<EOL>
Creates a tuple of ( Context, Adapter ) based on the options
specified by `self.options`. The Context is the pysyncml.Context created for
the storage location specified in `self.options`, and the Adapter is a newly
created Adapter if a previously created one was not found.