From 6394e9d1192e6171f6497675bad68bc1cb353084 Mon Sep 17 00:00:00 2001 From: davidovski Date: Wed, 22 Dec 2021 22:12:13 +0000 Subject: added info, search and file queries --- src/verbs/file.py | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++ src/verbs/info.py | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/verbs/search.py | 38 ++++++++++++++++++++++++++++++++ src/xi.py | 8 ++++--- xipkg.conf | 4 +--- 5 files changed, 167 insertions(+), 6 deletions(-) create mode 100644 src/verbs/file.py create mode 100644 src/verbs/info.py create mode 100644 src/verbs/search.py diff --git a/src/verbs/file.py b/src/verbs/file.py new file mode 100644 index 0000000..008635f --- /dev/null +++ b/src/verbs/file.py @@ -0,0 +1,62 @@ +import os +import colors +import util +import shutil + +import re + +from verbs.sync import sync +from verbs.search import list_repos + +# since we symlink /bin to /usr, we should make sure we are always looking for the same place +def condition_file(file_path): + file_path = re.sub("^/bin", "/usr/bin", file_path) + file_path = re.sub("^/sbin", "/usr/bin", file_path) + file_path = re.sub("^/usr/sbin", "/usr/bin", file_path) + file_path = re.sub("^/lib", "/usr/lib", file_path) + file_path = re.sub("^/lib64", "/usr/lib", file_path) + file_path = re.sub("^/usr/lib64", "/usr/lib", file_path) + return file_path + +def absolute_path(file_path, root="/"): + if file_path[0] == "/": + return file_path + else: + root_path = os.path.realpath(root) + file_path = os.path.realpath(file_path) + # this is a bad way of doing this + file_path = file_path.replace(root_path, "") + return file_path + +def list_files(package_name, config, root="/"): + file_list = util.add_path(root, config["dir"]["installed"], package_name, "files") + if os.path.exists(file_list): + with open(file_list, "r") as file: + return [condition_file(line.strip()) for line in file] + else: + return [] + +def list_all_files(config, root="/"): + packages = [ p.split("/")[-1] for p in list_repos(config["repos"], config["dir"]["packages"], config["dir"]["sources"])] + file_list = {} + for package in packages: + file_list[package] = list_files(package, config, root=root) + return file_list + +def file(args, options, config): + if len(args) > 0: + file_list = list_all_files(config, options["r"]) + for file in args: + file = condition_file(absolute_path(file, options["r"])) + found = False + for package, files in file_list.items(): + if file in files: + found = True + print(colors.LIGHT_CYAN + file, colors.CYAN + "belongs to", colors.LIGHT_CYAN + package) + break + if not found: + print(colors.RED + "Could not determine which package owns " + colors.LIGHT_CYAN + file) + + + else: + print(colors.LIGHT_RED + "Nothing to do") diff --git a/src/verbs/info.py b/src/verbs/info.py new file mode 100644 index 0000000..90cf558 --- /dev/null +++ b/src/verbs/info.py @@ -0,0 +1,61 @@ +import os +import colors +import util +import shutil + +from verbs.install import find_package, retrieve_package_info, is_installed +from verbs.sync import sync + +def get_installed_info(package, config, options): + installed_info = {} + + info_file = util.add_path(options["r"], config["dir"]["installed"], package, "info") + with open(info_file, "r") as file: + for line in file: + line = line.strip() + key = line.split("=")[0] + value = "=".join(line.split("=")[1:]) + + installed_info[key] = value + + return installed_info + + +def info(args, options, config): + if not options["l"]: + sync(args, options, config) + + if len(args) > 0: + for package in args: + checksum, sources, repo = find_package(package, config["repos"], config["dir"]["packages"], config["sources"]) + + if not checksum is None: + info = retrieve_package_info( + sources, checksum, package, config, + verbose=options["v"], skip_verification=options["u"] + ) + installed = is_installed(package, config, options["r"]) + installed_info = get_installed_info(package, config, options) if installed else {} + + print(colors.CYAN + f"Information for {package}:") + print(colors.CYAN + "\tName: " + colors.LIGHT_CYAN + f"{info['NAME']}") + print(colors.CYAN + "\tDescription: " + colors.LIGHT_CYAN + f"{info['DESCRIPTION']}") + print(colors.CYAN + "\tRepo: " + colors.LIGHT_CYAN + f"{repo}") + print(colors.CYAN + "\tChecksum: " + colors.LIGHT_CYAN + f"{info['CHECKSUM']}") + print(colors.CYAN + "\tVersion Hash: " + colors.LIGHT_CYAN + f"{info['VER_HASH']}") + print(colors.CYAN + "\tBuild Date: " + colors.LIGHT_CYAN + f"{info['DATE']}") + print(colors.CYAN + "\tSource: " + colors.LIGHT_CYAN + f"{info['SOURCE']}") + print(colors.CYAN + "\tDependencies: " + colors.LIGHT_CYAN + f"{info['DEPS']}") + print(colors.CYAN + "\tInstalled: " + colors.LIGHT_CYAN + f"{installed}") + + if installed: + print(colors.CYAN + "\t\tDate: " + colors.LIGHT_CYAN + f"{installed_info['INSTALL_DATE']}") + print(colors.CYAN + "\t\tChecksum: " + colors.LIGHT_CYAN + f"{installed_info['CHECKSUM']}") + print(colors.CYAN + "\t\tURL: " + colors.LIGHT_CYAN + f"{installed_info['URL']}") + print(colors.CYAN + "\t\tValidation Key: " + colors.LIGHT_CYAN + f"{installed_info['KEY']}") + + + else: + print(colors.RED + f"Package {package} could not be found") + + diff --git a/src/verbs/search.py b/src/verbs/search.py new file mode 100644 index 0000000..b67f5a1 --- /dev/null +++ b/src/verbs/search.py @@ -0,0 +1,38 @@ +import os +import sys +import colors +import util +import shutil + +from verbs.install import find_package, retrieve_package_info +from verbs.sync import sync + +def list_repos(repos, packages_dir, sources): + return [ + f"{repo}/{file}" for repo in repos for file in os.listdir(os.path.join(packages_dir, repo)) + ] + +def search(args, options, config): + if not options["l"]: + sync(args, options, config) + + if len(args) > 0: + packages = list_repos(config["repos"], config["dir"]["packages"], config["sources"]) + for package in args: + + # TODO fuzzy searching here + results = [p for p in packages if package.lower() in p.lower()] + + if len(results) > 0: + print(colors.GREEN + f"Search results for {package}:") + for r in results: + print(colors.LIGHT_GREEN + f"\t{r}") + + sys.exit(0) + else: + print(colors.RED + f"Package {package} could not be found") + sys.exit(1) + else: + print(colors.LIGHT_RED + "Nothing to do") + + diff --git a/src/xi.py b/src/xi.py index 96faa33..157fc22 100644 --- a/src/xi.py +++ b/src/xi.py @@ -4,15 +4,17 @@ import util import colors from verbs.sync import sync +from verbs.file import file +from verbs.search import search +from verbs.info import info from verbs.remove import remove from verbs.install import install from verbs.update import update -def search(): - pass - verbs = { v: globals()[v] for v in [ "search", + "file", + "info", "update", "install", "remove", diff --git a/xipkg.conf b/xipkg.conf index 01488e3..992f20a 100644 --- a/xipkg.conf +++ b/xipkg.conf @@ -3,13 +3,11 @@ include /etc/xipkg.d/default.conf sources { - localhost http://localhost:8089/repo/ # this is for testing + localhost http://localhost:8089/repo/ davidovski https://xi.davidovski.xyz/repo/ codeberg https://xi.codeberg.page/repo/ ftp https://xilinux.ftp.sh/repo/ - ix https://xilinux.ix.tc/repo/ ro https://xi.ro.lt/repo/ - invalid https://xilinux.invalid/repo/ } # The sources to download the keys from -- cgit v1.2.1