from typing import Mapping, List from . import alpine_linux, arch_linux, crates_io, debian, homebrew, ubuntu from .base import Repository, slug, Version __all__ = [ 'get_versions', ] def repos_from(module): for exported in module.__all__: attr = getattr(module, exported) if isinstance(attr, Repository): yield attr all_repos: List[Repository] = [ *repos_from(alpine_linux), *repos_from(arch_linux), *repos_from(crates_io), *repos_from(debian), *repos_from(homebrew), *repos_from(ubuntu), ] def update_versions(): for repo in all_repos: repo.update() 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 result = dict() for repo in all_repos: if slug(repo.full_name()) in special_cases: package_here = special_cases[slug(repo.full_name())] elif slug(repo.family) in special_cases: package_here = special_cases[slug(repo.family)] elif slug(repo.repo) in special_cases: package_here = special_cases[slug(repo.repo)] else: package_here = package repo_version = repo.get_version(package_here) if repo_version is not None: result[repo] = repo_version return result