From ea0aa8ab184ae3fd2e4152a44af99d955307991b Mon Sep 17 00:00:00 2001 From: Mo8it Date: Sat, 23 Apr 2022 23:07:27 +0200 Subject: [PATCH] Rewrite fetch_installed_packages script --- .scripts/fetch_installed_packages.fish | 16 ------ .scripts/fetch_installed_packages.xsh | 79 ++++++++++++++++++++++++++ 2 files changed, 79 insertions(+), 16 deletions(-) delete mode 100644 .scripts/fetch_installed_packages.fish create mode 100644 .scripts/fetch_installed_packages.xsh diff --git a/.scripts/fetch_installed_packages.fish b/.scripts/fetch_installed_packages.fish deleted file mode 100644 index 608979e..0000000 --- a/.scripts/fetch_installed_packages.fish +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/fish - -set -l output_dir "$HOME/bk/installed_packages_info" -mkdir -p $output_dir - -rpm-ostree status -b | rg -A 100 "Packages:" >$output_dir/rpm-ostree.txt - -flatpak list --app --columns=name,application,origin >$output_dir/flatpak.txt - -cargo install --list | rg '(.+) .+:.*' -r '$1' >$output_dir/cargo.txt - -pipx list | rg '.*package ([^\s]+).*' -r '$1' >$output_dir/pipx.txt - -npm list -g >$output_dir/npm.txt - -fisher list >$output_dir/fisher.txt diff --git a/.scripts/fetch_installed_packages.xsh b/.scripts/fetch_installed_packages.xsh new file mode 100644 index 0000000..25f744b --- /dev/null +++ b/.scripts/fetch_installed_packages.xsh @@ -0,0 +1,79 @@ +#!/usr/bin/env xonsh + +import os +import json +from pathlib import Path + +def rpm_ostree_packages(output_dir): + out = $(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.adoc" + with file.open("w") as f: + f.write("== Removed:\n") + for p in removals: + f.write(p + "\n") + + f.write("\n== Added:\n") + for p in additions: + f.write(p + "\n") + +def npm_packages(output_dir): + out = $(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 = $(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[ind] = metadata["injected_packages"].keys() + + file = output_dir / "pipx.adoc" + with file.open("w") as f: + for ind, package in enumerate(packages): + f.write(f"== {package}\n") + + package_injections = injections[ind] + if package_injections is not None: + for injec in package_injections: + f.write(injec + "\n") + + f.write("\n") + +output_dir = Path(f"{$HOME}/bk/installed_packages_info") +output_dir.mkdir(parents=True, exist_ok=True) + +rpm_ostree_packages(output_dir) + +flatpak list --app --columns=name,application,origin >@(output_dir)/flatpak.txt + +cargo install --list | rg '(.+) .+:.*' -r '$1' >@(output_dir)/cargo.txt + +pipx_packages(output_dir) + +npm_packages(output_dir)