]> code.delx.au - monosys/blob - bin/pacorphan
Removed wepkeygen
[monosys] / bin / pacorphan
1 #!/usr/bin/python
2
3 import codecs
4 import subprocess
5 import os
6 import sys
7
8 PACORPHAN_PATH = os.path.expanduser("~/.pacorphan")
9
10 keep_pkg_list = []
11 mark_explicit_list = []
12 need_install_list = []
13 unneeded_pkg_list = []
14 installed_pkg_list = []
15 explicit_pkg_list = []
16
17 def strip_comment(line):
18 pos = line.find("#")
19 if pos >= 0:
20 line = line[:pos]
21 return line.strip()
22
23 for filename in os.listdir(PACORPHAN_PATH):
24 if filename.startswith("."):
25 continue
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)
31 if pkg:
32 keep_pkg_list.append(pkg.strip())
33
34 for pkg in subprocess.check_output(["pacman", "-Qq"]).decode("utf-8").split():
35 installed_pkg_list.append(pkg.strip())
36
37 for pkg in subprocess.check_output(["pacman", "-Qtq"]).decode("utf-8").split():
38 unneeded_pkg_list.append(pkg.strip())
39
40 for pkg in subprocess.check_output(["pacman", "-Qeq"]).decode("utf-8").split():
41 explicit_pkg_list.append(pkg.strip())
42
43
44 for pkg in keep_pkg_list:
45 if pkg in unneeded_pkg_list:
46 unneeded_pkg_list.remove(pkg)
47
48 if pkg in explicit_pkg_list:
49 explicit_pkg_list.remove(pkg)
50 else:
51 if pkg in installed_pkg_list:
52 mark_explicit_list.append(pkg)
53 else:
54 need_install_list.append(pkg)
55
56
57 if unneeded_pkg_list:
58 print("# Found packages to remove")
59 print("sudo pacman -R " + " ".join(unneeded_pkg_list))
60 print()
61
62 if explicit_pkg_list:
63 print("# Found explicitly installed packages to keep")
64 print("echo " + " ".join(explicit_pkg_list) + " | tr ' ' '\\n' >> ~/.pacorphan/keep")
65 print()
66
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))
70 print()
71
72 if need_install_list:
73 print("# Found packages which should be installed")
74 print("sudo pacman -S " + " ".join(need_install_list))
75 print()
76