]>
code.delx.au - monosys/blob - bin/pacorphan
8 PACORPHAN_PATH
= os
.path
.expanduser("~/.pacorphan")
11 mark_explicit_list
= []
12 need_install_list
= []
13 unneeded_pkg_list
= []
14 installed_pkg_list
= []
15 explicit_pkg_list
= []
17 def strip_comment(line
):
23 for filename
in os
.listdir(PACORPHAN_PATH
):
24 if filename
.startswith("."):
26 filename
= os
.path
.join(PACORPHAN_PATH
, filename
)
27 for pkg
in codecs
.open(filename
, "r", "utf-8"):
28 pkg
= strip_comment(pkg
)
29 if pkg
in keep_pkg_list
:
30 print("# Duplicate entry: " + pkg
)
32 keep_pkg_list
.append(pkg
.strip())
34 for pkg
in subprocess
.check_output(["pacman", "-Qq"]).decode("utf-8").split():
35 installed_pkg_list
.append(pkg
.strip())
37 for pkg
in subprocess
.check_output(["pacman", "-Qtq"]).decode("utf-8").split():
38 unneeded_pkg_list
.append(pkg
.strip())
40 for pkg
in subprocess
.check_output(["pacman", "-Qeq"]).decode("utf-8").split():
41 explicit_pkg_list
.append(pkg
.strip())
44 for pkg
in keep_pkg_list
:
45 if pkg
in unneeded_pkg_list
:
46 unneeded_pkg_list
.remove(pkg
)
48 if pkg
in explicit_pkg_list
:
49 explicit_pkg_list
.remove(pkg
)
51 if pkg
in installed_pkg_list
:
52 mark_explicit_list
.append(pkg
)
54 need_install_list
.append(pkg
)
58 print("# Found packages to remove")
59 print("sudo pacman -R " + " ".join(unneeded_pkg_list
))
63 print("# Found explicitly installed packages to keep")
64 print("echo " + " ".join(explicit_pkg_list
) + " | tr ' ' '\\n' >> ~/.pacorphan/keep")
67 if mark_explicit_list
:
68 print("# Found packages which should be marked as explicitly installed")
69 print("sudo pacman -D --asexplicit " + " ".join(mark_explicit_list
))
73 print("# Found packages which should be installed")
74 print("sudo pacman -S " + " ".join(need_install_list
))