Ejemplo n.º 1
0
def main():
    install_sigint_handler()
    prog = os.path.basename(sys.argv[0])
    args = get_opts(prog)
    config = build_config(env_var=CONFIG_ENV_VAR)

    if args.database_url:
        config['DATABASE_URL'] = avalon.cli.input_to_text(args.database_url)

    if args.quiet:
        config['LOG_LEVEL'] = logging.ERROR

    logger = avalon.log.get_error_log()
    avalon.app.factory.configure_logger(logger, config)

    try:
        database = avalon.app.factory.new_db_engine(config)
        database.connect()
    except avalon.exc.DatabaseError as e:
        logger.error("%s: %s", prog, e)
        return 1

    dao = avalon.app.factory.new_dao(database)
    id_cache = avalon.app.factory.new_id_cache(dao)
    scanner = AvalonCollectionScanner(database, id_cache)
    collection = avalon.cli.input_to_text(args.collection)

    try:
        scanner.scan_path(collection)
    except avalon.exc.AvalonError as e:
        logger.error(
            "%s: Scanning of music collection at %s failed: %s",
            prog, args.collection, e)
        return 1

    return 0
Ejemplo n.º 2
0
def main():
    install_sigint_handler()
    prog = os.path.basename(sys.argv[0])
    # We're not interested in the return value here, we're just
    # using argparse to handle --help and --version options, we
    # don't actually need any arguments to run this script.
    _ = get_opts(prog)

    config = build_config(env_var=CONFIG_ENV_VAR)
    logger = avalon.log.get_error_log()
    avalon.app.factory.configure_logger(logger, config)

    loader = pkgutil.find_loader("avalon.settings")
    if loader is None:
        logger.error("%s: could not find a loader for default settings module", prog)
        return 1

    source = loader.get_source()
    if source is None:
        logger.error("%s: could not load source for default settings module", prog)
        return 1

    print(source)
    return 0