Changeset - e4b9a1d1fea1
[Not reviewed]
default
0 1 2
Thomas De Schampheleire - 7 years ago 2018-11-18 20:02:17
thomas.de_schampheleire@nokia.com
cli: initial introduction of 'kallithea-cli' command

This commit adds a command 'kallithea-cli' that intends to replace the
existing set of 'gearbox' commands that relate to setting up kallithea.
Gearbox would still be used for 'gearbox serve', but other commands like
'make-config', 'setup-db', etc. would be converted to 'kallithea-cli'
commands.

The python package 'Click' is used to generate the CLI. Using decorators,
this package makes it very easy to generate a CLI out of simple methods.
See: http://click.pocoo.org/7/

Using Gearbox for custom commands is possible, but documentation on this
topic is limited. As the added value of Gearbox for that use case is not
clear, we can well switch to something else if it seems better/easier.
3 files changed with 73 insertions and 0 deletions:
0 comments (0 inline, 0 general)
kallithea/bin/kallithea_cli.py
Show inline comments
 
new file 100644
 
# -*- coding: utf-8 -*-
 
# This program is free software: you can redistribute it and/or modify
 
# it under the terms of the GNU General Public License as published by
 
# the Free Software Foundation, either version 3 of the License, or
 
# (at your option) any later version.
 
#
 
# This program is distributed in the hope that it will be useful,
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
# GNU General Public License for more details.
 
#
 
# You should have received a copy of the GNU General Public License
 
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 

	
 
# 'cli' is the main entry point for 'kallithea-cli', specified in setup.py as entry_points console_scripts
 
from kallithea.bin.kallithea_cli_base import cli
kallithea/bin/kallithea_cli_base.py
Show inline comments
 
new file 100644
 
# -*- coding: utf-8 -*-
 
# This program is free software: you can redistribute it and/or modify
 
# it under the terms of the GNU General Public License as published by
 
# the Free Software Foundation, either version 3 of the License, or
 
# (at your option) any later version.
 
#
 
# This program is distributed in the hope that it will be useful,
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
# GNU General Public License for more details.
 
#
 
# You should have received a copy of the GNU General Public License
 
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 

	
 
import click
 
import functools
 
import os
 

	
 
import kallithea
 
import logging.config
 
import paste.deploy
 

	
 

	
 
# This placeholder is the main entry point for the kallithea-cli command
 
@click.group()
 
def cli():
 
    """Various commands to manage a Kallithea instance."""
 

	
 
def register_command(config_file=False, config_file_initialize_app=False):
 
    """Register a kallithea-cli subcommand.
 

	
 
    If one of the config_file flags are true, a config file must be specified
 
    with -c and it is read and logging is configured. The configuration is
 
    available in the kallithea.CONFIG dict.
 

	
 
    If config_file_initialize_app is true, Kallithea, TurboGears global state
 
    (including tg.config), and database access will also be fully initialized.
 
    """
 
    cli_command = cli.command()
 
    if config_file or config_file_initialize_app:
 
        def annotator(annotated):
 
            @click.option('--config_file', '-c', help="Path to .ini file with app configuration.",
 
                type=click.Path(dir_okay=False, exists=True, readable=True), required=True)
 
            @functools.wraps(annotated) # reuse meta data from the wrapped function so click can see other options
 
            def runtime_wrapper(config_file, *args, **kwargs):
 
                path_to_ini_file = os.path.realpath(config_file)
 
                kallithea.CONFIG = paste.deploy.appconfig('config:' + path_to_ini_file)
 
                logging.config.fileConfig(path_to_ini_file)
 
                if config_file_initialize_app:
 
                    kallithea.config.middleware.make_app_without_logging(kallithea.CONFIG.global_conf, **kallithea.CONFIG.local_conf)
 
                    kallithea.lib.utils.setup_cache_regions(kallithea.CONFIG)
 
                return annotated(*args, **kwargs)
 
            return cli_command(runtime_wrapper)
 
        return annotator
 
    return cli_command
setup.py
Show inline comments
 
modified file chmod 100644 => 100755
 
@@ -52,24 +52,25 @@ requirements = [
 
    "celery >= 3.1, < 4.0", # celery 4 doesn't work
 
    "Babel >= 0.9.6, < 2.7",
 
    "python-dateutil >= 1.5.0, < 2.8",
 
    "Markdown >= 2.2.1, < 2.7",
 
    "docutils >= 0.8.1, < 0.15",
 
    "URLObject >= 2.3.4, < 2.5",
 
    "Routes >= 1.13, < 2",
 
    "dulwich >= 0.14.1, < 0.20",
 
    "mercurial >= 4.1.1, < 4.9",
 
    "decorator >= 3.3.2, < 4.4",
 
    "Paste >= 2.0.3, < 3",
 
    "bleach >= 3.0, < 3.1",
 
    "Click >= 7.0, < 8",
 
]
 

	
 
if sys.version_info < (2, 7):
 
    requirements.append("importlib == 1.0.1")
 
    requirements.append("argparse")
 

	
 
if not is_windows:
 
    requirements.append("bcrypt >= 3.1.0, < 3.2")
 

	
 
dependency_links = [
 
]
 

	
 
@@ -143,24 +144,25 @@ setuptools.setup(
 
    include_package_data=True,
 
    message_extractors={'kallithea': [
 
            ('**.py', 'python', None),
 
            ('templates/**.mako', 'mako', {'input_encoding': 'utf-8'}),
 
            ('templates/**.html', 'mako', {'input_encoding': 'utf-8'}),
 
            ('public/**', 'ignore', None)]},
 
    zip_safe=False,
 
    entry_points="""
 
    [console_scripts]
 
    kallithea-api =    kallithea.bin.kallithea_api:main
 
    kallithea-gist =   kallithea.bin.kallithea_gist:main
 
    kallithea-config = kallithea.bin.kallithea_config:main
 
    kallithea-cli =    kallithea.bin.kallithea_cli:cli
 

	
 
    [paste.app_factory]
 
    main = kallithea.config.middleware:make_app
 

	
 
    [gearbox.commands]
 
    cache-keys=kallithea.lib.paster_commands.cache_keys:Command
 
    celeryd=kallithea.lib.paster_commands.celeryd:Command
 
    cleanup-repos=kallithea.lib.paster_commands.cleanup:Command
 
    install-iis=kallithea.lib.paster_commands.install_iis:Command
 
    ishell=kallithea.lib.paster_commands.ishell:Command
 
    make-config=kallithea.lib.paster_commands.make_config:Command
 
    make-index=kallithea.lib.paster_commands.make_index:Command
0 comments (0 inline, 0 general)