Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
check-ubuntu-version-monotonicity
#!/usr/bin/python3
import apt_pkg
import debian.deb822
import gzip
import sys
from io import BytesIO
from ubuntutools.lp.lpapicache import Distribution
from urllib.request import urlopen
COMPONENTS = ["main", "restricted", "universe", "multiverse"]
POCKETS = ["", "-security", "-updates"]
apt_pkg.init_system()
def merge_versions(version_dicts):
out = {}
for d in version_dicts:
for p, v in d.items():
if p not in out or apt_pkg.version_compare(v, out[p]) > 0:
out[p] = v
return out
def get_pocket_component_versions(pocket, component):
url = (
f"http://archive.ubuntu.com/ubuntu/dists/{pocket}/{component}/source/Sources.gz"
)
print(f"Reading {url}", file=sys.stderr)
with urlopen(url) as fz, gzip.open(fz) as f:
return {
src["Package"]: src["Version"]
for src in debian.deb822.Sources.iter_paragraphs(BytesIO(f.read()))
}
def get_release_versions(release):
return merge_versions(
get_pocket_component_versions(release + pocket, component)
for pocket in POCKETS
for component in COMPONENTS
)
dist = Distribution("ubuntu")
releases = [series.name for series in dist.series if series.active]
versions = {release: get_release_versions(release) for release in releases}
for new, old in zip(releases[:-1], releases[1:]):
print(f"Comparing {new}, {old}:")
for p in sorted(set(versions[new]) & set(versions[old])):
if apt_pkg.version_compare(versions[new][p], versions[old][p]) < 0:
print(f"{p} {versions[new][p]} < {versions[old][p]}")
print()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.