コード例 #1
0
ファイル: app.py プロジェクト: AbelMon/librarian
def prestart(config, logfile=None, debug=False):
    ensure_dir(dirname(config['logging.output']))
    log_config({
        'version': 1,
        'root': {
            'handlers': ['file'],
            'level': logging.DEBUG,
        },
        'handlers': {
            'file': {
                'class': 'logging.handlers.RotatingFileHandler',
                'formatter': 'default',
                'filename': logfile or config['logging.output'],
                'maxBytes': config['logging.size'],
                'backupCount': config['logging.backups'],
            },
        },
        'formatters': {
            'default': {
                'format': config['logging.format'],
                'datefmt': config['logging.date_format'],
            },
        },
    })
    debug = debug or config['librarian.debug']
    logging.info('Configuring Librarian environment')

    database_configs = database_utils.get_database_configs(config)
    for db_name, db_path in database_configs.items():
        logging.debug('Using database {}'.format(db_path))

    # Make sure all necessary directories are present
    for db_path in database_configs.values():
        ensure_dir(dirname(db_path))

    ensure_dir(config['content.spooldir'])
    ensure_dir(config['content.appdir'])
    ensure_dir(config['content.unpackdir'])
    ensure_dir(config['content.contentdir'])
    ensure_dir(config['content.covers'])

    # Run database migrations
    databases = squery.get_databases(database_configs, debug=debug)
    for db_name, db in databases.items():
        migrations.migrate(db,
                           in_pkg('migrations', db_name),
                           'librarian.migrations.{0}'.format(db_name),
                           config)

    logging.debug("Finished running migrations")
    return databases
コード例 #2
0
def test_get_databases_does_not_connect_if_connection_is_passed(Database):
    """ When connection object is passed, connection is not made """
    mod.get_databases({})
    assert not Database.connect.called
コード例 #3
0
def test_get_databases_connects(db_connect):
    """ When database name is passed as string, connection is made """
    mod.get_databases({"foo": "foo.db"})
    db_connect.assert_called_once_with("foo.db")