]>
code.delx.au - monosys/blob - bin/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 os
.listdir(APTORPHAN_PATH
):
56 if filename
.startswith("."):
58 filename
= os
.path
.join(APTORPHAN_PATH
, filename
)
59 for pkg
in codecs
.open(filename
, "r", "utf-8"):
60 pkg
= strip_comment(pkg
)
61 if pkg
in keep_pkg_list
:
62 print("# Duplicate entry: " + pkg
)
64 keep_pkg_list
.append(pkg
.strip())
66 for pkg
in run(["aptitude", "search", "?or(~i!~aremove,~ainstall)", "-F", "%p"]):
67 installed_pkg_list
.append(pkg
.strip())
69 for pkg
in run(["aptitude", "search", "?or(~i!~M!~aremove,~ainstall!~M)", "-F", "%p"]):
70 explicit_pkg_list
.append(pkg
.strip())
73 for pkg
in keep_pkg_list
:
74 if pkg
in explicit_pkg_list
:
75 explicit_pkg_list
.remove(pkg
)
77 if pkg
in installed_pkg_list
:
78 mark_explicit_list
.append(pkg
)
80 need_install_list
.append(pkg
)
83 if mark_explicit_list
:
84 print("# Found packages which should be marked as explicitly installed")
85 print("sudo aptitude --schedule-only install " + " ".join(mark_explicit_list
))
89 print("# Found packages which should be installed")
90 print("sudo aptitude --schedule-only install " + " ".join(need_install_list
))
94 print("# Found explicitly installed packages to keep or remove")
95 print("echo " + " ".join(explicit_pkg_list
) + " | tr ' ' '\\n' >> ~/.aptorphan/keep")
96 print("sudo aptitude --schedule-only install " + " ".join([(x
+"+M") for x
in explicit_pkg_list
]))