Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/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 logging | |||||
import click | import click | ||||
from swh.core.cli import CONTEXT_SETTINGS | |||||
from swh.storage.api.server import load_and_check_config, app | from swh.storage.api.server import load_and_check_config, app | ||||
@click.command() | @click.group(name='storage', context_settings=CONTEXT_SETTINGS) | ||||
@click.pass_context | |||||
def storage(ctx): | |||||
'''Software Heritage Storage tools.''' | |||||
pass | |||||
@storage.command(name='rpc-serve') | |||||
@click.argument('config-path', required=1) | @click.argument('config-path', required=1) | ||||
@click.option('--host', default='0.0.0.0', help="Host to run the server") | @click.option('--host', default='0.0.0.0', help="Host to run the server") | ||||
@click.option('--port', default=5002, type=click.INT, | @click.option('--port', default=5002, type=click.INT, | ||||
help="Binding port of the server") | help="Binding port of the server") | ||||
@click.option('--debug/--nodebug', default=True, | @click.option('--debug/--no-debug', default=True, | ||||
help="Indicates if the server should run in debug mode") | help="Indicates if the server should run in debug mode") | ||||
def main(config_path, host, port, debug): | def serve(config_path, host, port, debug): | ||||
'''Software Heritage Storage RPC (standalone) server. | |||||
Do NOT use this in a production environment. | |||||
''' | |||||
api_cfg = load_and_check_config(config_path, type='any') | api_cfg = load_and_check_config(config_path, type='any') | ||||
app.config.update(api_cfg) | app.config.update(api_cfg) | ||||
app.run(host, port=int(port), debug=bool(debug)) | app.run(host, port=int(port), debug=bool(debug)) | ||||
def main(): | |||||
logging.basicConfig() | |||||
return serve(auto_envvar_prefix='SWH_STORAGE') | |||||
if __name__ == '__main__': | if __name__ == '__main__': | ||||
main() | main() |