mirror of
				https://github.com/arcan1s/ahriman.git
				synced 2025-10-30 21:33:43 +00:00 
			
		
		
		
	replace no-log with quiet
Also behavior of the flag has been changed: now it disables logs at all
This commit is contained in:
		| @ -52,8 +52,8 @@ def _parser() -> argparse.ArgumentParser: | ||||
|         help="lock file", | ||||
|         type=Path, | ||||
|         default=Path(tempfile.gettempdir()) / "ahriman.lock") | ||||
|     parser.add_argument("--no-log", help="redirect all log messages to stderr", action="store_true") | ||||
|     parser.add_argument("--no-report", help="force disable reporting to web service", action="store_true") | ||||
|     parser.add_argument("-q", "--quiet", help="force disable any logging", action="store_true") | ||||
|     parser.add_argument("--unsafe", help="allow to run ahriman as non-ahriman user", action="store_true") | ||||
|     parser.add_argument("-v", "--version", action="version", version=version.__version__) | ||||
|  | ||||
| @ -127,7 +127,7 @@ def _set_clean_parser(root: SubParserAction) -> argparse.ArgumentParser: | ||||
|     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, no_log=True, unsafe=True) | ||||
|     parser.set_defaults(handler=handlers.Clean, quiet=True, unsafe=True) | ||||
|     return parser | ||||
|  | ||||
|  | ||||
| @ -140,7 +140,7 @@ def _set_config_parser(root: SubParserAction) -> argparse.ArgumentParser: | ||||
|     parser = root.add_parser("config", help="dump configuration", | ||||
|                              description="dump configuration for specified architecture", | ||||
|                              formatter_class=argparse.ArgumentDefaultsHelpFormatter) | ||||
|     parser.set_defaults(handler=handlers.Dump, lock=None, no_log=True, no_report=True, unsafe=True) | ||||
|     parser.set_defaults(handler=handlers.Dump, lock=None, quiet=True, no_report=True, unsafe=True) | ||||
|     return parser | ||||
|  | ||||
|  | ||||
| @ -233,7 +233,7 @@ def _set_search_parser(root: SubParserAction) -> argparse.ArgumentParser: | ||||
|     """ | ||||
|     parser = root.add_parser("search", help="search for package", description="search for package in AUR using API") | ||||
|     parser.add_argument("search", help="search terms, can be specified multiple times", nargs="+") | ||||
|     parser.set_defaults(handler=handlers.Search, architecture=[""], lock=None, no_log=True, no_report=True, unsafe=True) | ||||
|     parser.set_defaults(handler=handlers.Search, architecture=[""], lock=None, quiet=True, no_report=True, unsafe=True) | ||||
|     return parser | ||||
|  | ||||
|  | ||||
| @ -256,7 +256,7 @@ def _set_setup_parser(root: SubParserAction) -> argparse.ArgumentParser: | ||||
|     parser.add_argument("--sign-target", help="sign options", type=SignSettings.from_option, | ||||
|                         choices=SignSettings, action="append") | ||||
|     parser.add_argument("--web-port", help="port of the web service", type=int) | ||||
|     parser.set_defaults(handler=handlers.Setup, lock=None, no_log=True, no_report=True, unsafe=True) | ||||
|     parser.set_defaults(handler=handlers.Setup, lock=None, quiet=True, no_report=True, unsafe=True) | ||||
|     return parser | ||||
|  | ||||
|  | ||||
| @ -284,7 +284,7 @@ def _set_status_parser(root: SubParserAction) -> argparse.ArgumentParser: | ||||
|     parser.add_argument("--ahriman", help="get service status itself", action="store_true") | ||||
|     parser.add_argument("--status", help="filter packages by status", choices=BuildStatusEnum, type=BuildStatusEnum) | ||||
|     parser.add_argument("package", help="filter status by package base", nargs="*") | ||||
|     parser.set_defaults(handler=handlers.Status, lock=None, no_log=True, no_report=True, unsafe=True) | ||||
|     parser.set_defaults(handler=handlers.Status, lock=None, quiet=True, no_report=True, unsafe=True) | ||||
|     return parser | ||||
|  | ||||
|  | ||||
| @ -303,7 +303,7 @@ def _set_status_update_parser(root: SubParserAction) -> argparse.ArgumentParser: | ||||
|     parser.add_argument("--status", help="new status", choices=BuildStatusEnum, | ||||
|                         type=BuildStatusEnum, default=BuildStatusEnum.Success) | ||||
|     parser.add_argument("--remove", help="remove package status page", action="store_true") | ||||
|     parser.set_defaults(handler=handlers.StatusUpdate, lock=None, no_log=True, no_report=True, unsafe=True) | ||||
|     parser.set_defaults(handler=handlers.StatusUpdate, lock=None, quiet=True, no_report=True, unsafe=True) | ||||
|     return parser | ||||
|  | ||||
|  | ||||
| @ -361,7 +361,7 @@ def _set_user_parser(root: SubParserAction) -> argparse.ArgumentParser: | ||||
|     parser.add_argument("-p", "--password", help="user password") | ||||
|     parser.add_argument("-r", "--remove", help="remove user from configuration", action="store_true") | ||||
|     parser.add_argument("--secure", help="set file permissions to user-only", action="store_true") | ||||
|     parser.set_defaults(handler=handlers.User, architecture=[""], lock=None, no_log=True, no_report=True, unsafe=True) | ||||
|     parser.set_defaults(handler=handlers.User, architecture=[""], lock=None, quiet=True, no_report=True, unsafe=True) | ||||
|     return parser | ||||
|  | ||||
|  | ||||
|  | ||||
| @ -50,7 +50,7 @@ class Handler: | ||||
|         :return: True on success, False otherwise | ||||
|         """ | ||||
|         try: | ||||
|             configuration = Configuration.from_path(args.configuration, architecture, not args.no_log) | ||||
|             configuration = Configuration.from_path(args.configuration, architecture, args.quiet) | ||||
|             with Lock(args, architecture, configuration): | ||||
|                 cls.run(args, architecture, configuration, args.no_report) | ||||
|             return True | ||||
|  | ||||
| @ -70,18 +70,18 @@ class Configuration(configparser.RawConfigParser): | ||||
|         return self.getpath("settings", "logging") | ||||
|  | ||||
|     @classmethod | ||||
|     def from_path(cls: Type[Configuration], path: Path, architecture: str, logfile: bool) -> Configuration: | ||||
|     def from_path(cls: Type[Configuration], path: Path, architecture: str, quiet: bool) -> Configuration: | ||||
|         """ | ||||
|         constructor with full object initialization | ||||
|         :param path: path to root configuration file | ||||
|         :param architecture: repository architecture | ||||
|         :param logfile: use log file to output messages | ||||
|         :param quiet: force disable any log messages | ||||
|         :return: configuration instance | ||||
|         """ | ||||
|         config = cls() | ||||
|         config.load(path) | ||||
|         config.merge_sections(architecture) | ||||
|         config.load_logging(logfile) | ||||
|         config.load_logging(quiet) | ||||
|         return config | ||||
|  | ||||
|     @staticmethod | ||||
| @ -142,27 +142,20 @@ class Configuration(configparser.RawConfigParser): | ||||
|         except (FileNotFoundError, configparser.NoOptionError, configparser.NoSectionError): | ||||
|             pass | ||||
|  | ||||
|     def load_logging(self, logfile: bool) -> None: | ||||
|     def load_logging(self, quiet: bool) -> None: | ||||
|         """ | ||||
|         setup logging settings from configuration | ||||
|         :param logfile: use log file to output messages | ||||
|         :param quiet: force disable any log messages | ||||
|         """ | ||||
|         def file_logger() -> None: | ||||
|             try: | ||||
|                 path = self.logging_path | ||||
|                 fileConfig(path) | ||||
|             except (FileNotFoundError, PermissionError): | ||||
|                 console_logger() | ||||
|                 logging.exception("could not create logfile, fallback to stderr") | ||||
|  | ||||
|         def console_logger() -> None: | ||||
|         try: | ||||
|             path = self.logging_path | ||||
|             fileConfig(path) | ||||
|         except (FileNotFoundError, PermissionError): | ||||
|             logging.basicConfig(filename=None, format=self.DEFAULT_LOG_FORMAT, | ||||
|                                 level=self.DEFAULT_LOG_LEVEL) | ||||
|  | ||||
|         if logfile: | ||||
|             file_logger() | ||||
|         else: | ||||
|             console_logger() | ||||
|             logging.exception("could not create logfile, fallback to stderr") | ||||
|         if quiet: | ||||
|             logging.disable() | ||||
|  | ||||
|     def merge_sections(self, architecture: str) -> None: | ||||
|         """ | ||||
|  | ||||
| @ -14,7 +14,7 @@ def test_call(args: argparse.Namespace, mocker: MockerFixture) -> None: | ||||
|     must call inside lock | ||||
|     """ | ||||
|     args.configuration = Path("") | ||||
|     args.no_log = False | ||||
|     args.quiet = False | ||||
|     mocker.patch("ahriman.application.handlers.Handler.run") | ||||
|     mocker.patch("ahriman.core.configuration.Configuration.from_path") | ||||
|     enter_mock = mocker.patch("ahriman.application.lock.Lock.__enter__") | ||||
|  | ||||
| @ -79,7 +79,7 @@ def test_subparsers_clean(parser: argparse.ArgumentParser) -> None: | ||||
|     clean command must imply unsafe and no-log | ||||
|     """ | ||||
|     args = parser.parse_args(["clean"]) | ||||
|     assert args.no_log | ||||
|     assert args.quiet | ||||
|     assert args.unsafe | ||||
|  | ||||
|  | ||||
| @ -100,7 +100,7 @@ def test_subparsers_config(parser: argparse.ArgumentParser) -> None: | ||||
|     args = parser.parse_args(["-a", "x86_64", "config"]) | ||||
|     assert args.architecture == ["x86_64"] | ||||
|     assert args.lock is None | ||||
|     assert args.no_log | ||||
|     assert args.quiet | ||||
|     assert args.no_report | ||||
|     assert args.unsafe | ||||
|  | ||||
| @ -169,7 +169,7 @@ def test_subparsers_search(parser: argparse.ArgumentParser) -> None: | ||||
|     args = parser.parse_args(["search", "ahriman"]) | ||||
|     assert args.architecture == [""] | ||||
|     assert args.lock is None | ||||
|     assert args.no_log | ||||
|     assert args.quiet | ||||
|     assert args.no_report | ||||
|     assert args.unsafe | ||||
|  | ||||
| @ -190,7 +190,7 @@ def test_subparsers_setup(parser: argparse.ArgumentParser) -> None: | ||||
|                               "--repository", "aur-clone"]) | ||||
|     assert args.architecture == ["x86_64"] | ||||
|     assert args.lock is None | ||||
|     assert args.no_log | ||||
|     assert args.quiet | ||||
|     assert args.no_report | ||||
|     assert args.unsafe | ||||
|  | ||||
| @ -234,7 +234,7 @@ def test_subparsers_status(parser: argparse.ArgumentParser) -> None: | ||||
|     args = parser.parse_args(["-a", "x86_64", "status"]) | ||||
|     assert args.architecture == ["x86_64"] | ||||
|     assert args.lock is None | ||||
|     assert args.no_log | ||||
|     assert args.quiet | ||||
|     assert args.no_report | ||||
|     assert args.unsafe | ||||
|  | ||||
| @ -246,7 +246,7 @@ def test_subparsers_status_update(parser: argparse.ArgumentParser) -> None: | ||||
|     args = parser.parse_args(["-a", "x86_64", "status-update"]) | ||||
|     assert args.architecture == ["x86_64"] | ||||
|     assert args.lock is None | ||||
|     assert args.no_log | ||||
|     assert args.quiet | ||||
|     assert args.no_report | ||||
|     assert args.unsafe | ||||
|  | ||||
| @ -288,7 +288,7 @@ def test_subparsers_user(parser: argparse.ArgumentParser) -> None: | ||||
|     args = parser.parse_args(["user", "username"]) | ||||
|     assert args.architecture == [""] | ||||
|     assert args.lock is None | ||||
|     assert args.no_log | ||||
|     assert args.quiet | ||||
|     assert args.no_report | ||||
|     assert args.unsafe | ||||
|  | ||||
|  | ||||
| @ -90,7 +90,7 @@ def configuration(resource_path_root: Path) -> Configuration: | ||||
|     :return: configuration test instance | ||||
|     """ | ||||
|     path = resource_path_root / "core" / "ahriman.ini" | ||||
|     return Configuration.from_path(path=path, architecture="x86_64", logfile=False) | ||||
|     return Configuration.from_path(path=path, architecture="x86_64", quiet=False) | ||||
|  | ||||
|  | ||||
| @pytest.fixture | ||||
|  | ||||
| @ -148,16 +148,16 @@ def test_load_logging_fallback(configuration: Configuration, mocker: MockerFixtu | ||||
|     must fallback to stderr without errors | ||||
|     """ | ||||
|     mocker.patch("logging.config.fileConfig", side_effect=PermissionError()) | ||||
|     configuration.load_logging(True) | ||||
|     configuration.load_logging(quiet=False) | ||||
|  | ||||
|  | ||||
| def test_load_logging_stderr(configuration: Configuration, mocker: MockerFixture) -> None: | ||||
| def test_load_logging_quiet(configuration: Configuration, mocker: MockerFixture) -> None: | ||||
|     """ | ||||
|     must use stderr if flag set | ||||
|     must disable logging in case if quiet flag set | ||||
|     """ | ||||
|     logging_mock = mocker.patch("logging.config.fileConfig") | ||||
|     configuration.load_logging(False) | ||||
|     logging_mock.assert_not_called() | ||||
|     disable_mock = mocker.patch("logging.disable") | ||||
|     configuration.load_logging(quiet=True) | ||||
|     disable_mock.assert_called_once() | ||||
|  | ||||
|  | ||||
| def test_merge_sections_missing(configuration: Configuration) -> None: | ||||
|  | ||||
| @ -82,3 +82,10 @@ def test_verify_access_write(user: User) -> None: | ||||
|     user.access = UserAccess.Write | ||||
|     assert user.verify_access(UserAccess.Read) | ||||
|     assert user.verify_access(UserAccess.Write) | ||||
|  | ||||
|  | ||||
| def test_repr(user: User) -> None: | ||||
|     """ | ||||
|     must print user without password | ||||
|     """ | ||||
|     assert "pa55w0rd" not in str(user) | ||||
|  | ||||
		Reference in New Issue
	
	Block a user