mirror of
https://codeberg.org/Mo8it/dotfiles.git
synced 2025-01-03 15:49:19 +00:00
87 lines
2.2 KiB
Python
87 lines
2.2 KiB
Python
import json
|
|
import re
|
|
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.strip()
|
|
|
|
|
|
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 cargo_packages(output_dir):
|
|
out = cap_run("cargo install --list")
|
|
|
|
pattern = r"(.+) .+:.*"
|
|
crates = re.findall(pattern, out)
|
|
|
|
file = output_dir / "cargo.txt"
|
|
with file.open("w") as f:
|
|
for crate in crates:
|
|
f.write(crate + "\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)
|
|
|
|
|
|
def main():
|
|
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"
|
|
)
|
|
|
|
pipx_packages(output_dir)
|
|
|
|
cargo_packages(output_dir)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|