Changeset View
Changeset View
Standalone View
Standalone View
swh/core/cli/db.py
#!/usr/bin/env python3 | #!/usr/bin/env python3 | ||||
# Copyright (C) 2018-2020 The Software Heritage developers | # Copyright (C) 2018-2020 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 | ||||
from os import path, environ | from os import path, environ | ||||
from typing import Tuple | from typing import Tuple | ||||
import warnings | import warnings | ||||
import click | import click | ||||
from swh.core.cli import CONTEXT_SETTINGS | from swh.core.cli import CONTEXT_SETTINGS, swh as swh_cli_group | ||||
warnings.filterwarnings("ignore") # noqa prevent psycopg from telling us sh*t | warnings.filterwarnings("ignore") # noqa prevent psycopg from telling us sh*t | ||||
logger = logging.getLogger(__name__) | logger = logging.getLogger(__name__) | ||||
@click.group(name="db", context_settings=CONTEXT_SETTINGS) | @swh_cli_group.group(name="db", context_settings=CONTEXT_SETTINGS) | ||||
@click.option( | @click.option( | ||||
"--config-file", | "--config-file", | ||||
"-C", | "-C", | ||||
default=None, | default=None, | ||||
type=click.Path(exists=True, dir_okay=False), | type=click.Path(exists=True, dir_okay=False), | ||||
help="Configuration file.", | help="Configuration file.", | ||||
) | ) | ||||
@click.pass_context | @click.pass_context | ||||
▲ Show 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | for modname, cfg in ctx.obj["config"].items(): | ||||
"DONE database for {} {} at version {}".format( | "DONE database for {} {} at version {}".format( | ||||
modname, "initialized" if initialized else "exists", dbversion | modname, "initialized" if initialized else "exists", dbversion | ||||
), | ), | ||||
fg="green", | fg="green", | ||||
bold=True, | bold=True, | ||||
) | ) | ||||
@click.command(context_settings=CONTEXT_SETTINGS) | @db.command(context_settings=CONTEXT_SETTINGS) | ||||
@click.argument("module", required=True) | @click.argument("module", required=True) | ||||
@click.option( | @click.option( | ||||
"--db-name", | "--db-name", | ||||
"-d", | "-d", | ||||
help="Database name.", | help="Database name.", | ||||
default="softwareheritage-dev", | default="softwareheritage-dev", | ||||
show_default=True, | show_default=True, | ||||
) | ) | ||||
▲ Show 20 Lines • Show All 103 Lines • Show Last 20 Lines |