print configuration paths in dump command

This commit is contained in:
Evgenii Alekseev 2023-06-11 15:11:34 +03:00
parent 2922bb9d72
commit 10100b20e1
6 changed files with 96 additions and 4 deletions

View File

@ -21,7 +21,7 @@ import argparse
from ahriman.application.handlers import Handler from ahriman.application.handlers import Handler
from ahriman.core.configuration import Configuration from ahriman.core.configuration import Configuration
from ahriman.core.formatters import ConfigurationPrinter from ahriman.core.formatters import ConfigurationPathsPrinter, ConfigurationPrinter, StringPrinter
class Dump(Handler): class Dump(Handler):
@ -44,6 +44,12 @@ class Dump(Handler):
report(bool): force enable or disable reporting report(bool): force enable or disable reporting
unsafe(bool): if set no user check will be performed before path creation unsafe(bool): if set no user check will be performed before path creation
""" """
root, _ = configuration.check_loaded()
ConfigurationPathsPrinter(root, configuration.includes).print(verbose=True, separator=" = ")
# empty line
StringPrinter("").print(verbose=False)
dump = configuration.dump() dump = configuration.dump()
for section, values in sorted(dump.items()): for section, values in sorted(dump.items()):
ConfigurationPrinter(section, values).print(verbose=not args.secure, separator=" = ") ConfigurationPrinter(section, values).print(verbose=not args.secure, separator=" = ")

View File

@ -38,6 +38,7 @@ class Configuration(configparser.RawConfigParser):
Required by dump and merging functions Required by dump and merging functions
SYSTEM_CONFIGURATION_PATH(Path): (class attribute) default system configuration path distributed by package SYSTEM_CONFIGURATION_PATH(Path): (class attribute) default system configuration path distributed by package
architecture(str | None): repository architecture architecture(str | None): repository architecture
includes(list[Path]): list of includes which were read
path(Path | None): path to root configuration file path(Path | None): path to root configuration file
Examples: Examples:
@ -78,6 +79,7 @@ class Configuration(configparser.RawConfigParser):
}) })
self.architecture: str | None = None self.architecture: str | None = None
self.path: Path | None = None self.path: Path | None = None
self.includes: list[Path] = []
@property @property
def include(self) -> Path: def include(self) -> Path:
@ -193,7 +195,7 @@ class Configuration(configparser.RawConfigParser):
} }
# pylint and mypy are too stupid to find these methods # pylint and mypy are too stupid to find these methods
# pylint: disable=missing-function-docstring,multiple-statements,unused-argument # pylint: disable=missing-function-docstring,unused-argument
def getlist(self, *args: Any, **kwargs: Any) -> list[str]: ... # type: ignore[empty-body] def getlist(self, *args: Any, **kwargs: Any) -> list[str]: ... # type: ignore[empty-body]
def getpath(self, *args: Any, **kwargs: Any) -> Path: ... # type: ignore[empty-body] def getpath(self, *args: Any, **kwargs: Any) -> Path: ... # type: ignore[empty-body]
@ -243,11 +245,13 @@ class Configuration(configparser.RawConfigParser):
""" """
load configuration includes load configuration includes
""" """
self.includes = [] # reset state
try: try:
for path in sorted(self.include.glob("*.ini")): for path in sorted(self.include.glob("*.ini")):
if path == self.logging_path: if path == self.logging_path:
continue # we don't want to load logging explicitly continue # we don't want to load logging explicitly
self.read(path) self.read(path)
self.includes.append(path)
except (FileNotFoundError, configparser.NoOptionError, configparser.NoSectionError): except (FileNotFoundError, configparser.NoOptionError, configparser.NoSectionError):
pass pass

View File

@ -22,6 +22,7 @@ from ahriman.core.formatters.string_printer import StringPrinter
from ahriman.core.formatters.aur_printer import AurPrinter from ahriman.core.formatters.aur_printer import AurPrinter
from ahriman.core.formatters.build_printer import BuildPrinter from ahriman.core.formatters.build_printer import BuildPrinter
from ahriman.core.formatters.configuration_paths_printer import ConfigurationPathsPrinter
from ahriman.core.formatters.configuration_printer import ConfigurationPrinter from ahriman.core.formatters.configuration_printer import ConfigurationPrinter
from ahriman.core.formatters.package_printer import PackagePrinter from ahriman.core.formatters.package_printer import PackagePrinter
from ahriman.core.formatters.patch_printer import PatchPrinter from ahriman.core.formatters.patch_printer import PatchPrinter

View File

@ -0,0 +1,52 @@
#
# Copyright (c) 2021-2023 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/>.
#
from pathlib import Path
from ahriman.core.formatters import StringPrinter
from ahriman.models.property import Property
class ConfigurationPathsPrinter(StringPrinter):
"""
print configuration paths
Attributes:
includes(list[Path]): list of include files
"""
def __init__(self, root: Path, includes: list[Path]) -> None:
"""
default constructor
Args:
root(Path): path to root configuration file
includes(list[Path]): list of include files
"""
StringPrinter.__init__(self, str(root))
self.includes = includes
def properties(self) -> list[Property]:
"""
convert content into printable data
Returns:
list[Property]: list of content properties
"""
return [Property("Include", str(path), is_required=True) for path in self.includes]

View File

@ -1,7 +1,10 @@
import pytest import pytest
from ahriman.core.formatters import AurPrinter, ConfigurationPrinter, PackagePrinter, PatchPrinter, StatusPrinter, \ from pathlib import Path
StringPrinter, TreePrinter, UpdatePrinter, UserPrinter, ValidationPrinter, VersionPrinter
from ahriman.core.formatters import AurPrinter, ConfigurationPrinter, ConfigurationPathsPrinter, PackagePrinter,\
PatchPrinter, StatusPrinter, StringPrinter, TreePrinter, UpdatePrinter, UserPrinter, ValidationPrinter, \
VersionPrinter
from ahriman.models.aur_package import AURPackage from ahriman.models.aur_package import AURPackage
from ahriman.models.build_status import BuildStatus from ahriman.models.build_status import BuildStatus
from ahriman.models.package import Package from ahriman.models.package import Package
@ -23,6 +26,17 @@ def aur_package_ahriman_printer(aur_package_ahriman: AURPackage) -> AurPrinter:
return AurPrinter(aur_package_ahriman) return AurPrinter(aur_package_ahriman)
@pytest.fixture
def configuration_paths_printer() -> ConfigurationPathsPrinter:
"""
fixture for configuration paths printer
Returns:
ConfigurationPathsPrinter: configuration paths printer test instance
"""
return ConfigurationPathsPrinter(Path("root"), [Path("include1"), Path("include2")])
@pytest.fixture @pytest.fixture
def configuration_printer() -> ConfigurationPrinter: def configuration_printer() -> ConfigurationPrinter:
""" """

View File

@ -0,0 +1,15 @@
from ahriman.core.formatters import ConfigurationPathsPrinter
def test_properties(configuration_paths_printer: ConfigurationPathsPrinter) -> None:
"""
must return non-empty properties list
"""
assert configuration_paths_printer.properties()
def test_title(configuration_paths_printer: ConfigurationPathsPrinter) -> None:
"""
must return non-empty title
"""
assert configuration_paths_printer.title() is not None