Skip to content

Instantly share code, notes, and snippets.

@iainlane
Created July 15, 2021 11:08
Show Gist options
  • Save iainlane/cf7a426ea35066e7ace8046cab922e6a to your computer and use it in GitHub Desktop.
Save iainlane/cf7a426ea35066e7ace8046cab922e6a to your computer and use it in GitHub Desktop.
esm
#!/usr/bin/python3
import apt
import apt_pkg
def list_esm_package_updates():
""" Find updates which you can install if you enable ESM. """
cache: apt.Cache = apt.Cache()
for pkg in cache:
found: bool = False
if not pkg.is_installed:
continue
candidate: apt.Version = pkg.candidate
# ok, now it's installed, look at the updates
for v in pkg.versions:
if (
v.policy_priority > -32768
): # this is not a Pin-Priority: never ESM update
continue
if (
v == candidate
): # we're only interested in versions that we can't upgrade to
continue
if (
apt_pkg.version_compare(v.version, pkg.installed.version) < 0
): # an older version, such as when we've installed an SRU
continue
for origin in v.origins:
if origin.archive and origin.origin.startswith("UbuntuESM"):
print(
f"{v.package.shortname} is available in {origin.origin}, which is not enabled."
)
found = True
break
if found:
break
if __name__ == "__main__":
list_esm_package_updates()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment