From 4734744f596d8b8cd6f041e963665eff85f340ef Mon Sep 17 00:00:00 2001 From: SpookyDervish Date: Sat, 20 Jun 2026 12:08:01 +1000 Subject: [PATCH] list installed rocks --- neb/src/install.py | 35 ++++++++++++++++------------------- neb/src/list.py | 30 ++++++++++++++++++++++++++++++ neb/src/main.py | 6 ++++++ neb/src/util.py | 32 ++++++++++++++++++-------------- 4 files changed, 70 insertions(+), 33 deletions(-) create mode 100644 neb/src/list.py diff --git a/neb/src/install.py b/neb/src/install.py index 288fa27..39feb0f 100644 --- a/neb/src/install.py +++ b/neb/src/install.py @@ -1,5 +1,5 @@ from .console import print_error_message, console -from .util import ensure_libs_env, comet_dir, get_package_index +from .util import libs_dir, comet_dir, get_package_index import tempfile import subprocess @@ -11,7 +11,7 @@ import glob def install(args): - ensure_libs_env() + comet_libs_dir = libs_dir() # install each package in given list for name in args.names: @@ -37,12 +37,13 @@ def install(args): status.update(f"Downloading [b]{name}[/]...", spinner="moon") with tempfile.TemporaryDirectory() as temp_dir: + os.chdir(temp_dir) result = subprocess.run(["git", "clone", package["repository"], temp_dir], stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.DEVNULL) if result.returncode != 0: print_error_message(f"Failed to download \"{name}\": \"{result.stderr.decode()}\"") sys.exit(1) - console.print(f"[b][:white_check_mark:] Downloaded [green]{name}[/green].[/]") + console.log(f"[d][:white_check_mark:] Downloaded {name}.[/]") status.update(f"Installing [b]{name}[/]...") rock_file = os.path.join(temp_dir, "rock.json") @@ -60,20 +61,12 @@ def install(args): # build source code rock_info = data.get("rock", {}) - libs_path = os.getenv("COMET_LIBS") - out_path = os.path.join(libs_path, f"{name}.cometlib") - - - - status.stop() - console.print("You may need to type your admin password: ") + out_path = os.path.join(comet_libs_dir, f"{name}.cometlib") + try: - if not os.path.isdir(libs_path): - subprocess.run(["sudo", "mkdir", libs_path], check=True, stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE) - os.chdir(temp_dir) subprocess.run( - ["sudo", "gcc"] + glob.glob("src/*.c", recursive=True) + ["-fPIC", "-shared", "-Wl,-undefined,symbol_lookup", "-o", out_path] + rock_info.get("gccArgs", []), + ["gcc"] + glob.glob("src/*.c", recursive=True) + ["-fPIC", "-shared", "-Wl,-undefined,symbol_lookup", "-o", out_path] + rock_info.get("gccArgs", []), stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE, @@ -85,17 +78,21 @@ def install(args): except subprocess.CalledProcessError as e: print_error_message(f"Failed to install [b]{name}[/]: build failed: \"{e.stderr.decode()}\"") sys.exit(1) + console.log(f"[d][:white_check_mark:] Built {name}.[/]") - data_path = os.path.join(libs_path, "lib_data") + data_path = os.path.join(comet_libs_dir, "lib_data") + # this feels really fragile but who caresssss.... lib_data_path = os.path.join(data_path, name) if not os.path.isdir(lib_data_path): - subprocess.run(["sudo", "mkdir", "-p", lib_data_path], check=True, stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE) + subprocess.run(["mkdir", "-p", lib_data_path], check=True, stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE) - subprocess.run(["sudo", "cp", os.path.join(temp_dir, "rock.json"), os.path.join(lib_data_path, "rock.json")], check=True) + subprocess.run(["cp", os.path.join(temp_dir, "rock.json"), os.path.join(lib_data_path, "rock.json")], check=True) docs_path = os.path.join(temp_dir, "docs/") if os.path.isdir(docs_path): - subprocess.run(["sudo", "cp", "-R", docs_path, os.path.join(lib_data_path, "docs/")], check=True) + subprocess.run(["cp", "-R", docs_path, os.path.join(lib_data_path, "docs/")], check=True) + console.log(f"[d][:white_check_mark:] Copied data for {name}.[/]") - console.print(f"[b][:white_check_mark:] Installed [green]{name}[/green]![/b]") \ No newline at end of file + + console.log(f"[b][:white_check_mark:] Installed [green]{name}[/green]![/b]") \ No newline at end of file diff --git a/neb/src/list.py b/neb/src/list.py new file mode 100644 index 0000000..0a02d8e --- /dev/null +++ b/neb/src/list.py @@ -0,0 +1,30 @@ +from .console import console +from .util import libs_dir + +from rich.box import ROUNDED +from rich.table import Table + +import json +import os + + +def list_packages(args) -> None: + packages_table = Table("Name", "Version", "Description", "Author", box=ROUNDED, header_style="bold blue", ) + + data_dir = os.path.join(libs_dir(), "lib_data/") + libs = os.listdir(data_dir) + + for name in libs: + lib_data_dir = os.path.join(data_dir, name) + rock_file = os.path.join(lib_data_dir, "rock.json") + + json_data = {} + try: + with open(rock_file, "r") as f: + json_data = json.load(f)["rock"] + + packages_table.add_row(json_data["name"], json_data["version"], json_data.get("description", ""), json_data.get("author", "")) + except (json.JSONDecodeError, FileNotFoundError, KeyError) as e: + continue + + console.print(packages_table) \ No newline at end of file diff --git a/neb/src/main.py b/neb/src/main.py index b7683f8..0812ac3 100644 --- a/neb/src/main.py +++ b/neb/src/main.py @@ -4,6 +4,7 @@ import os from .install import install from .pull import pull +from .list import list_packages __VERSION__ = "1.0.0" @@ -25,6 +26,9 @@ def main() -> int: # pull command pull_cmd = sub_parsers.add_parser(name="pull", description="pull rock index") + # list command + list_cmd = sub_parsers.add_parser(name="list", description="list installed rocks") + args = arg_parser.parse_args() # do different things based on args @@ -37,6 +41,8 @@ def main() -> int: install(args) case "pull": pull(args) + case "list": + list_packages(args) # really feeling like a C programmer lmao return 0 diff --git a/neb/src/util.py b/neb/src/util.py index 8b7817c..ab4e215 100644 --- a/neb/src/util.py +++ b/neb/src/util.py @@ -19,14 +19,14 @@ def get_needed_headers() -> bool: if not should_continue: return False - with console.status("Cloning git repo...", spinner="moon") as status: + with console.status("Cloning Comet repo...", spinner="moon") as status: with tempfile.TemporaryDirectory() as temp_dir: repo_url = "https://chookspace.com/Comet/Comet" result = subprocess.run(["git", "clone", repo_url, temp_dir], stdout=subprocess.PIPE, stderr=subprocess.PIPE) if result.returncode != 0: print_error_message(f"failed to get the Comet repository: {result.stderr.decode()}") - console.print("[d][:white_check_mark:] Cloned repo.[/]") + console.log("[d][:white_check_mark:] Cloned Comet repo.[/]") os.chdir(temp_dir) @@ -34,7 +34,7 @@ def get_needed_headers() -> bool: result = subprocess.run(["make"], check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) if result.returncode != 0: print_error_message(f"failed to build Comet: {result.stderr.decode()}") - console.print("[d][:white_check_mark:] Built Comet.[/]") + console.log("[d][:white_check_mark:] Built Comet.[/]") status.update("Installing...") status.stop() @@ -43,8 +43,10 @@ def get_needed_headers() -> bool: if result.returncode != 0: print_error_message(f"failed to install: {result.stderr.decode()}") - console.print("[d][:white_check_mark:] Installed headers.[/]") - console.print("[b][green]Comet headers are installed![/green] [:white_check_mark:][/b]\n") + console.log("[d][:white_check_mark:] Installed headers.[/]") + console.log("[b][:white_check_mark:] Comet headers are installed![/b]\n") + + return True def update_package_index() -> dict: with console.status("Downloading package index...", spinner="moon") as status: @@ -53,7 +55,7 @@ def update_package_index() -> dict: print_error_message(f"Failed to download package index: {package_data.reason}") sys.exit(1) - console.print("[d][:white_check_mark:] Downloaded package index.[/]") + console.log("[d][:white_check_mark:] Downloaded package index.[/]") status.update("Saving package index...") data = package_data.json() @@ -61,7 +63,7 @@ def update_package_index() -> dict: with open(os.path.join(comet_dir(), "package_index.json"), "w") as f: json.dump(data, f) - console.print("[b][:white_check_mark:] [green]Done pulling package index![/green][/b]") + console.log("[b][:white_check_mark:] Done pulling package index![/b]") return data @@ -105,11 +107,13 @@ def ensure_includes_exist() -> list[str]: return True -def ensure_libs_env() -> None: - if not os.getenv("COMET_LIBS"): - default_loc = "/usr/lib/comet" - os.environ["COMET_LIBS"] = default_loc - console.print(f"[b cyan]note:[/] Using default install location ({default_loc}). Set the $COMET_LIBS variable to silence this.") - +def libs_dir() -> str: + if not ensure_includes_exist(): - exit(0) \ No newline at end of file + exit(0) + + comet_libs_dir = os.path.join(comet_dir(), "libs/") + if not os.path.isdir(comet_libs_dir): + os.mkdir(comet_libs_dir) + + return comet_libs_dir \ No newline at end of file