-
Notifications
You must be signed in to change notification settings - Fork 5
/
arch-to-nvchecker
executable file
·98 lines (75 loc) · 3.37 KB
/
arch-to-nvchecker
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env python
import pyalpm
import argparse
from nvchecker import core as nvchecker_core
from nvchecker.util import RichResult
PREFIX_MAP = {
"pypi": "python-",
"cpan": "perl-",
"hackage": "haskell-",
"gems": "ruby-",
"npm": "nodejs-",
}
def main():
parser = argparse.ArgumentParser(description='Check or update nvchecker oldver db from pacman sync db')
parser.add_argument('-u', '--update', action="store_true",
help='Actually update nvchecker db after printing the difference')
parser.add_argument('--db', nargs="*", default=["core-testing", "core", "extra-testing", "extra",
"multilib-testing", "multilib"],
help='Pacman sync db to consider. Defaulting to all with testing and multilib enabled')
parser.add_argument("-n", "--newer", action="store_true",
help='Only consider entry when pacman version is not newer than newver (useful when Arch bumped to an alpha, etc)')
args = parser.parse_args()
nvchecker_config = nvchecker_core.get_default_config()
nvchecker_entries, nvchecker_options = nvchecker_core.load_file(nvchecker_config, use_keymanager=False)
oldvers = nvchecker_core.read_verfile(nvchecker_options.ver_files[0])
newvers = nvchecker_core.read_verfile(nvchecker_options.ver_files[1])
handle = pyalpm.Handle(".", "/var/lib/pacman")
archvers = {}
for db in args.db:
db_handle = handle.register_syncdb(db, 0)
for package in db_handle.search(""):
if package.name in archvers:
continue
archvers[package.name] = package.version.split("-")[0]
if ":" in archvers[package.name]:
archvers[package.name] = archvers[package.name].split(":")[1]
for entry_name in newvers:
pkgname = entry_name
if pkgname not in nvchecker_entries:
# Entry recently removed
continue
entry = nvchecker_entries[pkgname]
if entry.get("arch_ignored"):
continue
if _pkgname := entry.get("arch_pkgname"):
pkgname = _pkgname
else:
pkgname = PREFIX_MAP.get(entry["source"], "") + pkgname.lower()
if pkgname not in archvers and "_" in pkgname:
pkgname = pkgname.replace("_", "-")
if pkgname not in archvers and "." in pkgname:
pkgname = pkgname.replace(".", "-")
if pkgname not in archvers and pkgname != entry_name:
pkgname = entry_name
if pkgname not in archvers:
pkgname = pkgname.lower()
if pkgname not in archvers:
continue
archver = archvers[pkgname]
oldver = oldvers.get(entry_name, None)
if oldver is not None:
oldver = oldver.version
if archver != oldver:
if oldver is not None:
if oldver + ".0" == archver or archver + ".0" == oldver:
continue
if args.newer:
if pyalpm.vercmp(archver, newvers[entry_name]) > 0:
continue
print(pkgname, oldver, "->", archver)
oldvers[entry_name] = RichResult(version=archver)
if args.update:
nvchecker_core.write_verfile(nvchecker_options.ver_files[0], oldvers)
if __name__ == '__main__':
main()