/usr/lib/python3/dist-packages/DistUpgrade/apt-autoinst-fixup.py is in python3-distupgrade 1:0.220.10.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | #!/usr/bin/python
import sys
import os
import warnings
warnings.filterwarnings("ignore", "apt API not stable yet", FutureWarning)
import apt
import apt_pkg
import logging
logging.basicConfig(level=logging.DEBUG,
filename="/var/log/dist-upgrade/apt-autoinst-fixup.log",
format='%(asctime)s %(levelname)s %(message)s',
filemode='w')
cache = apt.Cache()
min_version = "0.6.20ubuntu13"
if apt_pkg.version_compare(getattr(cache["python-apt"].installed, "version", "0"), min_version) < 0:
logging.error("Need at least python-apt version %s " % min_version)
sys.exit(1)
# figure out what needs fixup
logging.debug("Starting to check for auto-install states that need fixup")
need_fixup = set()
# work around #105663
need_fixup.add("mdadm")
for pkg in cache:
if pkg.is_installed and pkg.section == "metapackages":
logging.debug("Found installed meta-pkg: '%s' " % pkg.name)
dependsList = pkg._pkg.current_ver.depends_list
for t in ["Depends","PreDepends","Recommends"]:
if t in dependsList:
for depOr in dependsList[t]:
for dep in depOr:
depname = dep.target_pkg.name
if (cache[depname].is_installed and
cache._depcache.is_auto_installed(cache[depname]._pkg)):
logging.info("Removed auto-flag from package '%s'" % depname)
need_fixup.add(depname)
# now go through the tagfile and actually fix it up
if len(need_fixup) > 0:
# action is set to zero (reset the auto-flag)
action = 0
STATE_FILE = apt_pkg.config.find_dir("Dir::State") + "extended_states"
# open the statefile
if os.path.exists(STATE_FILE):
tagfile = apt_pkg.TagFile(open(STATE_FILE))
outfile = open(STATE_FILE+".tmp","w")
for section in tagfile:
pkgname = section.get("Package")
autoInst = section.get("Auto-Installed")
if pkgname in need_fixup:
newsec = apt_pkg.rewrite_section(
section, [], [("Auto-Installed", str(action))])
outfile.write(newsec+"\n")
else:
outfile.write(str(section)+"\n")
os.rename(STATE_FILE, STATE_FILE+".fixup-save")
os.rename(outfile.name, STATE_FILE)
os.chmod(STATE_FILE, 0o644)
|