Skip to content

Instantly share code, notes, and snippets.

@ar45
Created March 4, 2015 00:10
Show Gist options
  • Save ar45/08db412615f2740f1fe9 to your computer and use it in GitHub Desktop.
Save ar45/08db412615f2740f1fe9 to your computer and use it in GitHub Desktop.
get a list of all packages installed which are no longer available from the current sources
#!/usr/bin/python
#
# Generates and prints list of packages that are no longer available on the system from existing apt sources.
#
# * Ensure your package lists is up-to-date - run apt-get update
#
# Author: Aron Podrigal <[email protected]>
#
import os, sys
installed = os.popen("dpkg -l |awk '/^i/ {print $2,$3}'").read().split('\n')
num_pkgs = len(installed)
num_processed = 1
need_remove = []
for p in installed:
package = p.split(' ')
if len(package) != 2:
continue
name, version = package
sys.stdout.write('\rproccesing %.2f%%: %d/%d packages -- %50s' % (100.0 / num_pkgs * num_processed, num_processed, num_pkgs, name))
sys.stdout.flush()
num_processed = num_processed + 1
apt_cache=os.popen("apt-cache madison %s |awk '{print $3}' |uniq" % name).read().split('\n')
if version not in apt_cache:
need_remove.append((name, version))
pkglist = ' '.join([n[0] for n in need_remove])
sys.stdout.write('+Done. to install thos packages from your existing stable repo do ` apt-get -t <source> install\n')
sys.stdout.flush()
print pkglist
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment