replace no-log with quiet

Also behavior of the flag has been changed: now it disables logs at all
This commit is contained in:
2021-10-03 01:59:23 +03:00
parent db195391e4
commit 6becd01803
8 changed files with 43 additions and 43 deletions

View File

@ -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

View File

@ -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

View File

@ -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:
"""