| |
@@ -1,14 +1,13 @@
|
| |
# -*- coding: utf-8 -*-
|
| |
# SPDX-License-Identifier: MIT
|
| |
from __future__ import absolute_import, print_function
|
| |
- from functools import wraps
|
| |
+ import click
|
| |
import getpass
|
| |
import logging
|
| |
import os
|
| |
- import textwrap
|
| |
|
| |
import flask_migrate
|
| |
- from flask_script import Manager, prompt_bool
|
| |
+ from flask.cli import FlaskGroup
|
| |
from werkzeug.datastructures import FileStorage
|
| |
|
| |
from module_build_service import app, db
|
| |
@@ -17,76 +16,39 @@
|
| |
)
|
| |
from module_build_service.common import conf, models
|
| |
from module_build_service.common.errors import StreamAmbigous
|
| |
- from module_build_service.common.logger import level_flags
|
| |
from module_build_service.common.utils import load_mmd_file, import_mmd
|
| |
import module_build_service.scheduler.consumer
|
| |
from module_build_service.scheduler.db_session import db_session
|
| |
import module_build_service.scheduler.local
|
| |
from module_build_service.web.submit import submit_module_build_from_yaml
|
| |
|
| |
-
|
| |
- def create_app(debug=False, verbose=False, quiet=False):
|
| |
- # logging (intended for flask-script, see manage.py)
|
| |
- log = logging.getLogger(__name__)
|
| |
- if debug:
|
| |
- log.setLevel(level_flags["debug"])
|
| |
- elif verbose:
|
| |
- log.setLevel(level_flags["verbose"])
|
| |
- elif quiet:
|
| |
- log.setLevel(level_flags["quiet"])
|
| |
-
|
| |
- return app
|
| |
-
|
| |
-
|
| |
- manager = Manager(create_app)
|
| |
- help_args = ("-?", "--help")
|
| |
- manager.help_args = help_args
|
| |
- migrations_dir = os.path.join(os.path.abspath(os.path.dirname(__file__)),
|
| |
- 'migrations')
|
| |
+ migrations_dir = os.path.join(os.path.abspath(os.path.dirname(__file__)), "migrations")
|
| |
migrate = flask_migrate.Migrate(app, db, directory=migrations_dir)
|
| |
- manager.add_command("db", flask_migrate.MigrateCommand)
|
| |
- manager.add_option("-d", "--debug", dest="debug", action="store_true")
|
| |
- manager.add_option("-v", "--verbose", dest="verbose", action="store_true")
|
| |
- manager.add_option("-q", "--quiet", dest="quiet", action="store_true")
|
| |
-
|
| |
-
|
| |
- def console_script_help(f):
|
| |
- @wraps(f)
|
| |
- def wrapped(*args, **kwargs):
|
| |
- import sys
|
| |
|
| |
- if any([arg in help_args for arg in sys.argv[1:]]):
|
| |
- command = os.path.basename(sys.argv[0])
|
| |
- print(textwrap.dedent(
|
| |
- """\
|
| |
- {0}
|
| |
|
| |
- Usage: {0} [{1}]
|
| |
+ @click.group(cls=FlaskGroup, create_app=lambda *args, **kwargs: app)
|
| |
+ def cli():
|
| |
+ """MBS manager"""
|
| |
|
| |
- See also:
|
| |
- mbs-manager(1)
|
| |
- """).strip().format(command, "|".join(help_args))
|
| |
- )
|
| |
- sys.exit(2)
|
| |
- r = f(*args, **kwargs)
|
| |
- return r
|
| |
|
| |
- return wrapped
|
| |
+ cli.command("db", flask_migrate.MigrateCommand)
|
| |
|
| |
|
| |
- @console_script_help
|
| |
- @manager.command
|
| |
+ @cli.command("upgradedb")
|
| |
def upgradedb():
|
| |
""" Upgrades the database schema to the latest revision
|
| |
"""
|
| |
app.config["SERVER_NAME"] = "localhost"
|
| |
- # TODO: configurable?
|
| |
- migrations_dir = os.path.join(os.path.abspath(os.path.dirname(__file__)), "migrations")
|
| |
with app.app_context():
|
| |
flask_migrate.upgrade(directory=migrations_dir)
|
| |
|
| |
|
| |
- @manager.command
|
| |
+ def upgradedb_entrypoint():
|
| |
+ """Entrypoint for command mbs-upgradedb"""
|
| |
+ cli(["db", "upgrade"])
|
| |
+
|
| |
+
|
| |
+ @cli.command("cleardb")
|
| |
def cleardb():
|
| |
""" Clears the database
|
| |
"""
|
| |
@@ -94,8 +56,8 @@
|
| |
models.ComponentBuild.query.delete()
|
| |
|
| |
|
| |
- @console_script_help
|
| |
- @manager.command
|
| |
+ @cli.command("import_module")
|
| |
+ @click.argument("mmd_file", type=click.Path(exists=True))
|
| |
def import_module(mmd_file):
|
| |
""" Imports the module from mmd_file
|
| |
"""
|
| |
@@ -103,29 +65,44 @@
|
| |
import_mmd(db.session, mmd)
|
| |
|
| |
|
| |
- @manager.option("--stream", action="store", dest="stream")
|
| |
- @manager.option("--file", action="store", dest="yaml_file")
|
| |
- @manager.option("--srpm", action="append", default=[], dest="srpms", metavar="SRPM")
|
| |
- @manager.option("--skiptests", action="store_true", dest="skiptests")
|
| |
- @manager.option("--offline", action="store_true", dest="offline")
|
| |
- @manager.option("-d", "--debug", action="store_true", dest="log_debug")
|
| |
- @manager.option("-l", "--add-local-build", action="append", default=None, dest="local_build_nsvs")
|
| |
- @manager.option("-s", "--set-stream", action="append", default=[], dest="default_streams")
|
| |
- @manager.option(
|
| |
- "-r", "--platform-repo-file", action="append", default=[], dest="platform_repofiles"
|
| |
+ @cli.command("build_module_locally")
|
| |
+ @click.option("--stream", metavar="STREAM")
|
| |
+ @click.option(
|
| |
+ "--file", "yaml_file",
|
| |
+ metavar="FILE",
|
| |
+ required=True,
|
| |
+ type=click.Path(exists=True),
|
| |
+ )
|
| |
+ @click.option("--srpm", "srpms", metavar="SRPM", multiple=True)
|
| |
+ @click.option("--skiptests", is_flag=True)
|
| |
+ @click.option("--offline", is_flag=True)
|
| |
+ @click.option("-d", "--debug", "log_debug", is_flag=True)
|
| |
+ @click.option(
|
| |
+ "-l", "--add-local-build", "local_build_nsvs",
|
| |
+ metavar="NSV", multiple=True
|
| |
+ )
|
| |
+ @click.option(
|
| |
+ "-s", "--set-stream", "default_streams",
|
| |
+ metavar="STREAM", multiple=True
|
| |
+ )
|
| |
+ @click.option(
|
| |
+ "-r", "--platform-repo-file", "platform_repofiles",
|
| |
+ metavar="FILE",
|
| |
+ type=click.Path(exists=True),
|
| |
+ multiple=True
|
| |
)
|
| |
- @manager.option("-p", "--platform-id", action="store", default=None, dest="platform_id")
|
| |
+ @click.option("-p", "--platform-id", metavar="PLATFORM_ID")
|
| |
def build_module_locally(
|
| |
- local_build_nsvs=None,
|
| |
+ stream=None,
|
| |
yaml_file=None,
|
| |
srpms=None,
|
| |
- stream=None,
|
| |
skiptests=False,
|
| |
- default_streams=None,
|
| |
offline=False,
|
| |
+ log_debug=False,
|
| |
+ local_build_nsvs=None,
|
| |
+ default_streams=None,
|
| |
platform_repofiles=None,
|
| |
platform_id=None,
|
| |
- log_debug=False,
|
| |
):
|
| |
""" Performs local module build using Mock
|
| |
"""
|
| |
@@ -205,14 +182,11 @@
|
| |
raise RuntimeError("Module build failed")
|
| |
|
| |
|
| |
- @manager.option(
|
| |
- "identifier",
|
| |
- metavar="NAME:STREAM[:VERSION[:CONTEXT]]",
|
| |
- help="Identifier for selecting module builds to retire",
|
| |
- )
|
| |
- @manager.option(
|
| |
+ @cli.command("retire")
|
| |
+ @click.argument("identifier", metavar="NAME:STREAM[:VERSION[:CONTEXT]]")
|
| |
+ @click.option(
|
| |
"--confirm",
|
| |
- action="store_true",
|
| |
+ is_flag=True,
|
| |
default=False,
|
| |
help="Perform retire operation without prompting",
|
| |
)
|
| |
@@ -245,7 +219,8 @@
|
| |
logging.info("\t%s", ":".join((build.name, build.stream, build.version, build.context)))
|
| |
|
| |
# Prompt for confirmation
|
| |
- is_confirmed = confirm or prompt_bool("Retire {} module builds?".format(len(module_builds)))
|
| |
+ confirm_msg = "Retire {} module builds?".format(len(module_builds))
|
| |
+ is_confirmed = confirm or click.confirm(confirm_msg, abort=False)
|
| |
if not is_confirmed:
|
| |
logging.info("Module builds were NOT retired.")
|
| |
return
|
| |
@@ -260,8 +235,10 @@
|
| |
logging.info("Module builds retired.")
|
| |
|
| |
|
| |
- @console_script_help
|
| |
- @manager.command
|
| |
+ @cli.command("run")
|
| |
+ @click.option("-h", "--host", metavar="HOST", help="Bind to this host.")
|
| |
+ @click.option("-p", "--port", metavar="PORT", help="Bind to this port along with --host.")
|
| |
+ @click.option("-d", "--debug", is_flag=True, default=False, help="Run frontend in debug mode.")
|
| |
def run(host=None, port=None, debug=None):
|
| |
""" Runs the Flask app, locally.
|
| |
"""
|
| |
@@ -274,9 +251,5 @@
|
| |
app.run(host=host, port=port, debug=debug)
|
| |
|
| |
|
| |
- def manager_wrapper():
|
| |
- manager.run()
|
| |
-
|
| |
-
|
| |
if __name__ == "__main__":
|
| |
- manager_wrapper()
|
| |
+ cli()
|
| |
Resolves: FACTORY-4876
Signed-off-by: Chenxiong Qi cqi@redhat.com