mirror of
https://codeberg.org/Mo8it/dotfiles.git
synced 2024-12-30 23:23:44 +00:00
80 lines
2.1 KiB
Python
80 lines
2.1 KiB
Python
import json
|
|
import subprocess
|
|
from os import environ
|
|
from pathlib import Path
|
|
|
|
|
|
def run(command, **kwargs):
|
|
return subprocess.run(command, shell=True, check=True, **kwargs)
|
|
|
|
|
|
def cap_run(command, **kwargs):
|
|
return run(
|
|
command, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, text=True, **kwargs
|
|
).stdout
|
|
|
|
|
|
def rpm_ostree_packages(output_dir):
|
|
out = cap_run("rpm-ostree status --json")
|
|
json_out = json.loads(out)
|
|
|
|
deployments = json_out["deployments"]
|
|
booted_deployment = deployments[0]
|
|
|
|
if not booted_deployment["booted"]:
|
|
for depl in deployments:
|
|
if depl["booted"]:
|
|
booted_deployment = depl
|
|
break
|
|
|
|
removals = booted_deployment["requested-base-removals"]
|
|
additions = booted_deployment["requested-packages"]
|
|
|
|
file = output_dir / "rpm-ostree.json"
|
|
with file.open("w") as f:
|
|
dict = {"Removed": removals, "Added": additions}
|
|
json.dump(dict, f, indent=4)
|
|
|
|
|
|
def npm_packages(output_dir):
|
|
out = cap_run("npm list --json -g")
|
|
json_out = json.loads(out)
|
|
deps = json_out["dependencies"].keys()
|
|
|
|
file = output_dir / "npm.txt"
|
|
with file.open("w") as f:
|
|
for dep in deps:
|
|
f.write(dep + "\n")
|
|
|
|
|
|
def pipx_packages(output_dir):
|
|
out = cap_run("pipx list --json")
|
|
json_out = json.loads(out)
|
|
|
|
venvs = json_out["venvs"]
|
|
|
|
packages = []
|
|
injections = []
|
|
for ind, venv_key in enumerate(venvs.keys()):
|
|
metadata = venvs[venv_key]["metadata"]
|
|
packages.append(metadata["main_package"]["package_or_url"])
|
|
injections.append(list(metadata["injected_packages"].keys()))
|
|
|
|
file = output_dir / "pipx.json"
|
|
with file.open("w") as f:
|
|
dict = {p: i for p, i in zip(packages, injections)}
|
|
json.dump(dict, f, indent=4)
|
|
|
|
|
|
output_dir = Path(f"{environ['HOME']}/bk/installed_packages_info")
|
|
output_dir.mkdir(parents=True, exist_ok=True)
|
|
|
|
rpm_ostree_packages(output_dir)
|
|
|
|
run(f"flatpak list --app --columns=name,application,origin > {output_dir}/flatpak.csv")
|
|
|
|
run(f"cargo install --list | rg '(.+) .+:.*' -r '$1' > {output_dir}/cargo.txt")
|
|
|
|
pipx_packages(output_dir)
|
|
|
|
npm_packages(output_dir)
|