Changeset View
Changeset View
Standalone View
Standalone View
swh/objstorage/cli.py
# Copyright (C) 2015-2019 The Software Heritage developers | # Copyright (C) 2015-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 os | import os | ||||
import logging | import logging | ||||
import time | import time | ||||
import click | import click | ||||
import aiohttp.web | import aiohttp.web | ||||
from swh.core import config | |||||
from swh.core.cli import CONTEXT_SETTINGS | from swh.core.cli import CONTEXT_SETTINGS | ||||
from swh.objstorage.api.server import load_and_check_config, make_app | |||||
from swh.objstorage.factory import get_objstorage | from swh.objstorage.factory import get_objstorage | ||||
from swh.objstorage.api.server import validate_config, make_app | |||||
@click.group(name="objstorage", context_settings=CONTEXT_SETTINGS) | @click.group(name="objstorage", 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 | ||||
def cli(ctx, config_file): | def cli(ctx, config_file): | ||||
"""Software Heritage Objstorage tools. | """Software Heritage Objstorage tools. | ||||
""" | """ | ||||
if not config_file: | |||||
config_file = os.environ.get("SWH_CONFIG_FILENAME") | |||||
if config_file: | |||||
if not os.path.exists(config_file): | |||||
raise ValueError("%s does not exist" % config_file) | |||||
conf = config.read(config_file) | |||||
else: | |||||
conf = {} | |||||
ctx.ensure_object(dict) | ctx.ensure_object(dict) | ||||
cfg = load_and_check_config(config_file) | |||||
ctx.obj["config"] = cfg | ctx.obj["config"] = conf | ||||
@cli.command("rpc-serve") | @cli.command("rpc-serve") | ||||
@click.option( | @click.option( | ||||
"--host", | "--host", | ||||
default="0.0.0.0", | default="0.0.0.0", | ||||
metavar="IP", | metavar="IP", | ||||
show_default=True, | show_default=True, | ||||
Show All 9 Lines | @click.option( | ||||
help="Binding port of the server", | help="Binding port of the server", | ||||
) | ) | ||||
@click.pass_context | @click.pass_context | ||||
def serve(ctx, host, port): | def serve(ctx, host, port): | ||||
"""Run a standalone objstorage server. | """Run a standalone objstorage server. | ||||
This is not meant to be run on production systems. | This is not meant to be run on production systems. | ||||
""" | """ | ||||
app = make_app(ctx.obj["config"]) | app = make_app(validate_config(ctx.obj["config"])) | ||||
if ctx.obj["log_level"] == "DEBUG": | if ctx.obj["log_level"] == "DEBUG": | ||||
app.update(debug=True) | app.update(debug=True) | ||||
aiohttp.web.run_app(app, host=host, port=int(port)) | aiohttp.web.run_app(app, host=host, port=int(port)) | ||||
@cli.command("import") | @cli.command("import") | ||||
@click.argument("directory", required=True, nargs=-1) | @click.argument("directory", required=True, nargs=-1) | ||||
@click.pass_context | @click.pass_context | ||||
Show All 40 Lines |