~straemer/ubuntu/quantal/update-manager/fix-for-1058070

« back to all changes in this revision

Viewing changes to DistUpgrade/apt-autoinst-fixup.py

  • Committer: Package Import Robot
  • Author(s): Michael Terry
  • Date: 2012-06-29 10:59:30 UTC
  • mfrom: (389.1.2 precise-security)
  • Revision ID: package-import@ubuntu.com-20120629105930-0oaj9vdvykmvkjum
Tags: 1:0.165
* Implementation of "update on start" feature from spec
  https://wiki.ubuntu.com/SoftwareUpdates
* Use a single main window that changes instead of having modal dialogs
* Implement several special-purpose dialogs like "No updates" or
  "Dist upgrade needed" accordingn to the above spec
* Split out release upgrader code and DistUpgrade module into a separate
  source package
* Drop python-update-manager, as it is unused
* debian/tests:
  - Add dep8 tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/python
2
 
 
3
 
import sys
4
 
import os
5
 
 
6
 
import warnings
7
 
warnings.filterwarnings("ignore", "apt API not stable yet", FutureWarning)
8
 
import apt
9
 
import apt_pkg
10
 
import logging
11
 
 
12
 
logging.basicConfig(level=logging.DEBUG,
13
 
                    filename="/var/log/dist-upgrade/apt-autoinst-fixup.log",
14
 
                    format='%(asctime)s %(levelname)s %(message)s',
15
 
                    filemode='w')
16
 
 
17
 
cache = apt.Cache()
18
 
 
19
 
min_version = "0.6.20ubuntu13"
20
 
if apt_pkg.version_compare(getattr(cache["python-apt"].installed, "version", "0"), min_version) < 0:
21
 
    logging.error("Need at least python-apt version %s " % min_version)
22
 
    sys.exit(1)
23
 
 
24
 
 
25
 
# figure out what needs fixup
26
 
logging.debug("Starting to check for auto-install states that need fixup")
27
 
need_fixup = set()
28
 
 
29
 
# work around #105663
30
 
need_fixup.add("mdadm")
31
 
 
32
 
for pkg in cache:
33
 
    if pkg.is_installed and pkg.section == "metapackages":
34
 
        logging.debug("Found installed meta-pkg: '%s' " % pkg.name)
35
 
        dependsList = pkg._pkg.current_ver.depends_list
36
 
        for t in ["Depends","PreDepends","Recommends"]:
37
 
            if t in dependsList:
38
 
                for depOr in dependsList[t]:
39
 
                    for dep in depOr:
40
 
                        depname = dep.target_pkg.name
41
 
                        if (cache[depname].is_installed and
42
 
                            cache._depcache.is_auto_installed(cache[depname]._pkg)):
43
 
                            logging.info("Removed auto-flag from package '%s'" % depname)
44
 
                            need_fixup.add(depname)
45
 
        
46
 
# now go through the tagfile and actually fix it up
47
 
if len(need_fixup) > 0:
48
 
    # action is set to zero (reset the auto-flag)
49
 
    action = 0
50
 
    STATE_FILE = apt_pkg.config.find_dir("Dir::State") + "extended_states"
51
 
    # open the statefile
52
 
    if os.path.exists(STATE_FILE):
53
 
        tagfile = apt_pkg.TagFile(open(STATE_FILE))
54
 
        outfile = open(STATE_FILE+".tmp","w")
55
 
        for section in tagfile:
56
 
            pkgname = section.get("Package")
57
 
            autoInst = section.get("Auto-Installed")
58
 
            if pkgname in need_fixup:
59
 
                newsec = apt_pkg.rewrite_section(
60
 
                    section, [], [("Auto-Installed", str(action))])
61
 
                outfile.write(newsec+"\n")
62
 
            else:
63
 
                outfile.write(str(section)+"\n")
64
 
        os.rename(STATE_FILE, STATE_FILE+".fixup-save")
65
 
        os.rename(outfile.name, STATE_FILE)
66
 
        os.chmod(STATE_FILE, 0o644)
67
 
 
68
 
 
69