]>
code.delx.au - monosys/blob - scripts/pacorphan
a64a2ee0c1d6a6d434ca8e21fe7ca073fbdb159a
8 PACORPHAN_PATH
= os
.path
.expanduser("~/.pacorphan")
11 for line
in subprocess
.check_output(cmd
).decode("utf-8").split("\n"):
16 def strip_comment(line
):
24 mark_explicit_list
= []
25 need_install_list
= []
26 unneeded_pkg_list
= []
27 installed_pkg_list
= []
28 explicit_pkg_list
= []
30 for filename
in sorted(os
.listdir(PACORPHAN_PATH
)):
31 if filename
.startswith("."):
33 full_filename
= os
.path
.join(PACORPHAN_PATH
, filename
)
34 for pkg
in codecs
.open(full_filename
, "r", "utf-8"):
35 pkg
= strip_comment(pkg
).strip()
38 if filename
[0] != "~":
39 if pkg
in keep_pkg_list
:
40 print("# Duplicate entry:", pkg
, "in file", filename
)
42 keep_pkg_list
.append(pkg
)
44 if pkg
not in keep_pkg_list
:
45 print("# Redundant removal:", pkg
, "in file", filename
)
47 keep_pkg_list
.remove(pkg
)
49 for pkg
in run(["pacman", "-Qq"]):
50 installed_pkg_list
.append(pkg
)
52 for pkg
in run(["pacman", "-Qttq"]):
53 unneeded_pkg_list
.append(pkg
)
55 for pkg
in run(["pacman", "-Qeq"]):
56 explicit_pkg_list
.append(pkg
)
59 for pkg
in keep_pkg_list
:
60 if pkg
in unneeded_pkg_list
:
61 unneeded_pkg_list
.remove(pkg
)
63 if pkg
in explicit_pkg_list
:
64 explicit_pkg_list
.remove(pkg
)
66 if pkg
in installed_pkg_list
:
67 mark_explicit_list
.append(pkg
)
69 need_install_list
.append(pkg
)
73 print("# Found packages to remove")
74 print("sudo pacman -R " + " ".join(unneeded_pkg_list
))
78 print("# Found explicitly installed packages to keep")
79 print("echo " + " ".join(explicit_pkg_list
) + " | tr ' ' '\\n' >> ~/.pacorphan/keep")
82 if mark_explicit_list
:
83 print("# Found packages which should be marked as explicitly installed")
84 print("sudo pacman -D --asexplicit " + " ".join(mark_explicit_list
))
88 print("# Found packages which should be installed")
89 print("sudo pacman -S " + " ".join(need_install_list
))