def _cmd_help_backends(self, options, *args): if len(args) > 1: exit(_('Please specifiy only one backend!')) from tel import backendmanager manager = backendmanager.manager() if not args: items = [(unicode(backend.__name__), backend.__short_description__) for backend in manager.itervalues()] headline = [_('Backend name'), _('Description')] print_simple_table(headline, items) else: try: # print complete description for a single backend backend = manager[args[0]] except KeyError, e: exit(e.message) fields = backend.__phonebook_class__.supported_fields() wrap = textwrap.TextWrapper(79) info = { 'name': backend.__name__, 'shortdesc': wrap.fill(backend.__short_description__), 'longdesc': wrap.fill(backend.__long_description__), 'fields': wrap.fill(', '.join(fields)) } print >> stdout, _(""" %(name)s - %(shortdesc)s ------------ Supported fields: %(fields)s ------------ %(longdesc)s""") % info
def _cmd_help_backends(self, options, *args): if len(args) > 1: exit(_('Please specifiy only one backend!')) from tel import backendmanager manager = backendmanager.manager() if not args: items = [(unicode(backend.__name__), backend.__short_description__) for backend in manager.itervalues()] headline = [_('Backend name'), _('Description')] print_simple_table(headline, items) else: try: # print complete description for a single backend backend = manager[args[0]] except KeyError, e: exit(e.message) fields = backend.__phonebook_class__.supported_fields() wrap = textwrap.TextWrapper(79) info = {'name': backend.__name__, 'shortdesc': wrap.fill(backend.__short_description__), 'longdesc': wrap.fill(backend.__long_description__), 'fields': wrap.fill(', '.join(fields)) } print >> stdout, _(""" %(name)s - %(shortdesc)s ------------ Supported fields: %(fields)s ------------ %(longdesc)s""") % info
def absolutize(self): """Set the scheme of this URI by guessing it from location. Only changes scheme, if it is None or empty.""" if not self.isabsolute(): manager = backendmanager.manager() backend = manager.backend_for_file(self.location) if backend: self.scheme = backend.__name__
def phonebook_open(uri): """Opens a phonebook denoted by `uri`. `uri` may be a plain string, or an instance of URI class. Note, that the returned phonebook instance doesn't contain entries. These must be loaded explicitly using the load() method""" if isinstance(uri, basestring): uri = URI(uri) # guess backend, if uri was not absolute (= no scheme was given) uri.absolutize() if uri.scheme is None: raise IOError(_(u'Couldn\'t find a backend for %s.') % uri) try: backend = backendmanager.manager()[uri.scheme] except KeyError: raise IOError(_(u'Unknown backend %s.') % uri.scheme) return backend.__phonebook_class__(uri)
def phonebook_open(uri): """Opens a phonebook denoted by `uri`. `uri` may be a plain string, or an instance of URI class. Note, that the returned phonebook instance doesn't contain entries. These must be loaded explicitly using the load() method""" if isinstance(uri, basestring): uri = URI(uri) # guess backend, if uri was not absolute (= no scheme was given) uri.absolutize() if uri.scheme is None: raise IOError(_(u"Couldn't find a backend for %s.") % uri) try: backend = backendmanager.manager()[uri.scheme] except KeyError: raise IOError(_(u"Unknown backend %s.") % uri.scheme) return backend.__phonebook_class__(uri)