Changeset View
Changeset View
Standalone View
Standalone View
swh/core/cli/__init__.py
# Copyright (C) 2019 The Software Heritage developers | # Copyright (C) 2019 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
import logging | import logging | ||||
import logging.config | import logging.config | ||||
import signal | import signal | ||||
import click | import click | ||||
import pkg_resources | import pkg_resources | ||||
import sentry_sdk | |||||
import yaml | import yaml | ||||
from ..sentry import init_sentry | |||||
LOG_LEVEL_NAMES = ['NOTSET', 'DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'] | LOG_LEVEL_NAMES = ['NOTSET', 'DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'] | ||||
CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help']) | CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help']) | ||||
logger = logging.getLogger(__name__) | logger = logging.getLogger(__name__) | ||||
class AliasedGroup(click.Group): | class AliasedGroup(click.Group): | ||||
▲ Show 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | @click.option('--sentry-debug/--no-sentry-debug', | ||||
help="Enable debugging of sentry") | help="Enable debugging of sentry") | ||||
@click.pass_context | @click.pass_context | ||||
def swh(ctx, log_level, log_config, sentry_dsn, sentry_debug): | def swh(ctx, log_level, log_config, sentry_dsn, sentry_debug): | ||||
"""Command line interface for Software Heritage. | """Command line interface for Software Heritage. | ||||
""" | """ | ||||
signal.signal(signal.SIGTERM, clean_exit_on_signal) | signal.signal(signal.SIGTERM, clean_exit_on_signal) | ||||
signal.signal(signal.SIGINT, clean_exit_on_signal) | signal.signal(signal.SIGINT, clean_exit_on_signal) | ||||
if sentry_dsn: | init_sentry(sentry_dsn, debug=sentry_debug) | ||||
sentry_sdk.init(dsn=sentry_dsn, debug=sentry_debug) | |||||
if log_level is None and log_config is None: | if log_level is None and log_config is None: | ||||
log_level = 'INFO' | log_level = 'INFO' | ||||
if log_config: | if log_config: | ||||
logging.config.dictConfig(yaml.safe_load(log_config.read())) | logging.config.dictConfig(yaml.safe_load(log_config.read())) | ||||
if log_level: | if log_level: | ||||
Show All 25 Lines |