+++ /dev/null
-#!/usr/bin/python3
-
-import codecs
-import subprocess
-import os
-import sys
-
-PACORPHAN_PATH = os.path.expanduser("~/.pacorphan")
-
-def run(cmd):
- for line in subprocess.check_output(cmd).decode("utf-8").split("\n"):
- line = line.strip()
- if line:
- yield line
-
-def strip_comment(line):
- pos = line.find("#")
- if pos >= 0:
- line = line[:pos]
- return line.strip()
-
-
-keep_pkg_list = []
-mark_explicit_list = []
-need_install_list = []
-unneeded_pkg_list = []
-installed_pkg_list = []
-explicit_pkg_list = []
-
-for filename in os.listdir(PACORPHAN_PATH):
- if filename.startswith("."):
- continue
- filename = os.path.join(PACORPHAN_PATH, filename)
- for pkg in codecs.open(filename, "r", "utf-8"):
- pkg = strip_comment(pkg)
- if pkg in keep_pkg_list:
- print("# Duplicate entry: " + pkg)
- if pkg:
- keep_pkg_list.append(pkg.strip())
-
-for pkg in run(["pacman", "-Qq"]):
- installed_pkg_list.append(pkg)
-
-for pkg in run(["pacman", "-Qtq"]):
- unneeded_pkg_list.append(pkg)
-
-for pkg in run(["pacman", "-Qeq"]):
- explicit_pkg_list.append(pkg)
-
-
-for pkg in keep_pkg_list:
- if pkg in unneeded_pkg_list:
- unneeded_pkg_list.remove(pkg)
-
- if pkg in explicit_pkg_list:
- explicit_pkg_list.remove(pkg)
- else:
- if pkg in installed_pkg_list:
- mark_explicit_list.append(pkg)
- else:
- need_install_list.append(pkg)
-
-
-if unneeded_pkg_list:
- print("# Found packages to remove")
- print("sudo pacman -R " + " ".join(unneeded_pkg_list))
- print()
-
-if explicit_pkg_list:
- print("# Found explicitly installed packages to keep")
- print("echo " + " ".join(explicit_pkg_list) + " | tr ' ' '\\n' >> ~/.pacorphan/keep")
- print()
-
-if mark_explicit_list:
- print("# Found packages which should be marked as explicitly installed")
- print("sudo pacman -D --asexplicit " + " ".join(mark_explicit_list))
- print()
-
-if need_install_list:
- print("# Found packages which should be installed")
- print("sudo pacman -S " + " ".join(need_install_list))
- print()
-