#!/usr/bin/env python
# http://users.sarai.net/shehjar/download/py-apt-tut.txt
import apt_pkg
import os
import sys
# init
apt_pkg.init()
# get caches
cache = apt_pkg.GetCache()
depcache = apt_pkg.GetDepCache(cache)
# read the pin files
depcache.ReadPinFile()
# read the synaptic pins too
#if os.path.exists(SYNAPTIC_PINFILE):
# depcache.ReadPinFile(SYNAPTIC_PINFILE)
# init the depcache
depcache.Init()
if depcache.BrokenCount > 0:
sys.stderr.write("E: BrokenCount > 0")
sys.exit(-1)
depcache.Upgrade()
# version comparison function:
# http://mail.python.org/pipermail/python-list/2005-March/272909.html
for pkg in cache.Packages:
# print pkg.Name
if pkg.CurrentVer:
print pkg.CurrentVer.VerStr
#for depend in pkg.CurrentVer.DependsList.get("Depends", []):
# print "depends", depend,
if depcache.MarkedInstall(pkg) or depcache.MarkedUpgrade(pkg):
if depcache.GetCandidateVer(pkg) != pkg.CurrentVer:
print "Update", pkg.Name
# sys.exit(0)
sys.exit(0)