Changeset View
Changeset View
Standalone View
Standalone View
swh/indexer/cli.py
# Copyright (C) 2019 The Software Heritage developers | # Copyright (C) 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 functools | import functools | ||||
import json | |||||
import time | import time | ||||
import click | import click | ||||
from swh.core import config | from swh.core import config | ||||
from swh.core.cli import CONTEXT_SETTINGS, AliasedGroup | from swh.core.cli import CONTEXT_SETTINGS, AliasedGroup | ||||
from swh.journal.cli import get_journal_client | from swh.journal.cli import get_journal_client | ||||
from swh.scheduler import get_scheduler | from swh.scheduler import get_scheduler | ||||
▲ Show 20 Lines • Show All 69 Lines • ▼ Show 20 Lines | for (property_name, supported_mappings) in sorted(properties.items()): | ||||
if supported_mappings: | if supported_mappings: | ||||
if concise: | if concise: | ||||
click.echo(property_name) | click.echo(property_name) | ||||
else: | else: | ||||
click.echo('{}:'.format(property_name)) | click.echo('{}:'.format(property_name)) | ||||
click.echo('\t' + ', '.join(sorted(supported_mappings))) | click.echo('\t' + ', '.join(sorted(supported_mappings))) | ||||
@mapping.command('translate') | |||||
@click.argument('mapping-name') | |||||
@click.argument('file', type=click.File('rb')) | |||||
def mapping_translate(mapping_name, file): | |||||
"""Prints the list of known mappings.""" | |||||
ardumont: looks like it's not meant to stay, is it (you use click.echo further down the line). | |||||
mapping_cls = [cls for cls in metadata_dictionary.MAPPINGS.values() | |||||
if cls.name == mapping_name] | |||||
if not mapping_cls: | |||||
raise click.ClickException('Unknown mapping {}'.format(mapping_name)) | |||||
assert len(mapping_cls) == 1 | |||||
mapping_cls = mapping_cls[0] | |||||
mapping = mapping_cls() | |||||
codemeta_doc = mapping.translate(file.read()) | |||||
click.echo(json.dumps(codemeta_doc, indent=4)) | |||||
@cli.group('schedule') | @cli.group('schedule') | ||||
@click.option('--scheduler-url', '-s', default=None, | @click.option('--scheduler-url', '-s', default=None, | ||||
help="URL of the scheduler API") | help="URL of the scheduler API") | ||||
@click.option('--indexer-storage-url', '-i', default=None, | @click.option('--indexer-storage-url', '-i', default=None, | ||||
help="URL of the indexer storage API") | help="URL of the indexer storage API") | ||||
@click.option('--storage-url', '-g', default=None, | @click.option('--storage-url', '-g', default=None, | ||||
help="URL of the (graph) storage API") | help="URL of the (graph) storage API") | ||||
@click.option('--dry-run/--no-dry-run', is_flag=True, | @click.option('--dry-run/--no-dry-run', is_flag=True, | ||||
▲ Show 20 Lines • Show All 112 Lines • ▼ Show 20 Lines | try: | ||||
while not max_messages or nb_messages < max_messages: | while not max_messages or nb_messages < max_messages: | ||||
nb_messages += client.process(worker_fn) | nb_messages += client.process(worker_fn) | ||||
if time.monotonic() - last_log_time >= 60: | if time.monotonic() - last_log_time >= 60: | ||||
print('Processed %d messages.' % nb_messages) | print('Processed %d messages.' % nb_messages) | ||||
last_log_time = time.monotonic() | last_log_time = time.monotonic() | ||||
except KeyboardInterrupt: | except KeyboardInterrupt: | ||||
ctx.exit(0) | ctx.exit(0) | ||||
else: | else: | ||||
print('Done.') | print('Done.') | ||||
Not Done Inline Actionswhy does it go away? The description mentions adding something, not dropping something. ardumont: why does it go away?
The description mentions adding something, not dropping something. | |||||
@cli.command('rpc-serve') | @cli.command('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=5007, type=click.INT, | @click.option('--port', default=5007, type=click.INT, | ||||
help="Binding port of the server") | help="Binding port of the server") | ||||
@click.option('--debug/--nodebug', default=True, | @click.option('--debug/--nodebug', default=True, | ||||
help="Indicates if the server should run in debug mode") | help="Indicates if the server should run in debug mode") | ||||
def rpc_server(config_path, host, port, debug): | def rpc_server(config_path, host, port, debug): | ||||
"""Starts a Software Heritage Indexer RPC HTTP server.""" | """Starts a Software Heritage Indexer RPC HTTP server.""" | ||||
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(): | def main(): | ||||
Not Done Inline ActionsWeren't those removed some time ago? ardumont: Weren't those removed some time ago? | |||||
return cli(auto_envvar_prefix='SWH_INDEXER') | return cli(auto_envvar_prefix='SWH_INDEXER') | ||||
if __name__ == '__main__': | if __name__ == '__main__': | ||||
main() | main() |
looks like it's not meant to stay, is it (you use click.echo further down the line).