mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-04-24 15:27:17 +00:00
add status update subcommand
also satisfy pylint with too big method with too much variables
This commit is contained in:
parent
646190121a
commit
803b7bee1e
@ -23,8 +23,14 @@ import sys
|
|||||||
import ahriman.application.handlers as handlers
|
import ahriman.application.handlers as handlers
|
||||||
import ahriman.version as version
|
import ahriman.version as version
|
||||||
|
|
||||||
|
from ahriman.models.build_status import BuildStatusEnum
|
||||||
|
|
||||||
|
|
||||||
|
# pylint thinks it is bad idea, but get the fuck off
|
||||||
|
# pylint: disable=protected-access
|
||||||
|
SubParserAction = argparse._SubParsersAction
|
||||||
|
|
||||||
|
|
||||||
# pylint: disable=too-many-statements
|
|
||||||
def _parser() -> argparse.ArgumentParser:
|
def _parser() -> argparse.ArgumentParser:
|
||||||
"""
|
"""
|
||||||
command line parser generator
|
command line parser generator
|
||||||
@ -43,73 +49,207 @@ def _parser() -> argparse.ArgumentParser:
|
|||||||
|
|
||||||
subparsers = parser.add_subparsers(title="command", help="command to run", dest="command", required=True)
|
subparsers = parser.add_subparsers(title="command", help="command to run", dest="command", required=True)
|
||||||
|
|
||||||
add_parser = subparsers.add_parser("add", description="add package")
|
_set_add_parser(subparsers)
|
||||||
add_parser.add_argument("package", help="package base/name or archive path", nargs="+")
|
_set_check_parser(subparsers)
|
||||||
add_parser.add_argument("--without-dependencies", help="do not add dependencies", action="store_true")
|
_set_clean_parser(subparsers)
|
||||||
add_parser.set_defaults(handler=handlers.Add)
|
_set_config_parser(subparsers)
|
||||||
|
_set_rebuild_parser(subparsers)
|
||||||
|
_set_remove_parser(subparsers)
|
||||||
|
_set_report_parser(subparsers)
|
||||||
|
_set_setup_parser(subparsers)
|
||||||
|
_set_sign_parser(subparsers)
|
||||||
|
_set_status_parser(subparsers)
|
||||||
|
_set_status_update_parser(subparsers)
|
||||||
|
_set_sync_parser(subparsers)
|
||||||
|
_set_update_parser(subparsers)
|
||||||
|
_set_web_parser(subparsers)
|
||||||
|
|
||||||
check_parser = subparsers.add_parser("check", description="check for updates. Same as update --dry-run --no-manual")
|
return parser
|
||||||
check_parser.add_argument("package", help="filter check by package base", nargs="*")
|
|
||||||
check_parser.add_argument("--no-vcs", help="do not check VCS packages", action="store_true")
|
|
||||||
check_parser.set_defaults(handler=handlers.Update, no_aur=False, no_manual=True, dry_run=True)
|
|
||||||
|
|
||||||
clean_parser = subparsers.add_parser("clean", description="clear all local caches")
|
|
||||||
clean_parser.add_argument("--no-build", help="do not clear directory with package sources", action="store_true")
|
|
||||||
clean_parser.add_argument("--no-cache", help="do not clear directory with package caches", action="store_true")
|
|
||||||
clean_parser.add_argument("--no-chroot", help="do not clear build chroot", action="store_true")
|
|
||||||
clean_parser.add_argument("--no-manual", help="do not clear directory with manually added packages",
|
|
||||||
action="store_true")
|
|
||||||
clean_parser.add_argument("--no-packages", help="do not clear directory with built packages", action="store_true")
|
|
||||||
clean_parser.set_defaults(handler=handlers.Clean, unsafe=True)
|
|
||||||
|
|
||||||
config_parser = subparsers.add_parser("config", description="dump configuration for specified architecture")
|
def _set_add_parser(root: SubParserAction) -> argparse.ArgumentParser:
|
||||||
config_parser.set_defaults(handler=handlers.Dump, lock=None, no_report=True, unsafe=True)
|
"""
|
||||||
|
add parser for add subcommand
|
||||||
|
:param root: subparsers for the commands
|
||||||
|
:return: created argument parser
|
||||||
|
"""
|
||||||
|
parser = root.add_parser("add", description="add package")
|
||||||
|
parser.add_argument("package", help="package base/name or archive path", nargs="+")
|
||||||
|
parser.add_argument("--without-dependencies", help="do not add dependencies", action="store_true")
|
||||||
|
parser.set_defaults(handler=handlers.Add)
|
||||||
|
return parser
|
||||||
|
|
||||||
rebuild_parser = subparsers.add_parser("rebuild", description="rebuild whole repository")
|
|
||||||
rebuild_parser.set_defaults(handler=handlers.Rebuild)
|
|
||||||
|
|
||||||
remove_parser = subparsers.add_parser("remove", description="remove package")
|
def _set_check_parser(root: SubParserAction) -> argparse.ArgumentParser:
|
||||||
remove_parser.add_argument("package", help="package name or base", nargs="+")
|
"""
|
||||||
remove_parser.set_defaults(handler=handlers.Remove)
|
add parser for check subcommand
|
||||||
|
:param root: subparsers for the commands
|
||||||
|
:return: created argument parser
|
||||||
|
"""
|
||||||
|
parser = root.add_parser("check", description="check for updates. Same as update --dry-run --no-manual")
|
||||||
|
parser.add_argument("package", help="filter check by package base", nargs="*")
|
||||||
|
parser.add_argument("--no-vcs", help="do not check VCS packages", action="store_true")
|
||||||
|
parser.set_defaults(handler=handlers.Update, no_aur=False, no_manual=True, dry_run=True)
|
||||||
|
return parser
|
||||||
|
|
||||||
report_parser = subparsers.add_parser("report", description="generate report")
|
|
||||||
report_parser.add_argument("target", help="target to generate report", nargs="*")
|
|
||||||
report_parser.set_defaults(handler=handlers.Report)
|
|
||||||
|
|
||||||
setup_parser = subparsers.add_parser("setup", description="create initial service configuration, requires root")
|
def _set_clean_parser(root: SubParserAction) -> argparse.ArgumentParser:
|
||||||
setup_parser.add_argument("--build-command", help="build command prefix", default="ahriman")
|
"""
|
||||||
setup_parser.add_argument("--from-config", help="path to default devtools pacman configuration",
|
add parser for clean subcommand
|
||||||
default="/usr/share/devtools/pacman-extra.conf")
|
:param root: subparsers for the commands
|
||||||
setup_parser.add_argument("--no-multilib", help="do not add multilib repository", action="store_true")
|
:return: created argument parser
|
||||||
setup_parser.add_argument("--packager", help="packager name and email", required=True)
|
"""
|
||||||
setup_parser.add_argument("--repository", help="repository name", default="aur-clone")
|
parser = root.add_parser("clean", description="clear all local caches")
|
||||||
setup_parser.set_defaults(handler=handlers.Setup, lock=None, no_report=True, unsafe=True)
|
parser.add_argument("--no-build", help="do not clear directory with package sources", action="store_true")
|
||||||
|
parser.add_argument("--no-cache", help="do not clear directory with package caches", action="store_true")
|
||||||
|
parser.add_argument("--no-chroot", help="do not clear build chroot", action="store_true")
|
||||||
|
parser.add_argument("--no-manual", help="do not clear directory with manually added packages", action="store_true")
|
||||||
|
parser.add_argument("--no-packages", help="do not clear directory with built packages", action="store_true")
|
||||||
|
parser.set_defaults(handler=handlers.Clean, unsafe=True)
|
||||||
|
return parser
|
||||||
|
|
||||||
sign_parser = subparsers.add_parser("sign", description="(re-)sign packages and repository database")
|
|
||||||
sign_parser.add_argument("package", help="sign only specified packages", nargs="*")
|
|
||||||
sign_parser.set_defaults(handler=handlers.Sign)
|
|
||||||
|
|
||||||
status_parser = subparsers.add_parser("status", description="request status of the package")
|
def _set_config_parser(root: SubParserAction) -> argparse.ArgumentParser:
|
||||||
status_parser.add_argument("--ahriman", help="get service status itself", action="store_true")
|
"""
|
||||||
status_parser.add_argument("package", help="filter status by package base", nargs="*")
|
add parser for config subcommand
|
||||||
status_parser.set_defaults(handler=handlers.Status, lock=None, no_report=True, unsafe=True)
|
:param root: subparsers for the commands
|
||||||
|
:return: created argument parser
|
||||||
|
"""
|
||||||
|
parser = root.add_parser("config", description="dump configuration for specified architecture")
|
||||||
|
parser.set_defaults(handler=handlers.Dump, lock=None, no_report=True, unsafe=True)
|
||||||
|
return parser
|
||||||
|
|
||||||
sync_parser = subparsers.add_parser("sync", description="sync packages to remote server")
|
|
||||||
sync_parser.add_argument("target", help="target to sync", nargs="*")
|
|
||||||
sync_parser.set_defaults(handler=handlers.Sync)
|
|
||||||
|
|
||||||
update_parser = subparsers.add_parser("update", description="run updates")
|
def _set_rebuild_parser(root: SubParserAction) -> argparse.ArgumentParser:
|
||||||
update_parser.add_argument("package", help="filter check by package base", nargs="*")
|
"""
|
||||||
update_parser.add_argument("--dry-run", help="just perform check for updates, same as check command",
|
add parser for rebuild subcommand
|
||||||
action="store_true")
|
:param root: subparsers for the commands
|
||||||
update_parser.add_argument("--no-aur", help="do not check for AUR updates. Implies --no-vcs", action="store_true")
|
:return: created argument parser
|
||||||
update_parser.add_argument("--no-manual", help="do not include manual updates", action="store_true")
|
"""
|
||||||
update_parser.add_argument("--no-vcs", help="do not check VCS packages", action="store_true")
|
parser = root.add_parser("rebuild", description="rebuild whole repository")
|
||||||
update_parser.set_defaults(handler=handlers.Update)
|
parser.set_defaults(handler=handlers.Rebuild)
|
||||||
|
return parser
|
||||||
|
|
||||||
web_parser = subparsers.add_parser("web", description="start web server")
|
|
||||||
web_parser.set_defaults(handler=handlers.Web, lock=None, no_report=True)
|
|
||||||
|
|
||||||
|
def _set_remove_parser(root: SubParserAction) -> argparse.ArgumentParser:
|
||||||
|
"""
|
||||||
|
add parser for remove subcommand
|
||||||
|
:param root: subparsers for the commands
|
||||||
|
:return: created argument parser
|
||||||
|
"""
|
||||||
|
parser = root.add_parser("remove", description="remove package")
|
||||||
|
parser.add_argument("package", help="package name or base", nargs="+")
|
||||||
|
parser.set_defaults(handler=handlers.Remove)
|
||||||
|
return parser
|
||||||
|
|
||||||
|
|
||||||
|
def _set_report_parser(root: SubParserAction) -> argparse.ArgumentParser:
|
||||||
|
"""
|
||||||
|
add parser for report subcommand
|
||||||
|
:param root: subparsers for the commands
|
||||||
|
:return: created argument parser
|
||||||
|
"""
|
||||||
|
parser = root.add_parser("report", description="generate report")
|
||||||
|
parser.add_argument("target", help="target to generate report", nargs="*")
|
||||||
|
parser.set_defaults(handler=handlers.Report)
|
||||||
|
return parser
|
||||||
|
|
||||||
|
|
||||||
|
def _set_setup_parser(root: SubParserAction) -> argparse.ArgumentParser:
|
||||||
|
"""
|
||||||
|
add parser for setup subcommand
|
||||||
|
:param root: subparsers for the commands
|
||||||
|
:return: created argument parser
|
||||||
|
"""
|
||||||
|
parser = root.add_parser("setup", description="create initial service configuration, requires root")
|
||||||
|
parser.add_argument("--build-command", help="build command prefix", default="ahriman")
|
||||||
|
parser.add_argument("--from-config", help="path to default devtools pacman configuration",
|
||||||
|
default="/usr/share/devtools/pacman-extra.conf")
|
||||||
|
parser.add_argument("--no-multilib", help="do not add multilib repository", action="store_true")
|
||||||
|
parser.add_argument("--packager", help="packager name and email", required=True)
|
||||||
|
parser.add_argument("--repository", help="repository name", default="aur-clone")
|
||||||
|
parser.set_defaults(handler=handlers.Setup, lock=None, no_report=True, unsafe=True)
|
||||||
|
return parser
|
||||||
|
|
||||||
|
|
||||||
|
def _set_sign_parser(root: SubParserAction) -> argparse.ArgumentParser:
|
||||||
|
"""
|
||||||
|
add parser for sign subcommand
|
||||||
|
:param root: subparsers for the commands
|
||||||
|
:return: created argument parser
|
||||||
|
"""
|
||||||
|
parser = root.add_parser("sign", description="(re-)sign packages and repository database")
|
||||||
|
parser.add_argument("package", help="sign only specified packages", nargs="*")
|
||||||
|
parser.set_defaults(handler=handlers.Sign)
|
||||||
|
return parser
|
||||||
|
|
||||||
|
|
||||||
|
def _set_status_parser(root: SubParserAction) -> argparse.ArgumentParser:
|
||||||
|
"""
|
||||||
|
add parser for status subcommand
|
||||||
|
:param root: subparsers for the commands
|
||||||
|
:return: created argument parser
|
||||||
|
"""
|
||||||
|
parser = root.add_parser("status", description="request status of the package")
|
||||||
|
parser.add_argument("--ahriman", help="get service status itself", action="store_true")
|
||||||
|
parser.add_argument("package", help="filter status by package base", nargs="*")
|
||||||
|
parser.set_defaults(handler=handlers.Status, lock=None, no_report=True, unsafe=True)
|
||||||
|
return parser
|
||||||
|
|
||||||
|
|
||||||
|
def _set_status_update_parser(root: SubParserAction) -> argparse.ArgumentParser:
|
||||||
|
"""
|
||||||
|
add parser for status update subcommand
|
||||||
|
:param root: subparsers for the commands
|
||||||
|
:return: created argument parser
|
||||||
|
"""
|
||||||
|
parser = root.add_parser("status-update", description="request status of the package")
|
||||||
|
parser.add_argument(
|
||||||
|
"package",
|
||||||
|
help="set status for specified packages. If no packages supplied, service status will be updated",
|
||||||
|
nargs="*")
|
||||||
|
parser.add_argument("--status", help="new status", choices=[value.value for value in BuildStatusEnum],
|
||||||
|
default="success")
|
||||||
|
parser.set_defaults(handler=handlers.StatusUpdate, lock=None, no_report=True, unsafe=True)
|
||||||
|
return parser
|
||||||
|
|
||||||
|
|
||||||
|
def _set_sync_parser(root: SubParserAction) -> argparse.ArgumentParser:
|
||||||
|
"""
|
||||||
|
add parser for sync subcommand
|
||||||
|
:param root: subparsers for the commands
|
||||||
|
:return: created argument parser
|
||||||
|
"""
|
||||||
|
parser = root.add_parser("sync", description="sync packages to remote server")
|
||||||
|
parser.add_argument("target", help="target to sync", nargs="*")
|
||||||
|
parser.set_defaults(handler=handlers.Sync)
|
||||||
|
return parser
|
||||||
|
|
||||||
|
|
||||||
|
def _set_update_parser(root: SubParserAction) -> argparse.ArgumentParser:
|
||||||
|
"""
|
||||||
|
add parser for update subcommand
|
||||||
|
:param root: subparsers for the commands
|
||||||
|
:return: created argument parser
|
||||||
|
"""
|
||||||
|
parser = root.add_parser("update", description="run updates")
|
||||||
|
parser.add_argument("package", help="filter check by package base", nargs="*")
|
||||||
|
parser.add_argument("--dry-run", help="just perform check for updates, same as check command", action="store_true")
|
||||||
|
parser.add_argument("--no-aur", help="do not check for AUR updates. Implies --no-vcs", action="store_true")
|
||||||
|
parser.add_argument("--no-manual", help="do not include manual updates", action="store_true")
|
||||||
|
parser.add_argument("--no-vcs", help="do not check VCS packages", action="store_true")
|
||||||
|
parser.set_defaults(handler=handlers.Update)
|
||||||
|
return parser
|
||||||
|
|
||||||
|
|
||||||
|
def _set_web_parser(root: SubParserAction) -> argparse.ArgumentParser:
|
||||||
|
"""
|
||||||
|
add parser for web subcommand
|
||||||
|
:param root: subparsers for the commands
|
||||||
|
:return: created argument parser
|
||||||
|
"""
|
||||||
|
parser = root.add_parser("web", description="start web server")
|
||||||
|
parser.set_defaults(handler=handlers.Web, lock=None, no_report=True)
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
|
|
||||||
|
@ -28,6 +28,7 @@ from ahriman.application.handlers.report import Report
|
|||||||
from ahriman.application.handlers.setup import Setup
|
from ahriman.application.handlers.setup import Setup
|
||||||
from ahriman.application.handlers.sign import Sign
|
from ahriman.application.handlers.sign import Sign
|
||||||
from ahriman.application.handlers.status import Status
|
from ahriman.application.handlers.status import Status
|
||||||
|
from ahriman.application.handlers.status_update import StatusUpdate
|
||||||
from ahriman.application.handlers.sync import Sync
|
from ahriman.application.handlers.sync import Sync
|
||||||
from ahriman.application.handlers.update import Update
|
from ahriman.application.handlers.update import Update
|
||||||
from ahriman.application.handlers.web import Web
|
from ahriman.application.handlers.web import Web
|
||||||
|
51
src/ahriman/application/handlers/status_update.py
Normal file
51
src/ahriman/application/handlers/status_update.py
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
#
|
||||||
|
# Copyright (c) 2021 ahriman team.
|
||||||
|
#
|
||||||
|
# This file is part of ahriman
|
||||||
|
# (see https://github.com/arcan1s/ahriman).
|
||||||
|
#
|
||||||
|
# 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 argparse
|
||||||
|
|
||||||
|
from typing import Type
|
||||||
|
|
||||||
|
from ahriman.application.application import Application
|
||||||
|
from ahriman.application.handlers.handler import Handler
|
||||||
|
from ahriman.core.configuration import Configuration
|
||||||
|
from ahriman.models.build_status import BuildStatusEnum
|
||||||
|
|
||||||
|
|
||||||
|
class StatusUpdate(Handler):
|
||||||
|
"""
|
||||||
|
status update handler
|
||||||
|
"""
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def run(cls: Type[Handler], args: argparse.Namespace, architecture: str, config: Configuration) -> None:
|
||||||
|
"""
|
||||||
|
callback for command line
|
||||||
|
:param args: command line args
|
||||||
|
:param architecture: repository architecture
|
||||||
|
:param config: configuration instance
|
||||||
|
"""
|
||||||
|
client = Application(architecture, config).repository.reporter
|
||||||
|
status = BuildStatusEnum(args.status)
|
||||||
|
if args.package:
|
||||||
|
# update packages statuses
|
||||||
|
for package in args.package:
|
||||||
|
client.update(package, status)
|
||||||
|
else:
|
||||||
|
# update service status
|
||||||
|
client.update_self(status)
|
@ -0,0 +1,40 @@
|
|||||||
|
import argparse
|
||||||
|
|
||||||
|
from pytest_mock import MockerFixture
|
||||||
|
|
||||||
|
from ahriman.application.handlers import StatusUpdate
|
||||||
|
from ahriman.core.configuration import Configuration
|
||||||
|
from ahriman.models.build_status import BuildStatusEnum
|
||||||
|
from ahriman.models.package import Package
|
||||||
|
|
||||||
|
|
||||||
|
def _default_args(args: argparse.Namespace) -> argparse.Namespace:
|
||||||
|
args.status = BuildStatusEnum.Success.value
|
||||||
|
args.package = None
|
||||||
|
return args
|
||||||
|
|
||||||
|
|
||||||
|
def test_run(args: argparse.Namespace, configuration: Configuration, mocker: MockerFixture) -> None:
|
||||||
|
"""
|
||||||
|
must run command
|
||||||
|
"""
|
||||||
|
args = _default_args(args)
|
||||||
|
mocker.patch("pathlib.Path.mkdir")
|
||||||
|
update_self_mock = mocker.patch("ahriman.core.status.client.Client.update_self")
|
||||||
|
|
||||||
|
StatusUpdate.run(args, "x86_64", configuration)
|
||||||
|
update_self_mock.assert_called_once()
|
||||||
|
|
||||||
|
|
||||||
|
def test_run_packages(args: argparse.Namespace, configuration: Configuration, package_ahriman: Package,
|
||||||
|
mocker: MockerFixture) -> None:
|
||||||
|
"""
|
||||||
|
must run command with specified packages
|
||||||
|
"""
|
||||||
|
args = _default_args(args)
|
||||||
|
args.package = [package_ahriman.base]
|
||||||
|
mocker.patch("pathlib.Path.mkdir")
|
||||||
|
update_mock = mocker.patch("ahriman.core.status.client.Client.update")
|
||||||
|
|
||||||
|
StatusUpdate.run(args, "x86_64", configuration)
|
||||||
|
update_mock.assert_called_once()
|
@ -64,6 +64,16 @@ def test_subparsers_status(parser: argparse.ArgumentParser) -> None:
|
|||||||
assert args.unsafe
|
assert args.unsafe
|
||||||
|
|
||||||
|
|
||||||
|
def test_subparsers_status_update(parser: argparse.ArgumentParser) -> None:
|
||||||
|
"""
|
||||||
|
status-update command must imply lock, no_report and unsafe
|
||||||
|
"""
|
||||||
|
args = parser.parse_args(["-a", "x86_64", "status-update"])
|
||||||
|
assert args.lock is None
|
||||||
|
assert args.no_report
|
||||||
|
assert args.unsafe
|
||||||
|
|
||||||
|
|
||||||
def test_subparsers_web(parser: argparse.ArgumentParser) -> None:
|
def test_subparsers_web(parser: argparse.ArgumentParser) -> None:
|
||||||
"""
|
"""
|
||||||
web command must imply lock and no_report
|
web command must imply lock and no_report
|
||||||
|
Loading…
Reference in New Issue
Block a user