diff options
author | Melody Horn <melody@boringcactus.com> | 2021-03-29 19:24:55 -0600 |
---|---|---|
committer | Melody Horn <melody@boringcactus.com> | 2021-03-29 19:24:55 -0600 |
commit | 768aa24eeb1c9606fa214bf0aa57315814c04f5e (patch) | |
tree | d2543e5ff1a55ca56e667b9c6c5837d7d6e2d7f9 /repos | |
parent | 588c46173e28abb50d7b176ff09b383e0b7b0a09 (diff) | |
download | where-packaged-768aa24eeb1c9606fa214bf0aa57315814c04f5e.tar.gz where-packaged-768aa24eeb1c9606fa214bf0aa57315814c04f5e.zip |
homebrew time
Diffstat (limited to 'repos')
-rw-r--r-- | repos/__init__.py | 3 | ||||
-rw-r--r-- | repos/homebrew.py | 51 |
2 files changed, 53 insertions, 1 deletions
diff --git a/repos/__init__.py b/repos/__init__.py index c836861..005dcf8 100644 --- a/repos/__init__.py +++ b/repos/__init__.py @@ -1,6 +1,6 @@ from typing import Mapping, List -from . import alpine_linux, arch_linux, crates_io +from . import alpine_linux, arch_linux, crates_io, homebrew from .base import Repository, slug, Version __all__ = [ @@ -17,6 +17,7 @@ all_repos: List[Repository] = [ *repos_from(alpine_linux), *repos_from(arch_linux), *repos_from(crates_io), + *repos_from(homebrew), ] def get_versions(package: str, args: Mapping[str, str]) -> Mapping[str, Version]: diff --git a/repos/homebrew.py b/repos/homebrew.py new file mode 100644 index 0000000..77dc05b --- /dev/null +++ b/repos/homebrew.py @@ -0,0 +1,51 @@ +import json +from pathlib import Path +from typing import Mapping + +from .base import Repository, Version + +__all__ = [ + 'core', + 'linux', + 'cask', +] + +def parse_cached(cached: Path) -> Mapping[str, Version]: + with cached.open('r') as json_file: + formulae = json.load(json_file) + result = dict() + for formula in formulae: + if 'full_name' in formula: + name = formula['full_name'] + elif 'full_token' in formula: + name = formula['full_token'] + else: + print('no name', formula) + raise ValueError() + if 'version' in formula: + version = formula['version'] + elif 'versions' in formula: + versions = formula['versions'] + if 'stable' in versions: + version = versions['stable'] + else: + print('no stable versions', versions) + raise ValueError() + else: + print('no versions??', formula) + raise ValueError() + result[name] = Version(version, version) + return result + +def build_repo(name: str, url: str) -> Repository: + url = f'https://formulae.brew.sh/api/{url}.json' + return Repository( + family='Homebrew', + repo=name, + index_url=url, + parse=parse_cached, + ) + +core = build_repo('Core', 'formula') +linux = build_repo('Linux', 'formula-linux') +cask = build_repo('Cask', 'cask') |