Last active
March 11, 2022 04:48
-
-
Save srkiNZ84/57f22d256be87f59b7575a5584239ef8 to your computer and use it in GitHub Desktop.
Python script to get list of installed packages that have upgrades and output in JSON
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
# NOTE: Requires the python3-apt package | |
import apt | |
import apt_pkg | |
import json | |
need_upgrade = [] | |
cache = apt.apt_pkg.Cache() | |
dep_cache = apt.apt_pkg.DepCache(cache) | |
for pkg in cache.packages: | |
if dep_cache.is_upgradable(pkg) and pkg.current_state == apt_pkg.CURSTATE_INSTALLED: | |
#print(" ", pkg.name) | |
need_upgrade.append(pkg.name) | |
print(pkg.name, " needs upgrade. Current version is: ", pkg.current_ver.ver_str, "\n latest is: ", \ | |
dep_cache.get_candidate_ver(pkg).ver_str) | |
print(json.dumps(need_upgrade)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment