From e9046a96f1edd2d52594785998d90a14d10a5803 Mon Sep 17 00:00:00 2001 From: huker667 Date: Sun, 10 May 2026 09:51:20 +0300 Subject: init commit v0.7 --- qulay.py | 126 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100755 qulay.py (limited to 'qulay.py') diff --git a/qulay.py b/qulay.py new file mode 100755 index 0000000..86ce457 --- /dev/null +++ b/qulay.py @@ -0,0 +1,126 @@ +#!/usr/bin/env python3 + +import package +import database +import signal +import sys +import os + +from pathlib import Path +from logs import info, warn, error + + +_NAME = os.path.basename(sys.argv[0]) +_VERSION = "0.4" +_HELP_TEXT = f"""{_NAME}: command-line interface to the Qulay Package Manager +Usage: + {_NAME} h -> help menu + {_NAME} + pkg -> download and install package + {_NAME} - pkg -> remove package + {_NAME} g pkg -> get package version + {_NAME} s pkg -> search packages in repos + {_NAME} u -> update all repositories + {_NAME} i -> init Qulay PM + {_NAME} r -> get all repositories URLs + {_NAME} q -> get all installed packages + {_NAME} v -> get {_NAME} version +Options: + :v -> verbose output + :a -> ask before doing + :nl -> disable recording in databases and logs + :nd -> do not download deps + :r -> reinstall already installed deps +Vars: + DESTDIR -> path where the package will be installed/removed""" + +all_commands_list = ["h", "+", "-", "g", "u", "w", "i", "r", "q", "v", "s"] +allowed_args = [":v", ":a", ":nl", ":nd", ":r"] +def handle_ctrl_c(signum, frame): + warn("\nw! canceled by the user", True, ":nl" in sys.argv) + sys.exit(130) + +signal.signal(signal.SIGINT, handle_ctrl_c) + +def parse_args(args, mode): + return_args = [] + for arg in args: + if mode == "c": + if not arg.startswith(":"): + return_args += [arg] + elif mode == "a": + if arg.startswith(":"): + return_args += [arg] + elif mode == "o": + in_cmds = arg in all_commands_list + is_name = arg == sys.argv[0] + if not arg.startswith(":") and not in_cmds and not is_name: + return_args += [arg] + return return_args + +if __name__ == "__main__": + args = parse_args(sys.argv, "a") + cmds = parse_args(sys.argv, "c") + oths = parse_args(sys.argv, "o") + dest_dir = Path(os.environ.get("DESTDIR") or "/").resolve() + root_cmds = ["+", "-", "u", "i", "w"] + + if len(cmds) < 2: + print(_HELP_TEXT) + sys.exit(1) + + if cmds[1] in root_cmds: + if os.geteuid() != 0: + error("!! not enough rights. run this with root privileges.", True, ":nl" in args) + sys.exit(1) + + if cmds[1] == "+": + for pkg in oths: + package.install(pkg, args=args, dest_dir=dest_dir) + elif cmds[1] == "-": + for pkg in oths: + package.remove(pkg, args=args, dest_dir=dest_dir) + elif cmds[1] == "u": + database.download_repos(database.get_repos_urls()) + elif cmds[1] == "g": + if len(cmds) > 2: + print(database.get_version_package(cmds[2])[0]) + else: + error("!! package is not specified", True, ":nl" in args) + elif cmds[1] == "i": + database.ensure_database(verbose=":v" in args, ask=":a" in args, dest_dir=dest_dir) + elif cmds[1] == "r": + for url in database.get_repos_urls(): + print(url.strip()) + elif cmds[1] == "q": + for name, data in database._read_installed(dest_dir=dest_dir).items(): + print(f"{name} - {data[0]}") + elif cmds[1] == "s": + if len(cmds) > 2: + for name in oths: + if "/" in name: + parts = name.split("/", 1) + if parts[0] == "" or parts[1] == "": + continue + repo_name, name = parts[0], parts[1] + pkgs = package._find_package(name, dest_dir=dest_dir) + pkgs = [package._find_repo_package(pkgs, repo_name, name)] + else: + pkgs = package._find_package(name, dest_dir=dest_dir) + if not pkgs: + continue + for pkg in pkgs: + if database.is_installed(f"{pkg['repo']}/{pkg['name']}", dest_dir=dest_dir): + print(f"[+] {pkg['repo']}/{pkg['name']} - {pkg['data'][0]} - {pkg['data'][1]}") + else: + print(f" {pkg['repo']}/{pkg['name']} - {pkg['data'][0]} - {pkg['data'][1]}") + else: + pkgs = package._get_packages(dest_dir=dest_dir) + for pkg in pkgs: + if database.is_installed(f"{pkg['repo']}/{pkg['name']}", dest_dir=dest_dir): + print(f"[+] {pkg['repo']}/{pkg['name']} - {pkg['data'][0]} - {pkg['data'][1]}") + else: + print(f" {pkg['repo']}/{pkg['name']} - {pkg['data'][0]} - {pkg['data'][1]}") + elif cmds[1] == "v": + print(f"{_NAME}: {_VERSION}") + else: + print(_HELP_TEXT) -- cgit v1.3.1