Changeset View
Changeset View
Standalone View
Standalone View
swh/vault/cli.py
import os | # Copyright (C) 2015-2020 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | |||||
# License: GNU General Public License version 3, or any later version | |||||
# See top-level LICENSE file for more information | |||||
# WARNING: do not import unnecessary things here to keep cli startup time under | |||||
# control | |||||
import logging | import logging | ||||
import click | import click | ||||
from swh.core.config import SWH_CONFIG_DIRECTORIES, SWH_CONFIG_EXTENSIONS | |||||
from swh.core.cli import CONTEXT_SETTINGS, AliasedGroup | from swh.core.cli import CONTEXT_SETTINGS, AliasedGroup | ||||
from swh.vault.api.server import make_app_from_configfile, DEFAULT_CONFIG_PATH | |||||
CFG_HELP = """Software Heritage Vault RPC server. | |||||
If the CONFIGFILE option is not set, the default config file search will | CFG_HELP = """Software Heritage Vault RPC server.""" | ||||
be used; first the SWH_CONFIG_FILENAME environment variable will be | |||||
checked, then the config file will be searched in: | |||||
%s""" % ( | |||||
"\n\n".join( | |||||
"- %s(%s)" | |||||
% (os.path.join(d, DEFAULT_CONFIG_PATH), "|".join(SWH_CONFIG_EXTENSIONS)) | |||||
for d in SWH_CONFIG_DIRECTORIES | |||||
) | |||||
) | |||||
@click.group(name="vault", context_settings=CONTEXT_SETTINGS, cls=AliasedGroup) | @click.group(name="vault", context_settings=CONTEXT_SETTINGS, cls=AliasedGroup) | ||||
@click.pass_context | @click.pass_context | ||||
def vault(ctx): | def vault(ctx): | ||||
"""Software Heritage Vault tools.""" | """Software Heritage Vault tools.""" | ||||
pass | pass | ||||
Show All 28 Lines | @click.option( | ||||
"--debug/--no-debug", | "--debug/--no-debug", | ||||
default=True, | default=True, | ||||
help="Indicates if the server should run in debug mode", | help="Indicates if the server should run in debug mode", | ||||
) | ) | ||||
@click.pass_context | @click.pass_context | ||||
def serve(ctx, config_file, no_stdout, host, port, debug): | def serve(ctx, config_file, no_stdout, host, port, debug): | ||||
import aiohttp | import aiohttp | ||||
from swh.scheduler.celery_backend.config import setup_log_handler | from swh.scheduler.celery_backend.config import setup_log_handler | ||||
from swh.vault.api.server import make_app_from_configfile | |||||
ctx.ensure_object(dict) | ctx.ensure_object(dict) | ||||
setup_log_handler( | setup_log_handler( | ||||
loglevel=ctx.obj.get("log_level", logging.INFO), | loglevel=ctx.obj.get("log_level", logging.INFO), | ||||
colorize=False, | colorize=False, | ||||
format="[%(levelname)s] %(name)s -- %(message)s", | format="[%(levelname)s] %(name)s -- %(message)s", | ||||
log_console=not no_stdout, | log_console=not no_stdout, | ||||
) | ) | ||||
Show All 17 Lines |