mirror of
				https://github.com/arcan1s/ahriman.git
				synced 2025-10-31 13:53:41 +00:00 
			
		
		
		
	add init subcommand
This commit is contained in:
		| @ -56,6 +56,7 @@ def _parser() -> argparse.ArgumentParser: | ||||
|     _set_check_parser(subparsers) | ||||
|     _set_clean_parser(subparsers) | ||||
|     _set_config_parser(subparsers) | ||||
|     _set_init_parser(subparsers) | ||||
|     _set_key_import_parser(subparsers) | ||||
|     _set_rebuild_parser(subparsers) | ||||
|     _set_remove_parser(subparsers) | ||||
| @ -132,6 +133,19 @@ def _set_config_parser(root: SubParserAction) -> argparse.ArgumentParser: | ||||
|     return parser | ||||
|  | ||||
|  | ||||
| def _set_init_parser(root: SubParserAction) -> argparse.ArgumentParser: | ||||
|     """ | ||||
|     add parser for init subcommand | ||||
|     :param root: subparsers for the commands | ||||
|     :return: created argument parser | ||||
|     """ | ||||
|     parser = root.add_parser("init", help="create repository tree", | ||||
|                              description="create empty repository tree. Optional command for auto architecture support", | ||||
|                              formatter_class=argparse.ArgumentDefaultsHelpFormatter) | ||||
|     parser.set_defaults(handler=handlers.Init, no_report=True) | ||||
|     return parser | ||||
|  | ||||
|  | ||||
| def _set_key_import_parser(root: SubParserAction) -> argparse.ArgumentParser: | ||||
|     """ | ||||
|     add parser for key import subcommand | ||||
|  | ||||
| @ -22,6 +22,7 @@ from ahriman.application.handlers.handler import Handler | ||||
| from ahriman.application.handlers.add import Add | ||||
| from ahriman.application.handlers.clean import Clean | ||||
| from ahriman.application.handlers.dump import Dump | ||||
| from ahriman.application.handlers.init import Init | ||||
| from ahriman.application.handlers.key_import import KeyImport | ||||
| from ahriman.application.handlers.rebuild import Rebuild | ||||
| from ahriman.application.handlers.remove import Remove | ||||
|  | ||||
							
								
								
									
										42
									
								
								src/ahriman/application/handlers/init.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										42
									
								
								src/ahriman/application/handlers/init.py
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,42 @@ | ||||
| # | ||||
| # 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 | ||||
|  | ||||
|  | ||||
| class Init(Handler): | ||||
|     """ | ||||
|     repository init handler | ||||
|     """ | ||||
|  | ||||
|     @classmethod | ||||
|     def run(cls: Type[Handler], args: argparse.Namespace, architecture: str, configuration: Configuration) -> None: | ||||
|         """ | ||||
|         callback for command line | ||||
|         :param args: command line args | ||||
|         :param architecture: repository architecture | ||||
|         :param configuration: configuration instance | ||||
|         """ | ||||
|         Application(architecture, configuration) | ||||
							
								
								
									
										16
									
								
								tests/ahriman/application/handlers/test_handler_init.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								tests/ahriman/application/handlers/test_handler_init.py
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,16 @@ | ||||
| import argparse | ||||
|  | ||||
| from pytest_mock import MockerFixture | ||||
|  | ||||
| from ahriman.application.handlers import Init | ||||
| from ahriman.core.configuration import Configuration | ||||
|  | ||||
|  | ||||
| def test_run(args: argparse.Namespace, configuration: Configuration, mocker: MockerFixture) -> None: | ||||
|     """ | ||||
|     must run command | ||||
|     """ | ||||
|     create_tree_mock = mocker.patch("ahriman.models.repository_paths.RepositoryPaths.create_tree") | ||||
|  | ||||
|     Init.run(args, "x86_64", configuration) | ||||
|     create_tree_mock.assert_called_once() | ||||
| @ -73,6 +73,14 @@ def test_subparsers_config(parser: argparse.ArgumentParser) -> None: | ||||
|     assert args.unsafe | ||||
|  | ||||
|  | ||||
| def test_subparsers_init(parser: argparse.ArgumentParser) -> None: | ||||
|     """ | ||||
|     init command must imply no_report | ||||
|     """ | ||||
|     args = parser.parse_args(["-a", "x86_64", "init"]) | ||||
|     assert args.no_report | ||||
|  | ||||
|  | ||||
| def test_subparsers_key_import(parser: argparse.ArgumentParser) -> None: | ||||
|     """ | ||||
|     key-import command must imply lock and no_report | ||||
|  | ||||
| @ -8,7 +8,7 @@ from ahriman.models.package import Package | ||||
|  | ||||
| async def test_get(client: TestClient, package_ahriman: Package) -> None: | ||||
|     """ | ||||
|     must generate web service status correctly) | ||||
|     must generate web service status correctly | ||||
|     """ | ||||
|     await client.post(f"/api/v1/packages/{package_ahriman.base}", | ||||
|                       json={"status": BuildStatusEnum.Success.value, "package": package_ahriman.view()}) | ||||
|  | ||||
		Reference in New Issue
	
	Block a user