Changeset View
Changeset View
Standalone View
Standalone View
swh/search/cli.py
# Copyright (C) 2019-2020 The Software Heritage developers | # Copyright (C) 2019-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 | ||||
# 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 | ||||
# control | # control | ||||
import logging | |||||
import click | import click | ||||
from swh.core.cli import CONTEXT_SETTINGS | from swh.core.cli import CONTEXT_SETTINGS | ||||
from swh.core.cli import swh as swh_cli_group | from swh.core.cli import swh as swh_cli_group | ||||
@swh_cli_group.group(name="search", context_settings=CONTEXT_SETTINGS) | @swh_cli_group.group(name="search", context_settings=CONTEXT_SETTINGS) | ||||
@click.option( | @click.option( | ||||
Show All 19 Lines | def initialize(ctx): | ||||
"""Creates Elasticsearch indices.""" | """Creates Elasticsearch indices.""" | ||||
from . import get_search | from . import get_search | ||||
search = get_search(**ctx.obj["config"]["search"]) | search = get_search(**ctx.obj["config"]["search"]) | ||||
search.initialize() | search.initialize() | ||||
print("Done.") | print("Done.") | ||||
@search_cli_group.command(name="rpc-serve") | |||||
@click.option( | |||||
"--host", | |||||
default="0.0.0.0", | |||||
metavar="IP", | |||||
show_default=True, | |||||
help="Host ip address to bind the server on", | |||||
) | |||||
@click.option( | |||||
"--port", | |||||
default=5010, | |||||
type=click.INT, | |||||
metavar="PORT", | |||||
show_default=True, | |||||
help="Binding port of the server", | |||||
) | |||||
@click.option( | |||||
"--debug/--no-debug", | |||||
default=True, | |||||
help="Indicates if the server should run in debug mode", | |||||
) | |||||
@click.pass_context | |||||
def serve(ctx, host, port, debug): | |||||
"""Software Heritage Storage RPC server. | |||||
Do NOT use this in a production environment. | |||||
""" | |||||
from swh.search.api.server import app | |||||
if "log_level" in ctx.obj: | |||||
logging.getLogger("werkzeug").setLevel(ctx.obj["log_level"]) | |||||
app.config.update(ctx.obj["config"]) | |||||
app.run(host, port=int(port), debug=bool(debug)) | |||||
@search_cli_group.group("journal-client") | @search_cli_group.group("journal-client") | ||||
@click.pass_context | @click.pass_context | ||||
def journal_client(ctx): | def journal_client(ctx): | ||||
"""""" | """""" | ||||
pass | pass | ||||
@journal_client.command("objects") | @journal_client.command("objects") | ||||
▲ Show 20 Lines • Show All 63 Lines • Show Last 20 Lines |