Skip to content

Instantly share code, notes, and snippets.

@jeremylowery
Created May 17, 2016 15:36
Show Gist options
  • Save jeremylowery/c47b9a1fb9a5700a284c0de708367a5b to your computer and use it in GitHub Desktop.
Save jeremylowery/c47b9a1fb9a5700a284c0de708367a5b to your computer and use it in GitHub Desktop.
Ubuntu: Show version by version comparison of manually installed packages in current distribution with another distribution
#!/usr/bin/env python
""" Show the difference between the versions of manually installed
packages on this system with the given distribution.
"""
import re
import sys
def main():
if not distribution():
sys.stderr.write("Could not determine distribution from /etc/os-release\n")
sys.exit(-1)
# Downloaded from http://packages.ubuntu.com/precise/allpackages?format=txt.gz
my_packages = packages_for('precise.txt')
# Downloaded from http://packages.ubuntu.com/trusty/allpackages?format=txt.gz
upgrade_packages = packages_for('trusty.txt')
for name in manually_installed():
print '{: <30}{: <35} {}'.format(
name,
my_packages.get(name, 'NOTPRESENT'),
upgrade_packages.get(name, 'NOTPRESENT'))
def packages_for(fname):
with open(fname) as fd:
[next(fd) for _ in range(6)]
pkg = {}
for line in fd:
if 'virtual package provided by' in line:
continue
m = re.match(r"^(\S+) \(([^\s\)]+)", line)
if not m:
print 'Could not match on line %r' % line
sys.exit(1)
name, ver = m.groups()
pkg[name] = ver
return pkg
def manually_installed():
# Create with comm -23 <(aptitude search '~i !~M' -F '%p' | sed "s/ *$//" | sort -u) <(gzip -dc /var/log/installer/initial-status.gz | sed -n 's/^Package: //p' | sort -u)
# http://askubuntu.com/questions/2389/generating-list-of-manually-installed-packages-and-querying-individual-packages
with open('manually-installed.txt') as fd:
return [s.strip() for s in fd]
def distribution():
with open("/etc/os-release") as fd:
for line in fd:
m = re.match('VERSION=".+?, (\S+)', line)
if m:
return m.groups()[0].lower()
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment