Skip to content

Commit 573885f

Browse files
committed
Find packages to update
Signed-off-by: Gaëtan Lehmann <gaetan.lehmann@vates.tech>
1 parent 79627ac commit 573885f

File tree

1 file changed

+132
-0
lines changed

1 file changed

+132
-0
lines changed
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
#!/usr/bin/env python3
2+
3+
import argparse
4+
import csv
5+
import logging
6+
import tempfile
7+
from collections import namedtuple
8+
from typing import Iterable, Iterator
9+
10+
import rpm # type: ignore
11+
12+
import repoquery
13+
14+
ARCH = "x86_64"
15+
XCP_VERSION = "8.3"
16+
17+
class EVR:
18+
def __init__(self, e: str, v: str, r: str):
19+
self._evr = (e, v, r)
20+
21+
def __eq__(self, other):
22+
if isinstance(other, EVR):
23+
return self._evr == other._evr
24+
else:
25+
return self._evr == other
26+
27+
def __gt__(self, other):
28+
if isinstance(other, EVR):
29+
return rpm.labelCompare(self._evr, other._evr) > 0 # type: ignore
30+
else:
31+
return self._evr > other
32+
33+
def __lt__(self, other):
34+
return other > self
35+
36+
def __str__(self):
37+
if self._evr[0] != '0':
38+
return f'{self._evr[0]}:{self._evr[1]}.{self._evr[2]}'
39+
else:
40+
return f'{self._evr[1]}.{self._evr[2]}'
41+
42+
# Filters an iterator of (n, e, v, r) for newest evr of each `n`.
43+
# Older versions are allowed to appear before the newer ones.
44+
def filter_best_evr(nevrs: Iterable[tuple[str, str, str, str]]) -> Iterator[tuple[str, str, str, str]]:
45+
best: dict[str, tuple[str, str, str]] = {}
46+
for (n, e, v, r) in nevrs:
47+
if n not in best or rpm.labelCompare(best[n], (e, v, r)) < 0: # type: ignore
48+
best[n] = (e, v, r)
49+
yield (n, e, v, r)
50+
# else (e, v, r) is older than a previously-seen version, drop
51+
52+
def collect_data_xcpng() -> dict[str, EVR]:
53+
with (tempfile.NamedTemporaryFile() as dnfconf,
54+
tempfile.TemporaryDirectory() as yumrepod):
55+
repoquery.setup_xcpng_yum_repos(yum_repo_d=yumrepod,
56+
sections=['base', 'updates'],
57+
bin_arch=None,
58+
version=XCP_VERSION)
59+
repoquery.dnf_setup(dnf_conf=dnfconf.name, yum_repo_d=yumrepod)
60+
61+
xcp_nevr = {
62+
n: EVR(e, v, r)
63+
for (n, e, v, r)
64+
in filter_best_evr(repoquery.rpm_parse_nevr(nevr, f".xcpng{XCP_VERSION}")
65+
for nevr in repoquery.all_srpms())}
66+
67+
return xcp_nevr
68+
69+
def collect_data_xs8():
70+
with (tempfile.NamedTemporaryFile() as dnfconf,
71+
tempfile.TemporaryDirectory() as yumrepod):
72+
73+
repoquery.setup_xs8_yum_repos(yum_repo_d=yumrepod,
74+
sections=['base', 'normal'],
75+
)
76+
repoquery.dnf_setup(dnf_conf=dnfconf.name, yum_repo_d=yumrepod)
77+
logging.debug("fill cache with XS info")
78+
repoquery.fill_srpm_binrpms_cache()
79+
80+
logging.debug("get all XS SRPMs")
81+
xs8_srpms = {nevr for nevr in repoquery.all_srpms()}
82+
xs8_rpms_sources = {nevr for nevr in repoquery.SRPM_BINRPMS_CACHE}
83+
84+
xs8_srpms_set = {n: EVR(e, v, r)
85+
for (n, e, v, r)
86+
in filter_best_evr(repoquery.rpm_parse_nevr(nevr, ".xs8")
87+
for nevr in xs8_srpms)}
88+
xs8_rpms_sources_set = {n: EVR(e, v, r)
89+
for (n, e, v, r)
90+
in filter_best_evr(repoquery.rpm_parse_nevr(nevr, ".xs8")
91+
for nevr in xs8_rpms_sources)}
92+
93+
return (xs8_srpms_set, xs8_rpms_sources_set)
94+
95+
def read_package_status_metadata():
96+
with open('package_status.csv', newline='') as csvfile:
97+
csvreader = csv.reader(csvfile, delimiter=';', quotechar='|')
98+
headers = next(csvreader)
99+
assert headers == ["SRPM_name", "status", "comment"], f"unexpected headers {headers!r}"
100+
PackageStatus = namedtuple("PackageStatus", headers[1:]) # type: ignore[misc]
101+
return {row[0]: PackageStatus(*row[1:])
102+
for row in csvreader}
103+
104+
parser = argparse.ArgumentParser()
105+
parser.add_argument('-v', '--verbose', action='count', default=0)
106+
args = parser.parse_args()
107+
108+
loglevel = {0: logging.WARNING, 1: logging.INFO, 2: logging.DEBUG}.get(args.verbose, logging.DEBUG)
109+
logging.basicConfig(format='[%(levelname)s] %(message)s', level=loglevel)
110+
111+
PACKAGE_STATUS = read_package_status_metadata()
112+
113+
xcp_set = collect_data_xcpng()
114+
(xs8_srpms_set, xs8_rpms_sources_set) = collect_data_xs8()
115+
116+
for n in sorted(set(xs8_srpms_set.keys()) | xs8_rpms_sources_set.keys()):
117+
if n in PACKAGE_STATUS and PACKAGE_STATUS[n].status == 'ignored':
118+
logging.debug(f"ignoring {n}")
119+
continue
120+
xs8_srpms_evr = xs8_srpms_set.get(n)
121+
xs8_rpms_sources_evr = xs8_rpms_sources_set.get(n)
122+
if xs8_srpms_evr is not None and xs8_rpms_sources_evr is not None:
123+
xs8_evr = max(xs8_srpms_evr, xs8_rpms_sources_evr)
124+
else:
125+
xs8_evr = xs8_srpms_evr or xs8_rpms_sources_evr
126+
xcp_evr = xcp_set.get(n)
127+
# if xcp_evr is not None and xcp_evr < xs8_evr:
128+
if xcp_evr is None:
129+
if not repoquery.is_pristine_upstream(str(xs8_evr)):
130+
print(f'{n} {xcp_evr} -> {xs8_evr}')
131+
elif xcp_evr < xs8_evr:
132+
print(f'{n} {xcp_evr} -> {xs8_evr}')

0 commit comments

Comments
 (0)