mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-04-28 01:07:18 +00:00
feat: read old web sections
This commit is contained in:
parent
b18000c777
commit
eec94521a7
@ -63,6 +63,7 @@ class Configuration(configparser.RawConfigParser):
|
|||||||
>>> path, repository_id = configuration.check_loaded()
|
>>> path, repository_id = configuration.check_loaded()
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
_LEGACY_ARCHITECTURE_SPECIFIC_SECTIONS = ["web"]
|
||||||
ARCHITECTURE_SPECIFIC_SECTIONS = ["alpm", "build", "sign"]
|
ARCHITECTURE_SPECIFIC_SECTIONS = ["alpm", "build", "sign"]
|
||||||
SYSTEM_CONFIGURATION_PATH = Path(sys.prefix) / "share" / "ahriman" / "settings" / "ahriman.ini"
|
SYSTEM_CONFIGURATION_PATH = Path(sys.prefix) / "share" / "ahriman" / "settings" / "ahriman.ini"
|
||||||
converters: dict[str, Callable[[str], Any]] # typing guard
|
converters: dict[str, Callable[[str], Any]] # typing guard
|
||||||
@ -160,25 +161,6 @@ class Configuration(configparser.RawConfigParser):
|
|||||||
configuration.merge_sections(repository_id)
|
configuration.merge_sections(repository_id)
|
||||||
return configuration
|
return configuration
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def override_sections(section: str, repository_id: RepositoryId) -> list[str]:
|
|
||||||
"""
|
|
||||||
extract override sections
|
|
||||||
|
|
||||||
Args:
|
|
||||||
section(str): section name
|
|
||||||
repository_id(RepositoryId): repository unique identifier
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
list[str]: architecture and repository specific sections in correct order
|
|
||||||
"""
|
|
||||||
# the valid order is global < per architecture < per repository < per repository and architecture
|
|
||||||
return [
|
|
||||||
Configuration.section_name(section, repository_id.architecture), # architecture specific override
|
|
||||||
Configuration.section_name(section, repository_id.name), # override with repository name
|
|
||||||
Configuration.section_name(section, repository_id.name, repository_id.architecture), # both
|
|
||||||
]
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def section_name(section: str, *suffixes: str | None) -> str:
|
def section_name(section: str, *suffixes: str | None) -> str:
|
||||||
"""
|
"""
|
||||||
@ -315,7 +297,7 @@ class Configuration(configparser.RawConfigParser):
|
|||||||
"""
|
"""
|
||||||
self.repository_id = repository_id
|
self.repository_id = repository_id
|
||||||
|
|
||||||
for section in self.ARCHITECTURE_SPECIFIC_SECTIONS:
|
for section in self.ARCHITECTURE_SPECIFIC_SECTIONS + self._LEGACY_ARCHITECTURE_SPECIFIC_SECTIONS:
|
||||||
for specific in self.override_sections(section, repository_id):
|
for specific in self.override_sections(section, repository_id):
|
||||||
if self.has_section(specific):
|
if self.has_section(specific):
|
||||||
# if there is no such section it means that there is no overrides for this arch,
|
# if there is no such section it means that there is no overrides for this arch,
|
||||||
@ -330,6 +312,26 @@ class Configuration(configparser.RawConfigParser):
|
|||||||
continue
|
continue
|
||||||
self.remove_section(foreign)
|
self.remove_section(foreign)
|
||||||
|
|
||||||
|
def override_sections(self, section: str, repository_id: RepositoryId) -> list[str]:
|
||||||
|
"""
|
||||||
|
extract override sections
|
||||||
|
|
||||||
|
Args:
|
||||||
|
section(str): section name
|
||||||
|
repository_id(RepositoryId): repository unique identifier
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
list[str]: architecture and repository specific sections in correct order
|
||||||
|
"""
|
||||||
|
if repository_id.is_empty: # special case, guess sections from configuration
|
||||||
|
return sorted(specific for specific in self.sections() if specific.startswith(f"{section}:"))
|
||||||
|
# the valid order is global < per architecture < per repository < per repository and architecture
|
||||||
|
return [
|
||||||
|
Configuration.section_name(section, repository_id.architecture), # architecture specific override
|
||||||
|
Configuration.section_name(section, repository_id.name), # override with repository name
|
||||||
|
Configuration.section_name(section, repository_id.name, repository_id.architecture), # both
|
||||||
|
]
|
||||||
|
|
||||||
def reload(self) -> None:
|
def reload(self) -> None:
|
||||||
"""
|
"""
|
||||||
reload configuration if possible or raise exception otherwise
|
reload configuration if possible or raise exception otherwise
|
||||||
|
@ -61,17 +61,6 @@ def test_from_path_file_missing(repository_id: RepositoryId, mocker: MockerFixtu
|
|||||||
read_mock.assert_called_once_with(configuration.SYSTEM_CONFIGURATION_PATH)
|
read_mock.assert_called_once_with(configuration.SYSTEM_CONFIGURATION_PATH)
|
||||||
|
|
||||||
|
|
||||||
def test_override_sections(repository_id: RepositoryId) -> None:
|
|
||||||
"""
|
|
||||||
must correctly generate override section names
|
|
||||||
"""
|
|
||||||
assert Configuration.override_sections("build", repository_id) == [
|
|
||||||
"build:x86_64",
|
|
||||||
"build:aur-clone",
|
|
||||||
"build:aur-clone:x86_64",
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
def test_section_name(configuration: Configuration) -> None:
|
def test_section_name(configuration: Configuration) -> None:
|
||||||
"""
|
"""
|
||||||
must return architecture specific group
|
must return architecture specific group
|
||||||
@ -384,6 +373,26 @@ def test_merge_sections_priority(configuration: Configuration) -> None:
|
|||||||
assert configuration.get("build", "key4") == "key4_value1"
|
assert configuration.get("build", "key4") == "key4_value1"
|
||||||
|
|
||||||
|
|
||||||
|
def test_override_sections(configuration: Configuration, repository_id: RepositoryId) -> None:
|
||||||
|
"""
|
||||||
|
must correctly generate override section names
|
||||||
|
"""
|
||||||
|
assert configuration.override_sections("build", repository_id) == [
|
||||||
|
"build:x86_64",
|
||||||
|
"build:aur-clone",
|
||||||
|
"build:aur-clone:x86_64",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def test_override_sections_empty(configuration: Configuration) -> None:
|
||||||
|
"""
|
||||||
|
must look up for sections if repository identifier is empty
|
||||||
|
"""
|
||||||
|
configuration.set_option("web:x86_64", "port", "8080")
|
||||||
|
configuration.set_option("web:i686", "port", "8080")
|
||||||
|
assert configuration.override_sections("web", RepositoryId("", "")) == ["web:i686", "web:x86_64"]
|
||||||
|
|
||||||
|
|
||||||
def test_reload(configuration: Configuration, mocker: MockerFixture) -> None:
|
def test_reload(configuration: Configuration, mocker: MockerFixture) -> None:
|
||||||
"""
|
"""
|
||||||
must reload configuration
|
must reload configuration
|
||||||
|
Loading…
Reference in New Issue
Block a user