From 6368d8f30a6d5361ac87bd9cc4394652b584cc59 Mon Sep 17 00:00:00 2001 From: Janis Hutz Date: Sat, 13 Jun 2026 10:24:55 +0200 Subject: [PATCH] feat: improved pkgbuild, config concepts --- PKGBUILD | 2 +- archmgr/__init__.py | 4 ++- archmgr/config/__init__.py | 17 ++++++++++++ archmgr/config/pkgs/__init__.py | 2 ++ archmgr/config/pkgs/aur/__init__.py | 3 ++ archmgr/config/pkgs/aur/aur_helper.py | 40 +++++++++++++++++++++++++++ archmgr/config/pkgs/aur/custom.py | 13 +++++++++ archmgr/config/pkgs/repos/__init__.py | 3 ++ archmgr/pyproject.toml | 10 +++++++ archmgr/setup.py | 0 archmgr/util/pacman.py | 11 +++++--- notes.md | 23 +++++++++++++++ test.py | 2 ++ 13 files changed, 124 insertions(+), 6 deletions(-) create mode 100644 archmgr/config/__init__.py create mode 100644 archmgr/config/pkgs/aur/__init__.py create mode 100644 archmgr/config/pkgs/aur/aur_helper.py create mode 100644 archmgr/config/pkgs/aur/custom.py create mode 100644 archmgr/config/pkgs/repos/__init__.py create mode 100644 archmgr/pyproject.toml create mode 100644 archmgr/setup.py diff --git a/PKGBUILD b/PKGBUILD index 1f3d3fd..2bbd237 100644 --- a/PKGBUILD +++ b/PKGBUILD @@ -7,7 +7,7 @@ pkgdesc='A nixos-like declarative config and package manager for Arch Linux' arch=('any') url="https://github.com/janishutz/archmgr" license=('GPL3') -depends=('python', 'python-pyaml') +depends=('python' 'python-pyaml' 'python-colorama' 'python-pystache') makedepends=('git') provides=('archmgr') conflicts=('archmgr') diff --git a/archmgr/__init__.py b/archmgr/__init__.py index 7bbf0b9..a7d6087 100755 --- a/archmgr/__init__.py +++ b/archmgr/__init__.py @@ -1,7 +1,9 @@ #!/usr/bin/env python3 # PYTHON_ARGCOMPLETE_OK -# TODO: Re-export the config stuff +from archmgr.config import create_config + +__all__ = ["create_config"] if __name__ == "__main__": from app import run as _run diff --git a/archmgr/config/__init__.py b/archmgr/config/__init__.py new file mode 100644 index 0000000..f6cb73f --- /dev/null +++ b/archmgr/config/__init__.py @@ -0,0 +1,17 @@ +from archmgr.config.pkgs import ArchMgrPkgs + + +class ArchMgrConfig: + pkgs: ArchMgrPkgs + + def __init__(self) -> None: + self.pkgs = ArchMgrPkgs() + + +def create_config(): + """Create a new ArchMgrConfig, or get the existing config, if one exists + + Returns: + [TODO:return] + """ + return ArchMgrConfig() diff --git a/archmgr/config/pkgs/__init__.py b/archmgr/config/pkgs/__init__.py index e69de29..59d13f4 100644 --- a/archmgr/config/pkgs/__init__.py +++ b/archmgr/config/pkgs/__init__.py @@ -0,0 +1,2 @@ +class ArchMgrPkgs: + pass diff --git a/archmgr/config/pkgs/aur/__init__.py b/archmgr/config/pkgs/aur/__init__.py new file mode 100644 index 0000000..dd59a3f --- /dev/null +++ b/archmgr/config/pkgs/aur/__init__.py @@ -0,0 +1,3 @@ +class ArchMgrAURPackages: + def __init__(self) -> None: + pass diff --git a/archmgr/config/pkgs/aur/aur_helper.py b/archmgr/config/pkgs/aur/aur_helper.py new file mode 100644 index 0000000..f2ee4d4 --- /dev/null +++ b/archmgr/config/pkgs/aur/aur_helper.py @@ -0,0 +1,40 @@ +import subprocess as sp +from typing import List + +from util.input import password + + +def uninstall_package_list(pkgs: List[str]) -> bool: + """Uninstall all packages in the list + + Args: + pkgs: A list of packages to uninstall + + Returns: + True if successful, False otherwise + """ + # TODO: Add guard to protect against uninstalling archmgr and confirm uninstalling crucial pkgs + # pkgs.index("archmgr") + # TODO: Consider if we want to print out stdout and stderr on err + return run_pkg_manager_cmd(["-Rs", *pkgs], True).returncode == 0 + + +def install_package_list(pkgs: List[str]) -> bool: + """Install all packages in the list + + Args: + pkgs: A list of packages to install + """ + return run_pkg_manager_cmd(["-S", *pkgs], True).returncode == 0 + + +def run_pkg_manager_cmd( + args: List[str], use_sudo: bool = False +) -> sp.CompletedProcess[str]: + if use_sudo: + pw = password() + return sp.run( + ["yay", "--noconfirm", *args], capture_output=True, text=True, input=pw + ) + else: + return sp.run(["yay", "--noconfirm", *args], capture_output=True, text=True) diff --git a/archmgr/config/pkgs/aur/custom.py b/archmgr/config/pkgs/aur/custom.py new file mode 100644 index 0000000..388748b --- /dev/null +++ b/archmgr/config/pkgs/aur/custom.py @@ -0,0 +1,13 @@ +class AURPackage: + def __init__(self, name: str) -> None: + self._name = name + self._deps: list[str] = [] + + def add_aur_dep(self, name: str) -> None: + self._deps.append(name) + + def get_pkg_name(self) -> str: + return self._name + + def get_deps(self) -> list[str]: + return self._deps diff --git a/archmgr/config/pkgs/repos/__init__.py b/archmgr/config/pkgs/repos/__init__.py new file mode 100644 index 0000000..3a99dc3 --- /dev/null +++ b/archmgr/config/pkgs/repos/__init__.py @@ -0,0 +1,3 @@ +class ArchMgrRepoPkgs: + def __init__(self) -> None: + pass diff --git a/archmgr/pyproject.toml b/archmgr/pyproject.toml new file mode 100644 index 0000000..a9a9a8e --- /dev/null +++ b/archmgr/pyproject.toml @@ -0,0 +1,10 @@ +[project] +name = "archmgr" +version = "0.1.0" +dependencies = [ + "pyaml" +] + +[build-system] +requires = ["setuptools >= 77.0.3"] +build-backend = "setuptools.build_meta" diff --git a/archmgr/setup.py b/archmgr/setup.py new file mode 100644 index 0000000..e69de29 diff --git a/archmgr/util/pacman.py b/archmgr/util/pacman.py index 9ec4ced..c5e1ebb 100644 --- a/archmgr/util/pacman.py +++ b/archmgr/util/pacman.py @@ -3,8 +3,6 @@ from typing import List from util.input import password -pkg_manager = ["yay", "--noconfirm"] - def list_explicitly_installed() -> List[str]: """List all packages explicitly installed @@ -59,6 +57,11 @@ def run_pkg_manager_cmd( ) -> sp.CompletedProcess[str]: if use_sudo: pw = password() - return sp.run([*pkg_manager, *args], capture_output=True, text=True, input=pw) + return sp.run( + ["sudo", "-S", "pacman", "--noconfirm", *args], + capture_output=True, + text=True, + input=pw, + ) else: - return sp.run([*pkg_manager, *args], capture_output=True, text=True) + return sp.run(["pacman", "--noconfirm", *args], capture_output=True, text=True) diff --git a/notes.md b/notes.md index 54bc6bd..9c6c9c5 100644 --- a/notes.md +++ b/notes.md @@ -3,5 +3,28 @@ In python, using functions and args for them +### Packages config +#### Repos +- Just use pacman with the list + +#### AUR +Users can choose to either use yay (less secure, but easier, using `archmgr.pkgs.aur.add_aur_helper_package`, does not do any checks on the PKGBUILDs) or +**Explicit management:** +- User provides package (by creating `archmgr.pkgs.aur.AURPackage` class) and adding its AUR deps. Other deps are resolved automatically +- Send the package class to the manager using `archmgr.pkgs.aur.add_aur_package` +- In the future will provide a function that will do the dep resolution automatically. +- For each and its deps, it will analyze the PKGBUILD for common malware issues. Also add option to display all PKGBUILDs before building + +### Commands +- Run the command on the specified hook + +### Templates +- Use pystache to replace elements + +### Themes +- Use python-colorthief to extract palette +- Add those as named elements to the templates list + + ## Init - Copy diff --git a/test.py b/test.py index 681437e..3256975 100644 --- a/test.py +++ b/test.py @@ -1 +1,3 @@ import archmgr + +archmgr.create_config()