aboutsummaryrefslogtreecommitdiff
path: root/repos/alpine_linux.py
diff options
context:
space:
mode:
Diffstat (limited to 'repos/alpine_linux.py')
-rw-r--r--repos/alpine_linux.py68
1 files changed, 68 insertions, 0 deletions
diff --git a/repos/alpine_linux.py b/repos/alpine_linux.py
new file mode 100644
index 0000000..64f159a
--- /dev/null
+++ b/repos/alpine_linux.py
@@ -0,0 +1,68 @@
+from io import TextIOWrapper
+from pathlib import Path
+import tarfile
+from typing import Mapping, TextIO
+
+from .base import Repository
+
+__all__ = [
+ 'stable_main_x86_64',
+ 'stable_community_x86_64',
+ 'edge_main_x86_64',
+ 'edge_community_x86_64',
+ 'edge_testing_x86_64',
+]
+
+def parse_apkindex(apkindex: TextIO) -> Mapping[str, str]:
+ result = dict()
+ current_package = None
+ current_version = None
+ ignore_lines = ['C', 'A', 'S', 'I', 'T', 'U', 'L', 'o', 'm', 't', 'c', 'D', 'p', 'i', 'k']
+ for line in apkindex:
+ line = line.strip()
+ if len(line) == 0:
+ if current_package is not None and current_version is not None:
+ result[current_package] = current_version
+ current_package = None
+ current_version = None
+ continue
+ try:
+ line_type, line_data = line.split(':', 1)
+ except ValueError:
+ print('what uhhhh the fuck', line, line.split(':', 1))
+ continue
+ if line_type == 'C':
+ # TODO figure out what this means
+ pass
+ elif line_type == 'P':
+ current_package = line_data
+ elif line_type == 'V':
+ current_version = line_data
+ elif line_type in ignore_lines:
+ pass
+ else:
+ raise ValueError('unknown line type: ' + line_type + ' in line ' + repr(line))
+ return result
+
+def parse_cached(cached: Path) -> Mapping[str, str]:
+ apkindex = tarfile.open(cached)
+ for archive_member in apkindex.getmembers():
+ if archive_member.name == 'APKINDEX':
+ apkindex_file = apkindex.extractfile(archive_member)
+ apkindex_file = TextIOWrapper(apkindex_file)
+ return parse_apkindex(apkindex_file)
+
+def build_repo(name: str, url_path: str):
+ url = f'http://dl-cdn.alpinelinux.org/alpine/{url_path}/APKINDEX.tar.gz'
+ return Repository(
+ family='Alpine Linux',
+ repo=name,
+ 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')