From 2376603de92761437a489c82c2fa0317f97de1af Mon Sep 17 00:00:00 2001 From: Evgenii Alekseev Date: Sun, 27 Oct 2024 14:28:12 +0200 Subject: [PATCH] separate support triggers from main package --- src/ahriman/application/handlers/triggers.py | 38 ---------- .../application/handlers/triggers_support.py | 70 +++++++++++++++++++ subpackages.py | 3 +- .../handlers/test_handler_triggers_support.py | 1 + 4 files changed, 73 insertions(+), 39 deletions(-) create mode 100644 src/ahriman/application/handlers/triggers_support.py create mode 100644 tests/ahriman/application/handlers/test_handler_triggers_support.py diff --git a/src/ahriman/application/handlers/triggers.py b/src/ahriman/application/handlers/triggers.py index 023a53d9..9d0ea46a 100644 --- a/src/ahriman/application/handlers/triggers.py +++ b/src/ahriman/application/handlers/triggers.py @@ -50,42 +50,6 @@ class Triggers(Handler): application.on_start() application.on_result(Result()) - @staticmethod - def _set_repo_create_keyring_parser(root: SubParserAction) -> argparse.ArgumentParser: - """ - add parser for create-keyring subcommand - - Args: - root(SubParserAction): subparsers for the commands - - Returns: - argparse.ArgumentParser: created argument parser - """ - parser = root.add_parser("repo-create-keyring", help="create keyring package", - description="create package which contains list of trusted keys as set by " - "configuration. Note, that this action will only create package, " - "the package itself has to be built manually") - parser.set_defaults(trigger=["ahriman.core.support.KeyringTrigger"]) - return parser - - @staticmethod - def _set_repo_create_mirrorlist_parser(root: SubParserAction) -> argparse.ArgumentParser: - """ - add parser for create-mirrorlist subcommand - - Args: - root(SubParserAction): subparsers for the commands - - Returns: - argparse.ArgumentParser: created argument parser - """ - parser = root.add_parser("repo-create-mirrorlist", help="create mirrorlist package", - description="create package which contains list of available mirrors as set by " - "configuration. Note, that this action will only create package, " - "the package itself has to be built manually") - parser.set_defaults(trigger=["ahriman.core.support.MirrorlistTrigger"]) - return parser - @staticmethod def _set_repo_report_parser(root: SubParserAction) -> argparse.ArgumentParser: """ @@ -138,8 +102,6 @@ class Triggers(Handler): return parser arguments = [ - _set_repo_create_keyring_parser, - _set_repo_create_mirrorlist_parser, _set_repo_report_parser, _set_repo_sync_parser, _set_repo_triggers_parser, diff --git a/src/ahriman/application/handlers/triggers_support.py b/src/ahriman/application/handlers/triggers_support.py new file mode 100644 index 00000000..f7e31691 --- /dev/null +++ b/src/ahriman/application/handlers/triggers_support.py @@ -0,0 +1,70 @@ +# +# Copyright (c) 2021-2024 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 . +# +import argparse + +from ahriman.application.handlers.handler import SubParserAction +from ahriman.application.handlers.triggers import Triggers + + +class TriggersSupport(Triggers): + """ + additional triggers handlers for support commands + """ + + @staticmethod + def _set_repo_create_keyring_parser(root: SubParserAction) -> argparse.ArgumentParser: + """ + add parser for create-keyring subcommand + + Args: + root(SubParserAction): subparsers for the commands + + Returns: + argparse.ArgumentParser: created argument parser + """ + parser = root.add_parser("repo-create-keyring", help="create keyring package", + description="create package which contains list of trusted keys as set by " + "configuration. Note, that this action will only create package, " + "the package itself has to be built manually") + parser.set_defaults(trigger=["ahriman.core.support.KeyringTrigger"]) + return parser + + @staticmethod + def _set_repo_create_mirrorlist_parser(root: SubParserAction) -> argparse.ArgumentParser: + """ + add parser for create-mirrorlist subcommand + + Args: + root(SubParserAction): subparsers for the commands + + Returns: + argparse.ArgumentParser: created argument parser + """ + parser = root.add_parser("repo-create-mirrorlist", help="create mirrorlist package", + description="create package which contains list of available mirrors as set by " + "configuration. Note, that this action will only create package, " + "the package itself has to be built manually") + parser.set_defaults(trigger=["ahriman.core.support.MirrorlistTrigger"]) + return parser + + arguments = [ + _set_repo_create_keyring_parser, + _set_repo_create_mirrorlist_parser, + ] diff --git a/subpackages.py b/subpackages.py index 16decf4f..69b05190 100644 --- a/subpackages.py +++ b/subpackages.py @@ -32,10 +32,11 @@ SUBPACKAGES = { prefix / "bin", prefix / "lib" / "systemd", prefix / "share", - site_packages / "ahriman", + site_packages, ], "ahriman-triggers": [ prefix / "share" / "ahriman" / "settings" / "ahriman.ini.d" / "00-triggers.ini", + site_packages / "ahriman" / "application" / "handlers" / "triggers_support.py", site_packages / "ahriman" / "core" / "distributed", site_packages / "ahriman" / "core" / "support", ], diff --git a/tests/ahriman/application/handlers/test_handler_triggers_support.py b/tests/ahriman/application/handlers/test_handler_triggers_support.py new file mode 100644 index 00000000..85115d23 --- /dev/null +++ b/tests/ahriman/application/handlers/test_handler_triggers_support.py @@ -0,0 +1 @@ +# nothing to test here