-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpkg_check.py
executable file
·43 lines (34 loc) · 1.21 KB
/
pkg_check.py
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
#!/usr/bin/env python3
"""Check if packages exist for Raspbian."""
import gzip
import os
import sys
from collections import defaultdict
from urllib.parse import urlparse
import six
def check(pkgs):
"""Check if packages exist for Raspbian."""
packages = defaultdict(int)
required_pkgs = "required_pkgs.txt"
url = "https://debian.osuosl.org/debian/dists/buster/main/binary-amd64/Packages.gz"
url_data = urlparse(url)
if not url_data.scheme.startswith("file"):
if not os.path.exists(pkgs):
six.print_("Downloading package list...", flush=True)
six.moves.urllib.request.urlretrieve(url, pkgs)
else:
print(f"Invalid URL: {url}")
sys.exit(1)
with gzip.open(pkgs, "rt") as pkg_file:
for line in pkg_file:
new_line = line.rstrip(os.linesep)
if new_line.startswith("Package"):
pkg = new_line.split(": ")[1]
packages[pkg] += 1
with open(required_pkgs, "rt") as required:
for line in required:
new_line = line.rstrip(os.linesep)
if new_line not in packages:
six.print_(new_line, flush=True)
if __name__ == "__main__":
check("Packages.gz")