mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-04-24 07:17:17 +00:00
print configuration paths in dump command
This commit is contained in:
parent
09839f755a
commit
a1c12200b8
@ -21,7 +21,7 @@ import argparse
|
||||
|
||||
from ahriman.application.handlers import Handler
|
||||
from ahriman.core.configuration import Configuration
|
||||
from ahriman.core.formatters import ConfigurationPrinter
|
||||
from ahriman.core.formatters import ConfigurationPathsPrinter, ConfigurationPrinter, StringPrinter
|
||||
|
||||
|
||||
class Dump(Handler):
|
||||
@ -44,6 +44,12 @@ class Dump(Handler):
|
||||
report(bool): force enable or disable reporting
|
||||
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()
|
||||
for section, values in sorted(dump.items()):
|
||||
ConfigurationPrinter(section, values).print(verbose=not args.secure, separator=" = ")
|
||||
|
@ -38,6 +38,7 @@ class Configuration(configparser.RawConfigParser):
|
||||
Required by dump and merging functions
|
||||
SYSTEM_CONFIGURATION_PATH(Path): (class attribute) default system configuration path distributed by package
|
||||
architecture(str | None): repository architecture
|
||||
includes(list[Path]): list of includes which were read
|
||||
path(Path | None): path to root configuration file
|
||||
|
||||
Examples:
|
||||
@ -78,6 +79,7 @@ class Configuration(configparser.RawConfigParser):
|
||||
})
|
||||
self.architecture: str | None = None
|
||||
self.path: Path | None = None
|
||||
self.includes: list[Path] = []
|
||||
|
||||
@property
|
||||
def include(self) -> Path:
|
||||
@ -193,7 +195,7 @@ class Configuration(configparser.RawConfigParser):
|
||||
}
|
||||
|
||||
# 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 getpath(self, *args: Any, **kwargs: Any) -> Path: ... # type: ignore[empty-body]
|
||||
@ -243,11 +245,13 @@ class Configuration(configparser.RawConfigParser):
|
||||
"""
|
||||
load configuration includes
|
||||
"""
|
||||
self.includes = [] # reset state
|
||||
try:
|
||||
for path in sorted(self.include.glob("*.ini")):
|
||||
if path == self.logging_path:
|
||||
continue # we don't want to load logging explicitly
|
||||
self.read(path)
|
||||
self.includes.append(path)
|
||||
except (FileNotFoundError, configparser.NoOptionError, configparser.NoSectionError):
|
||||
pass
|
||||
|
||||
|
@ -22,6 +22,7 @@ from ahriman.core.formatters.string_printer import StringPrinter
|
||||
|
||||
from ahriman.core.formatters.aur_printer import AurPrinter
|
||||
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.package_printer import PackagePrinter
|
||||
from ahriman.core.formatters.patch_printer import PatchPrinter
|
||||
|
52
src/ahriman/core/formatters/configuration_paths_printer.py
Normal file
52
src/ahriman/core/formatters/configuration_paths_printer.py
Normal 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]
|
@ -1,7 +1,10 @@
|
||||
import pytest
|
||||
|
||||
from ahriman.core.formatters import AurPrinter, ConfigurationPrinter, PackagePrinter, PatchPrinter, StatusPrinter, \
|
||||
StringPrinter, TreePrinter, UpdatePrinter, UserPrinter, ValidationPrinter, VersionPrinter
|
||||
from pathlib import Path
|
||||
|
||||
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.build_status import BuildStatus
|
||||
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)
|
||||
|
||||
|
||||
@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
|
||||
def configuration_printer() -> ConfigurationPrinter:
|
||||
"""
|
||||
|
@ -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
|
Loading…
Reference in New Issue
Block a user