From 7591c0f54fa3272df0f6b7057f6096bb513e9328 Mon Sep 17 00:00:00 2001 From: Melody Horn Date: Mon, 12 Apr 2021 12:12:16 -0600 Subject: give sections a separate thing --- repos/__init__.py | 4 +-- repos/alpine_linux.py | 13 ++++---- repos/arch_linux.py | 5 +-- repos/base.py | 32 ++++++++++++------ repos/crates_io.py | 1 + repos/debian.py | 27 +++++++++------- repos/homebrew.py | 1 + repos/ubuntu.py | 82 ++++++++++++++++++++++++----------------------- templates/badge.svg.jinja | 4 +-- 9 files changed, 96 insertions(+), 73 deletions(-) diff --git a/repos/__init__.py b/repos/__init__.py index 75f25c3..fbdca5e 100644 --- a/repos/__init__.py +++ b/repos/__init__.py @@ -26,7 +26,7 @@ def update_versions(): for repo in all_repos: repo.update() -def get_versions(package: str, args: Mapping[str, str]) -> Mapping[str, Version]: +def get_versions(package: str, args: Mapping[str, str]) -> Mapping[Repository, Version]: special_cases = dict() for repo, name in args.items(): special_cases[repo] = name @@ -42,5 +42,5 @@ def get_versions(package: str, args: Mapping[str, str]) -> Mapping[str, Version] package_here = package repo_version = repo.get_version(package_here) if repo_version is not None: - result[repo.full_name()] = repo_version + result[repo] = repo_version return result diff --git a/repos/alpine_linux.py b/repos/alpine_linux.py index 7c646cc..2714f48 100644 --- a/repos/alpine_linux.py +++ b/repos/alpine_linux.py @@ -57,17 +57,18 @@ def parse_cached(cached: Path) -> Mapping[str, Version]: apkindex_file = TextIOWrapper(apkindex_file) return parse_apkindex(apkindex_file) -def build_repo(name: str, url_path: str) -> Repository: +def build_repo(name: str, section: str, url_path: str) -> Repository: url = f'http://dl-cdn.alpinelinux.org/alpine/{url_path}/APKINDEX.tar.gz' return Repository( family='Alpine Linux', repo=name, + section=section, index_url=url, parse=parse_cached, ) -stable_main_x86_64 = build_repo('Stable (main/x86_64)', 'latest-stable/main/x86_64') -stable_community_x86_64 = build_repo('Stable (community/x86_64)', 'latest-stable/community/x86_64') -edge_main_x86_64 = build_repo('Edge (main/x86_64)', 'edge/main/x86_64') -edge_community_x86_64 = build_repo('Edge (community/x86_64)', 'edge/community/x86_64') -edge_testing_x86_64 = build_repo('Edge (testing/x86_64)', 'edge/testing/x86_64') +stable_main_x86_64 = build_repo('Stable', 'main/x86_64', 'latest-stable/main/x86_64') +stable_community_x86_64 = build_repo('Stable', 'community/x86_64', 'latest-stable/community/x86_64') +edge_main_x86_64 = build_repo('Edge', 'main/x86_64', 'edge/main/x86_64') +edge_community_x86_64 = build_repo('Edge', 'community/x86_64', 'edge/community/x86_64') +edge_testing_x86_64 = build_repo('Edge', 'testing/x86_64', 'edge/testing/x86_64') diff --git a/repos/arch_linux.py b/repos/arch_linux.py index 52ef557..c535484 100644 --- a/repos/arch_linux.py +++ b/repos/arch_linux.py @@ -55,8 +55,9 @@ def parse_cached(cached: Path) -> Mapping[str, Version]: def build_repo(name: str) -> Repository: url = f'https://mirror.rackspace.com/archlinux/{name}/os/x86_64/{name}.db.tar.gz' return Repository( - family='Arch Linux', - repo=name, + family=None, + repo='Arch Linux', + section=name, index_url=url, parse=parse_cached, ) diff --git a/repos/base.py b/repos/base.py index 1b4c42b..de0e5dc 100644 --- a/repos/base.py +++ b/repos/base.py @@ -58,24 +58,38 @@ class JSONDecoder(json.JSONDecoder): super().__init__(object_hook=self.object_hook) -@dataclass() +@dataclass(frozen=True) class Repository: family: Optional[str] repo: str + section: Optional[str] index_url: str parse: Callable[[Path], Mapping[str, Version]] def full_name(self): - if self.family is None: - return self.repo - else: - return f'{self.family} {self.repo}' + prefix = '' + if self.family is not None: + prefix = self.family + ' ' + suffix = '' + if self.section is not None: + suffix = ' ' + self.section + return f'{prefix}{self.repo}{suffix}' + + @property + def full_repo_name(self): + prefix = '' + if self.family is not None: + prefix = self.family + ' ' + return f'{prefix}{self.repo}' def _cache_dir(self) -> Path: - if self.family is None: - return Path('data') / slug(self.repo) - else: - return Path('data') / slug(self.family) / slug(self.repo) + result = Path('data') + if self.family is not None: + result = result / slug(self.family) + result = result / slug(self.repo) + if self.section is not None: + result = result / slug(self.section) + return result def _cache_file(self, name: str) -> Path: return self._cache_dir() / name diff --git a/repos/crates_io.py b/repos/crates_io.py index 95078e3..42680f0 100644 --- a/repos/crates_io.py +++ b/repos/crates_io.py @@ -42,6 +42,7 @@ def parse_cached(cached: Path) -> Mapping[str, Version]: crates = Repository( family=None, repo='crates.io', + section=None, index_url='https://static.crates.io/db-dump.tar.gz', parse=parse_cached, ) diff --git a/repos/debian.py b/repos/debian.py index db93b2e..44fc3a2 100644 --- a/repos/debian.py +++ b/repos/debian.py @@ -47,23 +47,26 @@ def parse_cached(cached: Path) -> Mapping[str, Version]: def build_repo(name: str, dist: str, section: str, arch: str = 'all') -> Repository: url = f'https://deb.debian.org/debian/dists/{dist}/{section}/binary-{arch}/Packages.gz' + if arch != 'all': + section = f'{section}/{arch}' return Repository( family='Debian', repo=name, + section=section, index_url=url, parse=parse_cached, ) -buster_main_all = build_repo('10 - Buster (main)', 'buster', 'main') -buster_main_amd64 = build_repo('10 - Buster (main/amd64)', 'buster', 'main', 'amd64') -buster_contrib_all = build_repo('10 - Buster (contrib)', 'buster', 'contrib') -buster_contrib_amd64 = build_repo('10 - Buster (contrib/amd64)', 'buster', 'contrib', 'amd64') -buster_non_free_all = build_repo('10 - Buster (non-free)', 'buster', 'non-free') -buster_non_free_amd64 = build_repo('10 - Buster (non-free/amd64)', 'buster', 'non-free', 'amd64') +buster_main_all = build_repo('10 - Buster', 'buster', 'main') +buster_main_amd64 = build_repo('10 - Buster', 'buster', 'main', 'amd64') +buster_contrib_all = build_repo('10 - Buster', 'buster', 'contrib') +buster_contrib_amd64 = build_repo('10 - Buster', 'buster', 'contrib', 'amd64') +buster_non_free_all = build_repo('10 - Buster', 'buster', 'non-free') +buster_non_free_amd64 = build_repo('10 - Buster', 'buster', 'non-free', 'amd64') -testing_main_all = build_repo('Testing (main)', 'testing', 'main') -testing_main_amd64 = build_repo('Testing (main/amd64)', 'testing', 'main', 'amd64') -testing_contrib_all = build_repo('Testing (contrib)', 'testing', 'contrib') -testing_contrib_amd64 = build_repo('Testing (contrib/amd64)', 'testing', 'contrib', 'amd64') -testing_non_free_all = build_repo('Testing (non-free)', 'testing', 'non-free') -testing_non_free_amd64 = build_repo('Testing (non-free/amd64)', 'testing', 'non-free', 'amd64') +testing_main_all = build_repo('Testing', 'testing', 'main') +testing_main_amd64 = build_repo('Testing', 'testing', 'main', 'amd64') +testing_contrib_all = build_repo('Testing', 'testing', 'contrib') +testing_contrib_amd64 = build_repo('Testing', 'testing', 'contrib', 'amd64') +testing_non_free_all = build_repo('Testing', 'testing', 'non-free') +testing_non_free_amd64 = build_repo('Testing', 'testing', 'non-free', 'amd64') diff --git a/repos/homebrew.py b/repos/homebrew.py index 77dc05b..42e2e7c 100644 --- a/repos/homebrew.py +++ b/repos/homebrew.py @@ -42,6 +42,7 @@ def build_repo(name: str, url: str) -> Repository: return Repository( family='Homebrew', repo=name, + section=None, index_url=url, parse=parse_cached, ) diff --git a/repos/ubuntu.py b/repos/ubuntu.py index 8eba45a..7b51ffd 100644 --- a/repos/ubuntu.py +++ b/repos/ubuntu.py @@ -72,51 +72,53 @@ def parse_cached(cached: Path) -> Mapping[str, Version]: this_package = None return result -def build_repo(name: str, dist: str, section: str, arch: str = 'all') -> Repository: +def build_repo(name: str, dist: str, section: str, arch: str) -> Repository: url = f'http://archive.ubuntu.com/ubuntu/dists/{dist}/{section}/binary-{arch}/Packages.gz' + section = f'{section}/{arch}' return Repository( family='Ubuntu', repo=name, + section=section, index_url=url, parse=parse_cached, ) -focal_main_amd64 = build_repo('20.04 Focal (main/amd64)', 'focal', 'main', 'amd64') -focal_restricted_amd64 = build_repo('20.04 Focal (restricted/amd64)', 'focal', 'restricted', 'amd64') -focal_universe_amd64 = build_repo('20.04 Focal (universe/amd64)', 'focal', 'universe', 'amd64') -focal_multiverse_amd64 = build_repo('20.04 Focal (multiverse/amd64)', 'focal', 'multiverse', 'amd64') - -focal_updates_main_amd64 = build_repo('20.04 Focal Updates (main/amd64)', 'focal-updates', 'main', 'amd64') -focal_updates_restricted_amd64 = build_repo('20.04 Focal Updates (restricted/amd64)', 'focal-updates', 'restricted', 'amd64') -focal_updates_universe_amd64 = build_repo('20.04 Focal Updates (universe/amd64)', 'focal-updates', 'universe', 'amd64') -focal_updates_multiverse_amd64 = build_repo('20.04 Focal Updates (multiverse/amd64)', 'focal-updates', 'multiverse', 'amd64') - -focal_backports_main_amd64 = build_repo('20.04 Focal Backports (main/amd64)', 'focal-backports', 'main', 'amd64') -focal_backports_restricted_amd64 = build_repo('20.04 Focal Backports (restricted/amd64)', 'focal-backports', 'restricted', 'amd64') -focal_backports_universe_amd64 = build_repo('20.04 Focal Backports (universe/amd64)', 'focal-backports', 'universe', 'amd64') -focal_backports_multiverse_amd64 = build_repo('20.04 Focal Backports (multiverse/amd64)', 'focal-backports', 'multiverse', 'amd64') - -focal_security_main_amd64 = build_repo('20.04 Focal Security (main/amd64)', 'focal-security', 'main', 'amd64') -focal_security_restricted_amd64 = build_repo('20.04 Focal Security (restricted/amd64)', 'focal-security', 'restricted', 'amd64') -focal_security_universe_amd64 = build_repo('20.04 Focal Security (universe/amd64)', 'focal-security', 'universe', 'amd64') -focal_security_multiverse_amd64 = build_repo('20.04 Focal Security (multiverse/amd64)', 'focal-security', 'multiverse', 'amd64') - -groovy_main_amd64 = build_repo('20.10 Groovy (main/amd64)', 'groovy', 'main', 'amd64') -groovy_restricted_amd64 = build_repo('20.10 Groovy (restricted/amd64)', 'groovy', 'restricted', 'amd64') -groovy_universe_amd64 = build_repo('20.10 Groovy (universe/amd64)', 'groovy', 'universe', 'amd64') -groovy_multiverse_amd64 = build_repo('20.10 Groovy (multiverse/amd64)', 'groovy', 'multiverse', 'amd64') - -groovy_updates_main_amd64 = build_repo('20.10 Groovy Updates (main/amd64)', 'groovy-updates', 'main', 'amd64') -groovy_updates_restricted_amd64 = build_repo('20.10 Groovy Updates (restricted/amd64)', 'groovy-updates', 'restricted', 'amd64') -groovy_updates_universe_amd64 = build_repo('20.10 Groovy Updates (universe/amd64)', 'groovy-updates', 'universe', 'amd64') -groovy_updates_multiverse_amd64 = build_repo('20.10 Groovy Updates (multiverse/amd64)', 'groovy-updates', 'multiverse', 'amd64') - -groovy_backports_main_amd64 = build_repo('20.10 Groovy Backports (main/amd64)', 'groovy-backports', 'main', 'amd64') -groovy_backports_restricted_amd64 = build_repo('20.10 Groovy Backports (restricted/amd64)', 'groovy-backports', 'restricted', 'amd64') -groovy_backports_universe_amd64 = build_repo('20.10 Groovy Backports (universe/amd64)', 'groovy-backports', 'universe', 'amd64') -groovy_backports_multiverse_amd64 = build_repo('20.10 Groovy Backports (multiverse/amd64)', 'groovy-backports', 'multiverse', 'amd64') - -groovy_security_main_amd64 = build_repo('20.10 Groovy Security (main/amd64)', 'groovy-security', 'main', 'amd64') -groovy_security_restricted_amd64 = build_repo('20.10 Groovy Security (restricted/amd64)', 'groovy-security', 'restricted', 'amd64') -groovy_security_universe_amd64 = build_repo('20.10 Groovy Security (universe/amd64)', 'groovy-security', 'universe', 'amd64') -groovy_security_multiverse_amd64 = build_repo('20.10 Groovy Security (multiverse/amd64)', 'groovy-security', 'multiverse', 'amd64') +focal_main_amd64 = build_repo('20.04 Focal', 'focal', 'main', 'amd64') +focal_restricted_amd64 = build_repo('20.04 Focal', 'focal', 'restricted', 'amd64') +focal_universe_amd64 = build_repo('20.04 Focal', 'focal', 'universe', 'amd64') +focal_multiverse_amd64 = build_repo('20.04 Focal', 'focal', 'multiverse', 'amd64') + +focal_updates_main_amd64 = build_repo('20.04 Focal Updates', 'focal-updates', 'main', 'amd64') +focal_updates_restricted_amd64 = build_repo('20.04 Focal Updates', 'focal-updates', 'restricted', 'amd64') +focal_updates_universe_amd64 = build_repo('20.04 Focal Updates', 'focal-updates', 'universe', 'amd64') +focal_updates_multiverse_amd64 = build_repo('20.04 Focal Updates', 'focal-updates', 'multiverse', 'amd64') + +focal_backports_main_amd64 = build_repo('20.04 Focal Backports', 'focal-backports', 'main', 'amd64') +focal_backports_restricted_amd64 = build_repo('20.04 Focal Backports', 'focal-backports', 'restricted', 'amd64') +focal_backports_universe_amd64 = build_repo('20.04 Focal Backports', 'focal-backports', 'universe', 'amd64') +focal_backports_multiverse_amd64 = build_repo('20.04 Focal Backports', 'focal-backports', 'multiverse', 'amd64') + +focal_security_main_amd64 = build_repo('20.04 Focal Security', 'focal-security', 'main', 'amd64') +focal_security_restricted_amd64 = build_repo('20.04 Focal Security', 'focal-security', 'restricted', 'amd64') +focal_security_universe_amd64 = build_repo('20.04 Focal Security', 'focal-security', 'universe', 'amd64') +focal_security_multiverse_amd64 = build_repo('20.04 Focal Security', 'focal-security', 'multiverse', 'amd64') + +groovy_main_amd64 = build_repo('20.10 Groovy', 'groovy', 'main', 'amd64') +groovy_restricted_amd64 = build_repo('20.10 Groovy', 'groovy', 'restricted', 'amd64') +groovy_universe_amd64 = build_repo('20.10 Groovy', 'groovy', 'universe', 'amd64') +groovy_multiverse_amd64 = build_repo('20.10 Groovy', 'groovy', 'multiverse', 'amd64') + +groovy_updates_main_amd64 = build_repo('20.10 Groovy Updates', 'groovy-updates', 'main', 'amd64') +groovy_updates_restricted_amd64 = build_repo('20.10 Groovy Updates', 'groovy-updates', 'restricted', 'amd64') +groovy_updates_universe_amd64 = build_repo('20.10 Groovy Updates', 'groovy-updates', 'universe', 'amd64') +groovy_updates_multiverse_amd64 = build_repo('20.10 Groovy Updates', 'groovy-updates', 'multiverse', 'amd64') + +groovy_backports_main_amd64 = build_repo('20.10 Groovy Backports', 'groovy-backports', 'main', 'amd64') +groovy_backports_restricted_amd64 = build_repo('20.10 Groovy Backports', 'groovy-backports', 'restricted', 'amd64') +groovy_backports_universe_amd64 = build_repo('20.10 Groovy Backports', 'groovy-backports', 'universe', 'amd64') +groovy_backports_multiverse_amd64 = build_repo('20.10 Groovy Backports', 'groovy-backports', 'multiverse', 'amd64') + +groovy_security_main_amd64 = build_repo('20.10 Groovy Security', 'groovy-security', 'main', 'amd64') +groovy_security_restricted_amd64 = build_repo('20.10 Groovy Security', 'groovy-security', 'restricted', 'amd64') +groovy_security_universe_amd64 = build_repo('20.10 Groovy Security', 'groovy-security', 'universe', 'amd64') +groovy_security_multiverse_amd64 = build_repo('20.10 Groovy Security', 'groovy-security', 'multiverse', 'amd64') diff --git a/templates/badge.svg.jinja b/templates/badge.svg.jinja index 8143cff..02ba3db 100644 --- a/templates/badge.svg.jinja +++ b/templates/badge.svg.jinja @@ -5,7 +5,7 @@ {%- set ROWS = 1 + versions|length -%} {%- set OUTER_MARGIN = 5 -%} {%- set FONT_WIDENESS = 0.5 -%} -{%- set LONGEST_REPO = versions.keys()|map('length')|max -%} +{%- set LONGEST_REPO = versions.keys()|map(attribute='full_repo_name')|map('length')|max -%} {%- set LONGEST_VERSION = versions.values()|map('string')|map('length')|max -%} {%- set VERSION_X = OUTER_MARGIN + LONGEST_REPO * FONT_WIDENESS * FONT_SIZE -%} {%- set VERSION_WIDTH = OUTER_MARGIN + LONGEST_VERSION * FONT_WIDENESS * FONT_SIZE -%} @@ -21,7 +21,7 @@ {{ end_row() }} {% for repo, version in versions.items() %} - {{ repo }} + {{ repo.full_repo_name }} {{ version }}{{ end_row() }} -- cgit v1.2.3