Refactor packages.py and add nixos (both profiles & nix-env)

This commit is contained in:
Skyler Grey 2022-05-22 22:29:16 +01:00
parent 3bd76dd35f
commit 97138dce31
No known key found for this signature in database
GPG Key ID: 24D31D3B1B986F33

View File

@ -1,28 +1,20 @@
from subprocess import check_output from subprocess import check_output
commands = [
"pacman -Qq",
"apt list --installed",
"yum list installed",
"dnf list installed",
"qlist -I",
"nix profile list",
"nix-env -q",
"rpm -qa",
]
def get_num_packages() -> (int, bool): def get_num_packages() -> (int, bool):
try: for command in commands:
return len(check_output(["pacman", "-Qq"]).decode("utf-8").split("\n")) - 1 try:
except FileNotFoundError: return len(check_output(command.split(" ")).decode("utf-8").split("\n")) - 1
pass except FileNotFoundError:
try: pass
return len(check_output(["apt", "list", "--installed"]).decode("utf-8").split("\n")) - 1 return False
except FileNotFoundError:
pass
try:
return len(check_output(["yum", "list", "installed"]).decode("utf-8").split("\n")) - 1
except FileNotFoundError:
pass
try:
return len(check_output(["dnf", "list", "installed"]).decode("utf-8").split("\n")) - 1
except FileNotFoundError:
pass
try:
return len(check_output(["qlist", "-I"]).decode("utf-8").split("\n")) - 1
except FileNotFoundError:
pass
try:
return len(check_output(["rpm", "-qa"]).decode("utf-8").split("\n")) - 1
except FileNotFoundError:
return False