File: checkstate.py

package info (click to toggle)
python-apt 0.9.3.11
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 3,024 kB
  • sloc: cpp: 9,274; python: 6,545; makefile: 106; sh: 16
file content (36 lines) | stat: -rwxr-xr-x 970 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/python
#
#
# this example is not usefull to find out about updated, upgradable packages
# use the depcache.py example for it (because a pkgPolicy is not used here)
#

import apt_pkg
apt_pkg.init()

cache = apt_pkg.Cache()
packages = cache.packages

uninstalled, updated, upgradable = {}, {}, {}

for package in packages:
    versions = package.version_list
    if not versions:
        continue
    version = versions[0]
    for other_version in versions:
        if apt_pkg.version_compare(version.ver_str, other_version.ver_str) < 0:
            version = other_version
    if package.current_ver:
        current = package.current_ver
        if apt_pkg.version_compare(current.ver_str, version.ver_str) < 0:
            upgradable[package.name] = version
            break
        else:
            updated[package.name] = current
    else:
        uninstalled[package.name] = version


for l in (uninstalled, updated, upgradable):
    print l.items()[0]