Changeset View
Changeset View
Standalone View
Standalone View
swh/web/client/cli.py
# Copyright (C) 2020 The Software Heritage developers | # Copyright (C) 2020-2021 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 os | import os | ||||
from typing import Any, Dict, List | from typing import Any, Dict, List | ||||
# WARNING: do not import unnecessary things here to keep cli startup time under | # WARNING: do not import unnecessary things here to keep cli startup time under | ||||
Show All 36 Lines | def web(ctx: Context, config_file: str): | ||||
if not config_file: | if not config_file: | ||||
config_file = DEFAULT_CONFIG_PATH | config_file = DEFAULT_CONFIG_PATH | ||||
try: | try: | ||||
conf = config.read_raw_config(config.config_basepath(config_file)) | conf = config.read_raw_config(config.config_basepath(config_file)) | ||||
if not conf: | if not conf: | ||||
raise ValueError(f"Cannot parse configuration file: {config_file}") | raise ValueError(f"Cannot parse configuration file: {config_file}") | ||||
# TODO: Determine what the following conditional is for | |||||
if config_file == DEFAULT_CONFIG_PATH: | if config_file == DEFAULT_CONFIG_PATH: | ||||
try: | try: | ||||
conf = conf["swh"]["web"]["client"] | conf = conf["swh"]["web"]["client"] | ||||
except KeyError: | except KeyError: | ||||
pass | pass | ||||
# recursive merge not done by config.read | # recursive merge not done by config.read | ||||
conf = config.merge_configs(DEFAULT_CONFIG, conf) | conf = config.merge_configs(DEFAULT_CONFIG, conf) | ||||
▲ Show 20 Lines • Show All 58 Lines • ▼ Show 20 Lines | try: | ||||
print("\t".join(result.values())) | print("\t".join(result.values())) | ||||
except requests.HTTPError as err: | except requests.HTTPError as err: | ||||
logging.error("Could not retrieve search results: %s", err) | logging.error("Could not retrieve search results: %s", err) | ||||
except (BrokenPipeError, IOError): | except (BrokenPipeError, IOError): | ||||
# Get rid of the BrokenPipeError message | # Get rid of the BrokenPipeError message | ||||
sys.stderr.close() | sys.stderr.close() | ||||
anlambert: maybe call the command simply `save` ? | |||||
Done Inline Actionssure ardumont: sure | |||||
@web.group(name="save", context_settings=CONTEXT_SETTINGS) | |||||
@click.pass_context | |||||
def savecodenow(ctx: Context,): | |||||
Not Done Inline Actions
anlambert: ~~Save code now ~~Subcommand to ... | |||||
"""Subcommand to interact from the cli with the save code now feature | |||||
""" | |||||
pass | |||||
@savecodenow.command("submit-request") | |||||
@click.option("--delimiter", "-d", default=",") | |||||
@click.pass_context | |||||
Not Done Inline Actionscommand could be named submit-request instead. swh web save submit-request anlambert: command could be named `submit-request` instead.
`swh web save submit-request` | |||||
def submit_request(ctx, delimiter: str) -> None: | |||||
"""Submit new save code now request through cli pipe. The expected format of the request | |||||
if one csv row ``<visit_type>,<origin>``. | |||||
Example: | |||||
cat list-origins | swh web save submit-request | |||||
echo svn;https://svn-url\ngit;https://git-url | swh web save \ | |||||
submit-request --delimiter ';' | |||||
Prints: | |||||
The output of save code now requests as json output. | |||||
""" | |||||
import json | |||||
import logging | |||||
import sys | |||||
logging.basicConfig(level=logging.INFO, stream=sys.stderr) | |||||
client = ctx.obj["client"] | |||||
processed_origins = [] | |||||
for origin in sys.stdin: | |||||
Done Inline Actionsgive some feedback to the user to show submissions are happening... ardumont: give some feedback to the user to show submissions are happening... | |||||
visit_type, origin = origin.rstrip().split(delimiter) | |||||
try: | |||||
saved_origin = client.origin_save(visit_type, origin) | |||||
logging.info("Submitted origin (%s, %s)", visit_type, origin) | |||||
processed_origins.append(saved_origin) | |||||
except Exception as e: | |||||
logging.warning( | |||||
"Issue for origin (%s, %s)\n%s", origin, visit_type, e, | |||||
) | |||||
logging.debug("Origin saved: %s", len(processed_origins)) | |||||
print(json.dumps(processed_origins)) | |||||
@web.group(name="auth", context_settings=CONTEXT_SETTINGS) | @web.group(name="auth", context_settings=CONTEXT_SETTINGS) | ||||
@click.option( | @click.option( | ||||
"--oidc-server-url", | "--oidc-server-url", | ||||
"oidc_server_url", | "oidc_server_url", | ||||
default="https://auth.softwareheritage.org/auth/", | default="https://auth.softwareheritage.org/auth/", | ||||
help=( | help=( | ||||
"URL of OpenID Connect server (default to " | "URL of OpenID Connect server (default to " | ||||
'"https://auth.softwareheritage.org/auth/")' | '"https://auth.softwareheritage.org/auth/")' | ||||
▲ Show 20 Lines • Show All 94 Lines • Show Last 20 Lines |
maybe call the command simply save ?