Skip to content

Instantly share code, notes, and snippets.

@changsijay
Last active July 24, 2018 17:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save changsijay/cd42cae827c2a549adaf3e7507ee5f2d to your computer and use it in GitHub Desktop.
Save changsijay/cd42cae827c2a549adaf3e7507ee5f2d to your computer and use it in GitHub Desktop.
remove unnecessary packages, only keep what I want
import subprocess
must_have = [
"linux46",
"systemd",
"acpid",
"xorg-server",
"xf86-video-ati",
"xf86-input-evdev",
"xorg-xinit",
"xorg-utils",
"gnome-shell",
"gnome-session",
"gnome-terminal",
"polkit-gnome",
"gnome-backgrounds",
"networkmanager",
"alsa-firmware",
"alsa-lib",
"alsa-plugins",
"alsa-utils",
"pulseaudio-alsa",
"pulseaudio",
"gstreamer",
"gstreamer0.10",
"gstreamer0.10-good",
"pacman-mirrorlist",
"sudo",
"tzdata",
]
def get_base_packages():
cmd = "pacman -Qqg base"
out = subprocess.check_output(cmd, shell=True).decode()
return out.split()
def double_check_removable(pkg):
cmd = "pactree -ar %s" % pkg
try:
out = subprocess.check_output(cmd, shell=True).decode()
except:
return True
for p in must_have:
check = "-%s\n" % p
if check in out:
return False
return True
def get_all_pkgs():
pkgs = []
cmd = "pacman -Qi"
out = subprocess.check_output(cmd, shell=True).decode().split("\n\n")
for block in out:
pkg = {}
for line in block.split("\n"):
if line.startswith("Name"):
pkg["name"] = line.split(":")[-1].strip()
elif line.startswith("Version"):
pkg["version"] = line.split(":")[-1].strip()
elif line.startswith("Installed Size"):
pkg["size"] = line.split(":")[-1].strip()
pkg["weight"] = 0
if "name" in pkg:
pkgs.append(pkg)
return pkgs
def get_dependencies(pkg):
cmd = "pactree -a %s" % pkg
out = subprocess.check_output(cmd, shell=True).decode().split("\n")
deps = []
for line in out:
if "-" in line:
name = (line.split("-", 1)[-1])
if "provides" in name:
name = name.split("provides")[0]
deps.append(name)
return deps
def remove(pkg):
cmd = "sudo pacman -Rsc --noconfirm %s" % pkg
subprocess.call(cmd, shell=True)
all_pkgs = get_all_pkgs()
must_have.extend(get_base_packages())
for p in must_have:
for pkg in all_pkgs:
if p == pkg["name"]:
pkg["weight"] = 9999
deps = get_dependencies(p)
for dep in deps:
for pkg in all_pkgs:
if dep == pkg["name"]:
pkg["weight"] += 1
all_pkgs = sorted(all_pkgs, key=lambda pkg: pkg["weight"])
for p in all_pkgs:
if p["weight"] == 0 and double_check_removable(p["name"]):
print("remove %s" % p["name"])
remove(p["name"])
import subprocess
must_have = [
"linux414",
"systemd",
"acpid",
"xorg-server",
"xf86-video-ati",
"xf86-input-evdev",
"xorg-xinit",
"plasma-desktop",
"plasma-nm",
"plasma-pa",
"plasma-workspace-wallpapers",
"plasma5-themes-breath",
"kwallet-pam",
"gtk-theme-breath",
"breeze",
"breath-icon-theme",
"kde-gtk-config",
"konsole",
"dolphin",
"sddm",
"sddm-breath-theme",
"networkmanager",
"alsa-firmware",
"alsa-lib",
"alsa-plugins",
"alsa-utils",
"pulseaudio-alsa",
"pulseaudio",
"gstreamer",
"gst-plugins-bad",
"gst-plugins-good",
"pacman-mirrorlist",
"sudo",
"tzdata",
"firefox",
"noto-fonts",
"noto-fonts-compat",
"noto-fonts-emoji",
]
def get_base_packages():
cmd = "pacman -Qqg base"
out = subprocess.check_output(cmd, shell=True).decode()
return out.split()
def double_check_removable(pkg):
cmd = "pactree -ar %s" % pkg
try:
out = subprocess.check_output(cmd, shell=True).decode()
except:
return True
for p in must_have:
check = "-%s\n" % p
if check in out:
return False
return True
def get_all_pkgs():
pkgs = []
cmd = "pacman -Qi"
out = subprocess.check_output(cmd, shell=True).decode().split("\n\n")
for block in out:
pkg = {}
for line in block.split("\n"):
if line.startswith("Name"):
pkg["name"] = line.split(":")[-1].strip()
elif line.startswith("Version"):
pkg["version"] = line.split(":")[-1].strip()
elif line.startswith("Installed Size"):
pkg["size"] = line.split(":")[-1].strip()
pkg["weight"] = 0
if "name" in pkg:
pkgs.append(pkg)
return pkgs
def get_dependencies(pkg):
cmd = "pactree -a %s" % pkg
out = subprocess.check_output(cmd, shell=True).decode().split("\n")
deps = []
for line in out:
if "-" in line:
name = (line.split("-", 1)[-1])
if "provides" in name:
name = name.split("provides")[0]
deps.append(name)
return deps
def remove(pkg):
cmd = "sudo pacman -Rsc --noconfirm %s" % pkg
subprocess.call(cmd, shell=True)
all_pkgs = get_all_pkgs()
must_have.extend(get_base_packages())
for p in must_have:
for pkg in all_pkgs:
if p == pkg["name"]:
pkg["weight"] = 9999
deps = get_dependencies(p)
for dep in deps:
for pkg in all_pkgs:
if dep == pkg["name"]:
pkg["weight"] += 1
all_pkgs = sorted(all_pkgs, key=lambda pkg: pkg["weight"])
for p in all_pkgs:
if p["weight"] == 0 and double_check_removable(p["name"]):
print("remove %s" % p["name"])
remove(p["name"])
@changsijay
Copy link
Author

noto fonts

@changsijay
Copy link
Author

ssdm -> kdewallet

@changsijay
Copy link
Author

breath icons

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment