From 563eda8e7772a49ebe242b65849359db0a077672 Mon Sep 17 00:00:00 2001 From: Melody Horn Date: Mon, 29 Mar 2021 18:52:31 -0600 Subject: flatten repository metastructure --- repos/__init__.py | 8 +++----- repos/base.py | 4 ++-- 2 files changed, 5 insertions(+), 7 deletions(-) (limited to 'repos') diff --git a/repos/__init__.py b/repos/__init__.py index fc81260..ab6aa76 100644 --- a/repos/__init__.py +++ b/repos/__init__.py @@ -1,7 +1,7 @@ from typing import Mapping, List from . import alpine_linux, arch_linux -from .base import Repository +from .base import Repository, Version __all__ = [ 'get_versions', @@ -18,12 +18,10 @@ all_repos: List[Repository] = [ *repos_from(arch_linux), ] -def get_versions(package: str) -> Mapping[str, Mapping[str, str]]: +def get_versions(package: str) -> Mapping[str, Version]: result = dict() for repo in all_repos: repo_versions = repo.get_versions() if package in repo_versions: - if repo.family not in result: - result[repo.family] = dict() - result[repo.family][repo.repo] = repo_versions[package] + result[repo.full_name()] = repo_versions[package] return result diff --git a/repos/base.py b/repos/base.py index 1bd4ae3..c7790c1 100644 --- a/repos/base.py +++ b/repos/base.py @@ -60,7 +60,7 @@ class Repository: index_url: str parse: Callable[[Path], Mapping[str, Version]] - def _full_name(self): + def full_name(self): return f'{self.family} {self.repo}' def _cache_dir(self) -> Path: @@ -88,7 +88,7 @@ class Repository: response = requests.get(self.index_url, headers=headers, stream=True) if response.status_code != requests.codes.not_modified: response.raise_for_status() - print('Re-downloading', self._full_name()) + print('Re-downloading', self.full_name()) with downloaded_file.open('wb') as f: for chunk in response.iter_content(chunk_size=256): f.write(chunk) -- cgit v1.2.3