]>
code.delx.au - monosys/blob - scripts/aptorphan
8 APTORPHAN_PATH
= os
.path
.expanduser("~/.aptorphan")
12 for line
in subprocess
.check_output(cmd
).decode("utf-8").split("\n"):
18 def strip_comment(line
):
26 APT::Install-Recommends "false";
27 APT::Install-Suggests "false";
28 APT::AutoRemove::RecommendsImportant "false";
29 APT::AutoRemove::SuggestsImportant "false";
30 """.strip().split("\n")
32 actual_config
= run(["apt-config", "dump"])
35 for required_line
in required_config
:
36 for line
in actual_config
:
37 if line
== required_line
:
40 missing_lines
.append(required_line
)
42 print("Missing apt-config, add these lines to /etc/apt/apt.conf.d/99recommends-disable")
43 print("\n".join(missing_lines
))
50 mark_explicit_list
= []
51 need_install_list
= []
52 installed_pkg_list
= []
53 explicit_pkg_list
= []
55 for filename
in sorted(os
.listdir(APTORPHAN_PATH
)):
56 if filename
.startswith("."):
58 full_filename
= os
.path
.join(APTORPHAN_PATH
, filename
)
59 for pkg
in codecs
.open(full_filename
, "r", "utf-8"):
60 pkg
= strip_comment(pkg
).strip()
63 if filename
[0] != "~":
64 if pkg
in keep_pkg_list
:
65 print("# Duplicate entry:", pkg
, "in file", filename
)
67 keep_pkg_list
.append(pkg
)
69 if pkg
not in keep_pkg_list
:
70 print("# Redundant removal:", pkg
, "in file", filename
)
72 keep_pkg_list
.remove(pkg
)
74 for pkg
in run(["aptitude", "search", "?or(~i!~aremove,~ainstall)", "-F", "%p"]):
75 installed_pkg_list
.append(pkg
.strip())
77 for pkg
in run(["aptitude", "search", "?or(~i!~M!~aremove,~ainstall!~M)", "-F", "%p"]):
78 explicit_pkg_list
.append(pkg
.strip())
81 for pkg
in keep_pkg_list
:
82 if pkg
in explicit_pkg_list
:
83 explicit_pkg_list
.remove(pkg
)
85 if pkg
in installed_pkg_list
:
86 mark_explicit_list
.append(pkg
)
88 need_install_list
.append(pkg
)
91 if mark_explicit_list
:
92 print("# Found packages which should be marked as explicitly installed")
93 print("sudo aptitude --schedule-only install " + " ".join([("'"+x
+"&m'") for x
in mark_explicit_list
]))
97 print("# Found packages which should be installed")
98 print("sudo aptitude --schedule-only install " + " ".join(need_install_list
))
101 if explicit_pkg_list
:
102 print("# Found explicitly installed packages to keep or remove")
103 print("echo " + " ".join(explicit_pkg_list
) + " | tr ' ' '\\n' >> ~/.aptorphan/keep")
104 print("sudo aptitude --schedule-only install " + " ".join([(x
+"+M") for x
in explicit_pkg_list
]))