diff --git a/setup.py b/setup.py index b53d85a..43b1da2 100644 --- a/setup.py +++ b/setup.py @@ -1,71 +1,71 @@ #!/usr/bin/env python3 # Copyright (C) 2015-2018 The Software Heritage developers # See the AUTHORS file at the top-level directory of this distribution # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information from setuptools import setup, find_packages from os import path from io import open here = path.abspath(path.dirname(__file__)) # Get the long description from the README file with open(path.join(here, 'README.md'), encoding='utf-8') as f: long_description = f.read() def parse_requirements(name=None): if name: reqf = 'requirements-%s.txt' % name else: reqf = 'requirements.txt' requirements = [] if not path.exists(reqf): return requirements with open(reqf) as f: for line in f.readlines(): line = line.strip() if not line or line.startswith('#'): continue requirements.append(line) return requirements setup( name='swh.vault', description='Software Heritage vault', long_description=long_description, long_description_content_type='text/markdown', author='Software Heritage developers', author_email='swh-devel@inria.fr', url='https://forge.softwareheritage.org/diffusion/DVAU/', packages=find_packages(), install_requires=parse_requirements() + parse_requirements('swh'), setup_requires=['vcversioner'], extras_require={'testing': parse_requirements('test')}, vcversioner={}, include_package_data=True, zip_safe=False, entry_points=''' [console_scripts] swh-vault=swh.vault.cli:main [swh.cli.subcommands] - vault=swh.vault.cli:cli + vault=swh.vault.cli:vault ''', classifiers=[ "Programming Language :: Python :: 3", "Intended Audience :: Developers", "License :: OSI Approved :: GNU General Public License v3 (GPLv3)", "Operating System :: OS Independent", "Development Status :: 5 - Production/Stable", ], project_urls={ 'Bug Reports': 'https://forge.softwareheritage.org/maniphest', 'Funding': 'https://www.softwareheritage.org/donate', 'Source': 'https://forge.softwareheritage.org/source/swh-vault', }, ) diff --git a/swh/vault/cli.py b/swh/vault/cli.py index 194225b..264f655 100644 --- a/swh/vault/cli.py +++ b/swh/vault/cli.py @@ -1,73 +1,74 @@ import os import logging import click from swh.core.config import SWH_CONFIG_DIRECTORIES, SWH_CONFIG_EXTENSIONS from swh.core.cli import CONTEXT_SETTINGS, AliasedGroup from swh.vault.api.server import make_app_from_configfile, DEFAULT_CONFIG_PATH CFG_HELP = """Software Heritage Vault RPC server. If the CONFIGFILE option is not set, the default config file search will be used; first the SWH_CONFIG_FILENAME environment variable will be checked, then the config file will be searched in: %s""" % ('\n\n'.join('- %s(%s)' % ( os.path.join(d, DEFAULT_CONFIG_PATH), '|'.join(SWH_CONFIG_EXTENSIONS)) for d in SWH_CONFIG_DIRECTORIES)) + @click.group(name='vault', context_settings=CONTEXT_SETTINGS, cls=AliasedGroup) @click.pass_context def vault(ctx): '''Software Heritage Vault tools.''' pass @vault.command(name='rpc-serve', help=CFG_HELP) @click.option('--config-file', '-C', default=None, metavar='CONFIGFILE', type=click.Path(exists=True, dir_okay=False,), help="Configuration file.") @click.option('--no-stdout', is_flag=True, default=False, help="Do NOT output logs on the console") @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=5005, type=click.INT, metavar='PORT', 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, config_file, no_stdout, host, port, debug): import aiohttp from swh.scheduler.celery_backend.config import setup_log_handler ctx.ensure_object(dict) setup_log_handler( loglevel=ctx.obj.get('log_level', logging.INFO), colorize=False, format='[%(levelname)s] %(name)s -- %(message)s', log_console=not no_stdout) try: app = make_app_from_configfile(config_file, debug=debug) except EnvironmentError as e: click.echo(e.msg, err=True) ctx.exit(1) aiohttp.web.run_app(app, host=host, port=int(port)) vault.add_alias(serve, 'serve') def main(): logging.basicConfig() return serve(auto_envvar_prefix='SWH_VAULT') if __name__ == '__main__': main()