~ubuntu-core-dev/update-notifier/ubuntu

« back to all changes in this revision

Viewing changes to data/apt-check

  • Committer: mvo
  • Date: 2005-01-15 00:23:58 UTC
  • Revision ID: gustavo@niemeyer.net-20050115002358-469848491f936cd5
* big rename: upgrade-notifier -> update-notifier

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env python
2
 
 
3
 
 
4
 
#nice apt-get -s -o Debug::NoLocking=true upgrade | grep ^Inst 
5
 
 
6
 
import apt_pkg
7
 
import os
8
 
import sys
9
 
from optparse import OptionParser
10
 
SYNAPTIC_PINFILE = "/var/lib/synaptic/preferences"
11
 
 
12
 
# be nice
13
 
os.nice(19)
14
 
 
15
 
# check arguments
16
 
parser = OptionParser()
17
 
parser.add_option("-s",
18
 
                  "--security-only",
19
 
                  action="store_true",
20
 
                  dest="security_only",
21
 
                  help="show only security updates")
22
 
(options, args) = parser.parse_args()
23
 
print options.security_only
24
 
 
25
 
# init
26
 
apt_pkg.init()
27
 
 
28
 
# get caches
29
 
cache = apt_pkg.GetCache()
30
 
depcache = apt_pkg.GetDepCache(cache)
31
 
 
32
 
# read the pin files
33
 
depcache.ReadPinFile()
34
 
# read the synaptic pins too
35
 
if os.path.exists(SYNAPTIC_PINFILE):
36
 
    depcache.ReadPinFile(SYNAPTIC_PINFILE)
37
 
 
38
 
# init the depcache
39
 
depcache.Init()
40
 
 
41
 
if depcache.BrokenCount > 0:
42
 
    sys.stderr.write("E: BrokenCount > 0")
43
 
    sys.exit(-1)
44
 
 
45
 
# do the upgrade (not dist-upgrade!)
46
 
depcache.Upgrade()
47
 
 
48
 
# check for upgrade packages, we need to do it this way
49
 
# because of ubuntu #7907
50
 
upgrades = 0
51
 
security_updates = 0
52
 
for pkg in cache.Packages:
53
 
    if depcache.MarkedInstall(pkg) or depcache.MarkedUpgrade(pkg):
54
 
        # check if this is really a upgrade or a false positive
55
 
        # (workaround for ubuntu #7907)
56
 
        if depcache.GetCandidateVer(pkg) != pkg.CurrentVer:
57
 
                upgrades = upgrades + 1 
58
 
                ver = depcache.GetCandidateVer(pkg)
59
 
                for (file, index) in ver.FileList:
60
 
                    if file.Archive == "hoary-security":
61
 
                        security_updates += 1
62
 
 
63
 
# print the number of upgrades
64
 
if options.security_only:
65
 
    sys.stderr.write("%s" % security_updates)
66
 
else:
67
 
    sys.stderr.write("%s" % upgrades)
68
 
 
69
 
sys.exit(0)
 
1
#!/bin/sh
 
2
 
 
3
 
 
4
nice apt-get -s -o Debug::NoLocking=true upgrade | grep ^Inst