1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
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
|