Esempio n. 1
0
 def main(self, arg0, args):
     print
     print
     from schevo.backend import backends
     for backend_name, backend_class in sorted(backends.iteritems()):
         print backend_name, '-', backend_class.description
         print '=' * (len(backend_name) + len(backend_class.description) + 3)
         print 'Available options for --backend-args:'
         print dedent(backend_class.backend_args_help).strip()
         print
Esempio n. 2
0
def new_backend(url, backend_args=None):
    """Return a new database backend instance for a file.

    - `url`: URL of the database to open with the backend.  If given
      as just a filename, and the file already exists, then the
      backend is auto-detected if possible, or an exception is raised.
      If the file does not already exist and `None` is given, an
      exception is raised.
    - `backend_args`: (optional) Additional arguments to pass to the backend.
    """
    if backend_args is None:
        backend_args = {}
    else:
        backend_args = backend_args.copy()
    if '://' not in url:
        # Assume filename, try to find backend.
        from schevo.backend import backends
        usable = False
        for backend_name, backend_class in backends.iteritems():
            try:
                usable = backend_class.usable_by_backend(url)
            except IOError:
                usable = False
            else:
                if usable:
                    usable, additional_args = usable
                    backend_args.update(additional_args)
                    # Convert to proper URL form.
                    url = '%s:///%s' % (backend_name, url)
                    break
        if not usable:
            raise IOError('No suitable backends found for %r' % url)
    # Convert to URL object.
    url = make_url(url)
    # Convert backend args to a dictionary.
    backend_args.update(url.translate_connect_args())
    return url.backend_class()(**backend_args)