Exemple #1
0
def open(filename, backend_name=None, backend_args=None):
    """Open an existing database and return it.

    - `filename`: Name of the file containing the database.
    - `backend_name`: (optional) Name of the backend to use if
      auto-detection is not desired.
    - `backend_args`: (optional) Arguments to pass to the backend.
    """
    backend = new_backend(filename, backend_name, backend_args)
    # Make sure the database already exists.
    root = backend.get_root()
    if 'SCHEVO' not in root:
        backend.close()
        raise DatabaseDoesNotExist(filename)
    # Determine the version of the database.
    schevo = root['SCHEVO']
    format = schevo['format']
    # Determine database class based on format number.
    Database = format_dbclass[format]
    # Create the Database instance.
    db = Database(backend)
    db._sync()
    # Install icon support and finalize opening of database.
    icon.install(db)
    return db
Exemple #2
0
def create(filename, backend_name, backend_args={},
           schema_source=None, schema_version=None, initialize=True,
           format=None, label=u'Schevo Database'):
    """Create a new database and return it.

    - `filename`: Filename of the new database.
    - `backend_name`: Name of the backend to use when creating the
      database.
    - `backend_args`: (optional) Arguments to pass to the backend.
    - `schema_source`: (optional) Schema source code to synchronize
      the new database with. If `None` is given, the database will
      exist but will contain no extents.
    - `schema_version`: (optional) Version of the schema being used to
      create the database.  If `None` is given, `1` is assumed.
    - `initialize`: `True` (default) if the new database should be
      populated with initial values defined in the schema.
    - `format`: (optional) Internal structure format to use.  If
      `None` is given, the latest format will be used.
    - `label`: (optional) The label to give the new database.
    """
    backend = new_backend(filename, backend_name, backend_args)
    # Make sure the database doesn't already exist.
    root = backend.get_root()
    if 'SCHEVO' in root:
        backend.close()
        raise DatabaseAlreadyExists(filename)
    # Continue creating the new database.
    Database = format_dbclass[format]
    db = Database(backend)
    db._sync(
        schema_source=schema_source,
        schema_version=schema_version,
        initialize=initialize,
        )
    # Apply label.
    relabel(db, label)
    # Install icon support.
    icon.install(db)
    return db
Exemple #3
0
def open(url, backend_args=None):
    """Open an existing database and return it.

    - `url`: URL of the database to open.
    - `backend_args`: (optional) Additional arguments to pass to the backend.
    """
    backend = new_backend(url, backend_args)
    # Make sure the database already exists.
    root = backend.get_root()
    if 'SCHEVO' not in root:
        backend.close()
        raise DatabaseDoesNotExist(url)
    # Determine the version of the database.
    schevo = root['SCHEVO']
    format = schevo['format']
    # Determine database class based on format number.
    Database = format_dbclass[format]
    # Create the Database instance.
    db = Database(backend)
    db._sync()
    # Install icon support and finalize opening of database.
    icon.install(db)
    return db