7
warnings.filterwarnings("ignore", "apt API not stable yet", FutureWarning)
12
logging.basicConfig(level=logging.DEBUG,
13
filename="/var/log/dist-upgrade/apt-autoinst-fixup.log",
14
format='%(asctime)s %(levelname)s %(message)s',
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)
25
# figure out what needs fixup
26
logging.debug("Starting to check for auto-install states that need fixup")
30
need_fixup.add("mdadm")
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"]:
38
for depOr in dependsList[t]:
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)
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)
50
STATE_FILE = apt_pkg.config.find_dir("Dir::State") + "extended_states"
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")
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)