Commit 39afbd2037bc3899c96a285bc3b558e844c69305
Commits[COMMIT BEGIN]commit 39afbd2037bc3899c96a285bc3b558e844c69305 Author: 0x4248 <[email protected]> Date: Thu Apr 16 21:52:30 2026 +0100 npkg-testing: remove due to bad design diff --git a/doc/TRX/TRX-26-0004.txt b/doc/TRX/TRX-26-0004.txt new file mode 100644 index 0000000..a64f0f5 --- /dev/null +++ b/doc/TRX/TRX-26-0004.txt @@ -0,0 +1,63 @@ + HYPER TEXT TRANSFER PROTOCOL 1.0 + TRX-26-0004 + 01/04/2026 +--------------------------------------------------------------------------- +TITLE: HYPER TEXT TRANSFER PROTOCOL 1.0 +DOCUMENT ID: TRX-26-0004 +REVISION: A1 +CATEGORY: DESIGN AND PROTOCOL +COPYRIGHTS: (C) 2026 0x4248. CC BY-SA 4.0. +USAGE RIGHTS: All rights given under CC BY-SA 4.0 +LICENSE: CC BY-SA 4.0 + +DATE CREATED: INSERT +DATE REVISED: INSERT + +THIS TRX IS A ALREADY STANDARDIZED PROTOCOL AND IS NOT CONTROLLED BY THE +WRITER OF THIS TECHNICAL RECORD FILE. + +--------------------------------------------------------------------------- +REVISION HISTORY +--------------------------------------------------------------------------- +REVISION DATE NOTES +A1 04/01/2026 Initial creation of record. + +--------------------------------------------------------------------------- +CONTENTS +--------------------------------------------------------------------------- + +1.0 INSERT +2.0 REFERENCES +3.0 SIGNATURES + +--------------------------------------------------------------------------- +ABSTRACT +--------------------------------------------------------------------------- + +Hyper Text Transfer Protocol (HTTP) is an application layer protocol for +distributed, collaborative, hypermedia information systems. HTTP is the +foundation of data communication for the World Wide Web, where hypertext files +are interlinked and accessed via the Internet. + +HTTP was developed in CERN in 1989 by Tim Berners-Lee and his team. It has since +evolved through several versions and now is a solid standard for web +communication. + +--------------------------------------------------------------------------- +1.0 +--------------------------------------------------------------------------- + + +--------------------------------------------------------------------------- +2.0 REFERENCES +--------------------------------------------------------------------------- + +1. https://www.rfc-editor.org/rfc/rfc1945.txt +2. https://www.rfc-editor.org/rfc/rfc2616.txt +--------------------------------------------------------------------------- +3.0 SIGNATURES +--------------------------------------------------------------------------- + +Written By: 0x4248 <0x4248.dev> DD/MM/YYYY +Reviewed By: INSERT DD/MM/YYYY +Approved By: INSERT DD/MM/YYYY \ No newline at end of file diff --git a/doc/linux-ref/docs/chapters/03-programming/00-part.md b/doc/linux-ref/docs/chapters/03-programming/00-part.md new file mode 100644 index 0000000..3eb2bda --- /dev/null +++ b/doc/linux-ref/docs/chapters/03-programming/00-part.md @@ -0,0 +1 @@ +# Part III: Programming \ No newline at end of file diff --git a/doc/linux-ref/docs/chapters/03-programming/01-asm.md b/doc/linux-ref/docs/chapters/03-programming/01-asm.md new file mode 100644 index 0000000..8dd6344 --- /dev/null +++ b/doc/linux-ref/docs/chapters/03-programming/01-asm.md @@ -0,0 +1,6 @@ +# Saying Hello to the World in Assembly + +In this chapter, we will have a crash course in programming an x86-64 linux +computer to say "Hello World" in assembly. Nothing dramatic, just a simple +program that prints "Hello World" to the terminal. + diff --git a/misc/www/html/afk.html b/misc/www/html/afk.html new file mode 100644 index 0000000..dae5216 --- /dev/null +++ b/misc/www/html/afk.html @@ -0,0 +1,68 @@ +<!DOCTYPE html> +<html lang="en"> +<head> +<meta charset="UTF-8"> +<meta name="viewport" content="width=device-width, initial-scale=1.0"> +<title>AFK</title> +<style> + body { + margin: 0; + overflow: hidden; + background: black; + } + #afk { + position: absolute; + color: white; + font-size: 5em; + font-family: Arial, sans-serif; + opacity: 0; + transition: opacity 1s ease, transform 1s ease; + transform: translate(0, 0); + pointer-events: none; + } +</style> +</head> +<body> + +<div id="afk"> + <h1>AFK</h1> + <p>Will be back soon</p> +</div> + +<script> +const afk = document.getElementById('afk'); + +function moveAFK() { + const rect = afk.getBoundingClientRect(); + + const maxX = window.innerWidth - rect.width; + const maxY = window.innerHeight - rect.height; + + const x = Math.random() * maxX; + const y = Math.random() * maxY; + + afk.style.transform = `translate(${x}px, ${y}px)`; +} + +function loop() { + // fade out + afk.style.opacity = 0; + + setTimeout(() => { + moveAFK(); + + // fade in after move + afk.style.opacity = 1; + }, 1000); +} + +// initial placement +moveAFK(); +afk.style.opacity = 1; + +// repeat cleanly +setInterval(loop, 5000); +</script> + +</body> +</html> \ No newline at end of file diff --git a/npkg-testing/.gitignore b/npkg-testing/.gitignore deleted file mode 100644 index 08eb0a0..0000000 --- a/npkg-testing/.gitignore +++ /dev/null @@ -1 +0,0 @@ -!bin/ \ No newline at end of file diff --git a/npkg-testing/README.md b/npkg-testing/README.md deleted file mode 100644 index 8009e69..0000000 --- a/npkg-testing/README.md +++ /dev/null @@ -1,48 +0,0 @@ -# NPKG Testing Workspace - -Flat, dev-first workspace for package migration experiments. - -The package CLI is `./npkg`, with package build artifacts in `./npkg-build/`. -Implementation modules live in `tools/npkg/*.py`. -Code and package folders live directly here so development stays simple. - -## Category Layout - -- `bin/` - user-facing binaries -- `sbin/` - admin/service binaries -- `toolkits/` - toolkit code and utilities -- `lib/public/` - public/installable libraries -- `lib/private/` - personal/internal libraries -- `lab/` - unstable prototypes -- `systems/` - system/platform-specific things (configs, patches, scripts) - -## Demo Package - -`bin/hello_world` builds a C binary and packages it as `/usr/bin/hello-world`. - -## Commands - -From repository root: - -```bash -./npkg list -./npkg installed -./npkg build hello-world -./npkg package hello-world -./npkg install hello-world -./npkg clean hello-world -./npkg uninstall hello-world -``` - -`build` compiles package sources only. -`package` creates `npkg-build/packages/<name>-<version>.tar.gz`. - -Default install root is `/opt/npkg`, so installs land under `/opt/npkg/usr/...`. -If `/opt/npkg` is not writable for your user, run install/uninstall with `sudo`. - -To run as `npkg ...` directly, symlink once: - -```bash -mkdir -p ~/.local/bin -ln -sf "$PWD/npkg" ~/.local/bin/npkg -``` diff --git a/npkg-testing/bin/hello_python/Makefile b/npkg-testing/bin/hello_python/Makefile deleted file mode 100644 index 73f85e7..0000000 --- a/npkg-testing/bin/hello_python/Makefile +++ /dev/null @@ -1,17 +0,0 @@ -# SPDX-License-Identifier: GPL-3.0 - -BIN = hello-python -DESTDIR ?= -INSTALL_PATH ?= /usr/bin/ - -.PHONY: all install clean - -all: - chmod +x $(BIN) - -install: all - install -d $(DESTDIR)$(INSTALL_PATH) - install -m 0755 $(BIN) $(DESTDIR)$(INSTALL_PATH)$(BIN) - -clean: - true diff --git a/npkg-testing/bin/hello_python/npkg.conf b/npkg-testing/bin/hello_python/npkg.conf deleted file mode 100644 index 4fe9e16..0000000 --- a/npkg-testing/bin/hello_python/npkg.conf +++ /dev/null @@ -1,13 +0,0 @@ -name = "hello-python" -version = "0.1.0" -description = "Tiny demo Python package that installs /usr/bin/hello-python" -install_path = "/usr/bin/" - -[build] -command = "make -C {package_dir} all" - -[package] -command = "make -C {package_dir} install DESTDIR={stage_dir} INSTALL_PATH={install_path}" - -[clean] -command = "make -C {package_dir} clean" diff --git a/npkg-testing/bin/hello_world/Makefile b/npkg-testing/bin/hello_world/Makefile deleted file mode 100644 index 4d4fd08..0000000 --- a/npkg-testing/bin/hello_world/Makefile +++ /dev/null @@ -1,29 +0,0 @@ -# SPDX-License-Identifier: GPL-3.0 - -CC ?= gcc -CFLAGS ?= -O2 -Wall - -PKG_NAME = hello-world -PKG_VERSION = 0.1.0 - -DESTDIR ?= -INSTALL_PATH ?= /usr/bin/ - -SRC = src/hello_world.c -BUILD_DIR = build -BIN = hello-world - -.PHONY: all clean install - -all: $(BUILD_DIR)/$(BIN) - -$(BUILD_DIR)/$(BIN): $(SRC) - @mkdir -p $(BUILD_DIR) - $(CC) $(CFLAGS) $(SRC) -o $(BUILD_DIR)/$(BIN) - -install: all - install -d $(DESTDIR)$(INSTALL_PATH) - install -m 0755 $(BUILD_DIR)/$(BIN) $(DESTDIR)$(INSTALL_PATH)$(BIN) - -clean: - rm -rf $(BUILD_DIR) diff --git a/npkg-testing/bin/hello_world/npkg.conf b/npkg-testing/bin/hello_world/npkg.conf deleted file mode 100644 index f60733f..0000000 --- a/npkg-testing/bin/hello_world/npkg.conf +++ /dev/null @@ -1,13 +0,0 @@ -name = "hello-world" -version = "0.1.0" -description = "Tiny demo C package that installs /usr/bin/hello-world" -install_path = "/usr/bin/" - -[build] -command = "make -C {package_dir} all" - -[package] -command = "make -C {package_dir} install DESTDIR={stage_dir} INSTALL_PATH={install_path}" - -[clean] -command = "make -C {package_dir} clean" \ No newline at end of file diff --git a/npkg-testing/bin/hello_world/src/hello_world.c b/npkg-testing/bin/hello_world/src/hello_world.c deleted file mode 100644 index fb98286..0000000 --- a/npkg-testing/bin/hello_world/src/hello_world.c +++ /dev/null @@ -1,6 +0,0 @@ -#include <stdio.h> - -int main(void) { - printf("hello from npkg-testing\n"); - return 0; -} diff --git a/npkg-testing/lab/README.md b/npkg-testing/lab/README.md deleted file mode 100644 index 23fe5f7..0000000 --- a/npkg-testing/lab/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# lab - -Unstable and in-progress experiments. diff --git a/npkg-testing/lib/private/README.md b/npkg-testing/lib/private/README.md deleted file mode 100644 index 8c180b1..0000000 --- a/npkg-testing/lib/private/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# private lib - -Internal/personal libraries not intended as public API. diff --git a/npkg-testing/lib/public/README.md b/npkg-testing/lib/public/README.md deleted file mode 100644 index f2b8c0b..0000000 --- a/npkg-testing/lib/public/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# public lib - -Installable/public-facing libraries. diff --git a/npkg-testing/npkg b/npkg-testing/npkg deleted file mode 100755 index c8fedb9..0000000 --- a/npkg-testing/npkg +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/env python3 - -import sys - -from tools.npkg.cli import main - - -if __name__ == "__main__": - raise SystemExit(main(sys.argv[1:])) \ No newline at end of file diff --git a/npkg-testing/sbin/README.md b/npkg-testing/sbin/README.md deleted file mode 100644 index e31a12c..0000000 --- a/npkg-testing/sbin/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# sbin - -Admin/service-oriented binaries for migration testing. diff --git a/npkg-testing/toolkits/README.md b/npkg-testing/toolkits/README.md deleted file mode 100644 index 74fb3f5..0000000 --- a/npkg-testing/toolkits/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# toolkits - -Toolkit projects and shared utilities for migration testing. diff --git a/npkg-testing/tools/__init__.py b/npkg-testing/tools/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/npkg-testing/tools/npkg/__init__.py b/npkg-testing/tools/npkg/__init__.py deleted file mode 100644 index ed32c05..0000000 --- a/npkg-testing/tools/npkg/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -from .cli import main - -__all__ = ["main"] diff --git a/npkg-testing/tools/npkg/archive.py b/npkg-testing/tools/npkg/archive.py deleted file mode 100644 index 88a34b6..0000000 --- a/npkg-testing/tools/npkg/archive.py +++ /dev/null @@ -1,70 +0,0 @@ -import shutil -import subprocess -import tarfile -from pathlib import Path -from typing import Dict, List, Optional - -from .console import info, ok -from .paths import package_archive_path, package_stage_dir, workspace_root -from .types import Package - - -def command_context(pkg: Package, stage_dir: Optional[Path] = None) -> Dict[str, str]: - context = { - "workspace_root": str(workspace_root()), - "npkg_root": str(workspace_root()), - "npkg_build_root": str(workspace_root() / "npkg-build"), - "package_dir": str(pkg.package_dir), - "install_path": pkg.install_path, - } - if stage_dir is not None: - context["stage_dir"] = str(stage_dir) - return context - - -def render_command(template: str, context: Dict[str, str]) -> str: - return template.format(**context) - - -def run_shell(command: str, cwd: Path) -> None: - result = subprocess.run(command, cwd=str(cwd), shell=True) - if result.returncode != 0: - raise RuntimeError(f"Command failed with exit code {result.returncode}: {command}") - - -def ensure_package_archive(pkg: Package) -> Path: - if not pkg.package_command: - raise RuntimeError(f"Package '{pkg.name}' does not define package.command") - - stage_dir = package_stage_dir(pkg) - archive_path = package_archive_path(pkg) - - shutil.rmtree(stage_dir, ignore_errors=True) - stage_dir.mkdir(parents=True, exist_ok=True) - - context = command_context(pkg, stage_dir=stage_dir) - package_command = render_command(pkg.package_command, context) - - info(f"staging {pkg.name} with: {package_command}") - run_shell(package_command, cwd=workspace_root()) - - archive_path.parent.mkdir(parents=True, exist_ok=True) - with tarfile.open(archive_path, "w:gz") as tar: - for item in sorted(stage_dir.iterdir()): - tar.add(item, arcname=item.name) - - ok(f"packaged {pkg.name} -> {archive_path}") - return archive_path - - -def extract_archive_into_root(archive_path: Path, install_root: Path) -> List[str]: - try: - with tarfile.open(archive_path, "r:gz") as tar: - member_names = [member.name for member in tar.getmembers() if member.name and member.name != "."] - try: - tar.extractall(path=install_root, filter="data") - except TypeError: - tar.extractall(path=install_root) - except (tarfile.TarError, OSError) as error: - raise RuntimeError(f"failed to install archive: {error}") from error - return member_names diff --git a/npkg-testing/tools/npkg/cli.py b/npkg-testing/tools/npkg/cli.py deleted file mode 100644 index 81d513c..0000000 --- a/npkg-testing/tools/npkg/cli.py +++ /dev/null @@ -1,98 +0,0 @@ -import argparse - -from .commands import ( - cmd_build, - cmd_clean, - cmd_install, - cmd_installed, - cmd_list, - cmd_package, - cmd_uninstall, -) -from .console import fail - - -def build_parser() -> argparse.ArgumentParser: - parser = argparse.ArgumentParser( - prog="npkg", - description="Simple package helper for the Nexus monorepo", - formatter_class=argparse.RawDescriptionHelpFormatter, - epilog=( - "Examples:\n" - " npkg list\n" - " npkg build hello-world\n" - " npkg build '*'\n" - " npkg package hello-world\n" - " npkg install hello-world\n" - " npkg clean '*'\n" - " npkg installed\n" - " npkg uninstall hello-world" - ), - ) - - sub = parser.add_subparsers(dest="command", required=True) - - list_parser = sub.add_parser("list", help="List available packages") - list_parser.set_defaults(func=cmd_list) - - build_parser = sub.add_parser("build", help="Build package(s) (supports wildcards)") - build_parser.add_argument( - "packages", - nargs="+", - help="Package selectors (name/path or wildcards like '*', 'hello-*', 'bin/*')", - ) - build_parser.set_defaults(func=cmd_build) - - package_parser = sub.add_parser("package", help="Create package archive(s) (.tar.gz, supports wildcards)") - package_parser.add_argument( - "packages", - nargs="+", - help="Package selectors (name/path or wildcards like '*', 'hello-*', 'bin/*')", - ) - package_parser.set_defaults(func=cmd_package) - - install_parser = sub.add_parser("install", help="Install a package") - install_parser.add_argument("package", help="Package name or package directory path") - install_parser.add_argument( - "--root", - default="/opt/npkg", - help="Installation root directory (default: /opt/npkg)", - ) - install_parser.set_defaults(func=cmd_install) - - clean_parser = sub.add_parser("clean", help="Run package clean command (supports wildcards)") - clean_parser.add_argument( - "packages", - nargs="+", - help="Package selectors (name/path or wildcards like '*', 'hello-*', 'bin/*')", - ) - clean_parser.set_defaults(func=cmd_clean) - - installed_parser = sub.add_parser("installed", help="List installed packages from manifest database") - installed_parser.add_argument( - "--root", - default="/opt/npkg", - help="Installation root directory (default: /opt/npkg)", - ) - installed_parser.set_defaults(func=cmd_installed) - - uninstall_parser = sub.add_parser("uninstall", help="Uninstall a package") - uninstall_parser.add_argument("package", help="Package name") - uninstall_parser.add_argument( - "--root", - default="/opt/npkg", - help="Installation root directory (default: /opt/npkg)", - ) - uninstall_parser.set_defaults(func=cmd_uninstall) - - return parser - - -def main(argv: list[str] | None = None) -> int: - parser = build_parser() - args = parser.parse_args(argv) - try: - return int(args.func(args)) - except ValueError as error: - fail(str(error)) - return 2 diff --git a/npkg-testing/tools/npkg/commands.py b/npkg-testing/tools/npkg/commands.py deleted file mode 100644 index 4b9d742..0000000 --- a/npkg-testing/tools/npkg/commands.py +++ /dev/null @@ -1,231 +0,0 @@ -from pathlib import Path -import fnmatch - -from .archive import command_context, ensure_package_archive, extract_archive_into_root, render_command, run_shell -from .console import fail, info, ok, style, warn -from .install_db import load_installed_rows, uninstall_from_manifest, write_install_manifest -from .metadata import discover_packages, select_package -from .paths import workspace_root - - -def resolve_package_selectors(packages, selectors): - root = workspace_root() - matched: list = [] - seen = set() - had_selector_miss = False - - for selector in selectors: - selector = selector.strip() - if not selector: - continue - - wildcard = any(token in selector for token in "*?[") - local_matches = [] - - if wildcard: - for pkg in packages.values(): - rel_dir = str(pkg.package_dir.relative_to(root)) - if fnmatch.fnmatch(pkg.name, selector) or fnmatch.fnmatch(rel_dir, selector): - local_matches.append(pkg) - else: - try: - local_matches.append(select_package(packages, selector)) - except KeyError: - normalized_selector = selector.strip().strip("/") - for pkg in packages.values(): - rel_dir = str(pkg.package_dir.relative_to(root)) - if rel_dir == normalized_selector or rel_dir.startswith(f"{normalized_selector}/"): - local_matches.append(pkg) - - if not local_matches: - normalized_selector = selector.strip().strip("/") - selector_exists = (root / normalized_selector).exists() if normalized_selector else False - if wildcard or not selector_exists: - warn(f"no packages matched selector: {selector}") - had_selector_miss = True - continue - - for pkg in local_matches: - if pkg.name in seen: - continue - seen.add(pkg.name) - matched.append(pkg) - - return matched, had_selector_miss - - -def cmd_list(_args) -> int: - packages = discover_packages() - print(style("NPKG packages", bold=True)) - if not packages: - warn("no packages found") - return 0 - - for pkg in packages.values(): - flags = [] - if pkg.build_command: - flags.append("build") - if pkg.package_command: - flags.append("install") - if pkg.clean_command: - flags.append("clean") - if not flags: - flags.append("meta-only") - - rel_dir = pkg.package_dir.relative_to(workspace_root()) - print( - f" {style(pkg.name, bold=True)} {pkg.version} " - f"[{', '.join(flags)}] {rel_dir}" - ) - if pkg.description: - print(f" {pkg.description}") - - return 0 - - -def cmd_build(args) -> int: - packages = discover_packages() - matched, had_selector_miss = resolve_package_selectors(packages, args.packages) - if not matched: - return 2 - - had_failures = False - for pkg in matched: - if not pkg.build_command: - warn(f"skipping {pkg.name}: build.command is not defined") - had_failures = True - continue - - command = render_command(pkg.build_command, command_context(pkg)) - info(f"building {pkg.name} with: {command}") - try: - run_shell(command, cwd=workspace_root()) - except RuntimeError as error: - warn(f"failed to build {pkg.name}: {error}") - had_failures = True - continue - - ok(f"built {pkg.name}") - - return 1 if (had_failures or had_selector_miss) else 0 - - -def cmd_package(args) -> int: - packages = discover_packages() - matched, had_selector_miss = resolve_package_selectors(packages, args.packages) - if not matched: - return 2 - - had_failures = False - for pkg in matched: - try: - archive_path = ensure_package_archive(pkg) - except RuntimeError as error: - warn(f"failed to package {pkg.name}: {error}") - had_failures = True - continue - - ok(f"package archive ready: {archive_path}") - - return 1 if (had_failures or had_selector_miss) else 0 - - -def cmd_install(args) -> int: - packages = discover_packages() - try: - pkg = select_package(packages, args.package) - except KeyError: - fail(f"package not found: {args.package}") - return 2 - - install_root = Path(args.root).expanduser().resolve() - try: - archive_path = ensure_package_archive(pkg) - except RuntimeError as error: - fail(str(error)) - return 2 - - install_root.mkdir(parents=True, exist_ok=True) - info(f"installing {pkg.name} into {install_root}") - try: - member_names = extract_archive_into_root(archive_path, install_root) - except RuntimeError as error: - fail(str(error)) - return 1 - - write_install_manifest(pkg, install_root, member_names) - ok(f"installed {pkg.name} -> {install_root}") - return 0 - - -def cmd_clean(args) -> int: - packages = discover_packages() - root = workspace_root() - matched, had_selector_miss = resolve_package_selectors(packages, args.packages) - if not matched: - return 2 - - had_failures = False - for pkg in matched: - if not pkg.clean_command: - warn(f"skipping {pkg.name}: clean.command is not defined") - had_failures = True - continue - - command = render_command(pkg.clean_command, command_context(pkg)) - info(f"cleaning {pkg.name} with: {command}") - try: - run_shell(command, cwd=root) - except RuntimeError as error: - warn(f"failed to clean {pkg.name}: {error}") - had_failures = True - continue - - ok(f"cleaned {pkg.name}") - - return 1 if (had_failures or had_selector_miss) else 0 - - -def cmd_uninstall(args) -> int: - packages = discover_packages() - pkg_name = args.package - if pkg_name in packages: - pkg_name = packages[pkg_name].name - else: - try: - pkg_name = select_package(packages, args.package).name - except KeyError: - pkg_name = args.package - - install_root = Path(args.root).expanduser().resolve() - info(f"uninstalling {pkg_name} from {install_root}") - try: - uninstall_from_manifest(pkg_name, install_root) - except RuntimeError as error: - fail(str(error)) - return 2 - - ok(f"uninstalled {pkg_name} from {install_root}") - return 0 - - -def cmd_installed(args) -> int: - install_root = Path(args.root).expanduser().resolve() - rows = load_installed_rows(install_root) - - print(style(f"Installed packages in {install_root}", bold=True)) - if not rows: - warn("no installed packages found") - return 0 - - for row in rows: - if row.get("error"): - warn(f"skipping invalid manifest {row['manifest'].name}: {row['error']}") - continue - - print( - f" {style(row['package'], bold=True)} {row['version']} " - f"({row['path_count']} paths)" - ) - - return 0 diff --git a/npkg-testing/tools/npkg/console.py b/npkg-testing/tools/npkg/console.py deleted file mode 100644 index d76d3b8..0000000 --- a/npkg-testing/tools/npkg/console.py +++ /dev/null @@ -1,41 +0,0 @@ -import os -import sys - - -RESET = "\033[0m" -BOLD = "\033[1m" -GREEN = "\033[32m" -YELLOW = "\033[33m" -RED = "\033[31m" -BLUE = "\033[34m" - - -def use_color() -> bool: - return sys.stdout.isatty() and os.environ.get("NO_COLOR") is None - - -def style(text: str, color: str = "", bold: bool = False) -> str: - if not use_color(): - return text - prefix = "" - if bold: - prefix += BOLD - if color: - prefix += color - return f"{prefix}{text}{RESET}" - - -def info(message: str) -> None: - print(f"[{style('>', BLUE)}] {message}") - - -def ok(message: str) -> None: - print(f"[{style('+', GREEN)}] {message}") - - -def warn(message: str) -> None: - print(f"[{style('!', YELLOW)}] {message}") - - -def fail(message: str) -> None: - print(f"[{style('x', RED)}] {message}", file=sys.stderr) diff --git a/npkg-testing/tools/npkg/install_db.py b/npkg-testing/tools/npkg/install_db.py deleted file mode 100644 index 0434a7a..0000000 --- a/npkg-testing/tools/npkg/install_db.py +++ /dev/null @@ -1,105 +0,0 @@ -import json -from pathlib import Path -from typing import Any, Dict, List - -from .paths import list_manifest_paths, manifest_root, package_manifest_path -from .types import Package - - -def write_install_manifest(pkg: Package, install_root: Path, members: List[str]) -> None: - db_dir = manifest_root(install_root) - db_dir.mkdir(parents=True, exist_ok=True) - manifest = { - "package": pkg.name, - "version": pkg.version, - "install_root": str(install_root), - "paths": members, - } - manifest_path = package_manifest_path(pkg.name, install_root) - with manifest_path.open("w", encoding="utf-8") as handle: - json.dump(manifest, handle, indent=2) - - -def read_install_manifest(pkg_name: str, install_root: Path) -> Dict[str, Any]: - manifest_path = package_manifest_path(pkg_name, install_root) - if not manifest_path.exists(): - raise RuntimeError(f"package '{pkg_name}' is not installed in {install_root}") - with manifest_path.open("r", encoding="utf-8") as handle: - data = json.load(handle) - if not isinstance(data, dict): - raise RuntimeError(f"invalid manifest for package '{pkg_name}'") - return data - - -def uninstall_from_manifest(pkg_name: str, install_root: Path) -> None: - data = read_install_manifest(pkg_name, install_root) - raw_paths = data.get("paths", []) - if not isinstance(raw_paths, list): - raise RuntimeError(f"invalid manifest path list for package '{pkg_name}'") - - unique_paths = [] - seen = set() - for item in raw_paths: - if not isinstance(item, str): - continue - normalized = item.strip().lstrip("/") - if not normalized or normalized in seen: - continue - seen.add(normalized) - unique_paths.append(normalized) - - for rel_path in sorted(unique_paths, key=lambda value: (value.count("/"), len(value)), reverse=True): - target = install_root / rel_path - if target.is_symlink() or target.is_file(): - target.unlink(missing_ok=True) - elif target.is_dir(): - try: - target.rmdir() - except OSError: - pass - - for rel_path in sorted(unique_paths, key=lambda value: value.count("/"), reverse=True): - current = (install_root / rel_path).parent - while current != install_root and current.exists(): - try: - current.rmdir() - except OSError: - break - current = current.parent - - manifest_path = package_manifest_path(pkg_name, install_root) - manifest_path.unlink(missing_ok=True) - - db_dir = manifest_root(install_root) - try: - db_dir.rmdir() - except OSError: - pass - - -def load_installed_rows(install_root: Path) -> List[Dict[str, Any]]: - rows: List[Dict[str, Any]] = [] - for manifest_path in list_manifest_paths(install_root): - try: - with manifest_path.open("r", encoding="utf-8") as handle: - data = json.load(handle) - except (OSError, json.JSONDecodeError) as error: - rows.append( - { - "manifest": manifest_path, - "error": str(error), - } - ) - continue - - rows.append( - { - "manifest": manifest_path, - "package": str(data.get("package") or manifest_path.stem), - "version": str(data.get("version") or "unknown"), - "path_count": len(data.get("paths", [])) if isinstance(data.get("paths", []), list) else 0, - "error": None, - } - ) - - return rows diff --git a/npkg-testing/tools/npkg/metadata.py b/npkg-testing/tools/npkg/metadata.py deleted file mode 100644 index ed048cd..0000000 --- a/npkg-testing/tools/npkg/metadata.py +++ /dev/null @@ -1,117 +0,0 @@ -import os -from pathlib import Path -from typing import Any, Dict, Optional - -try: - import tomllib -except ModuleNotFoundError: # pragma: no cover - tomllib = None - -from .paths import workspace_root -from .types import Package - - -def normalize_command(raw: Optional[str]) -> Optional[str]: - if raw is None: - return None - command = raw.strip() - return command or None - - -def as_dict(value: Any) -> Dict[str, Any]: - return value if isinstance(value, dict) else {} - - -def load_raw_package(meta_path: Path) -> Dict[str, Any]: - if tomllib is None: - raise ValueError("TOML metadata requires Python 3.11+ (tomllib not available)") - with meta_path.open("rb") as handle: - parsed = tomllib.load(handle) - if not isinstance(parsed, dict): - raise ValueError(f"Invalid metadata in {meta_path}: expected top-level table") - return parsed - - -def load_package(meta_path: Path) -> Package: - data = load_raw_package(meta_path) - - default_name = meta_path.parent.name.replace("_", "-") - name = str(data.get("name") or default_name).strip() - version = str(data.get("version") or "0.1.0").strip() - description = str(data.get("description") or "").strip() - install_path = str(data.get("install_path") or "/usr/bin/").strip() - - build = as_dict(data.get("build", {})) - package_section = as_dict(data.get("package", {})) - clean = as_dict(data.get("clean", {})) - - if not name or not version: - raise ValueError(f"Invalid metadata in {meta_path}: missing name/version") - - if install_path and not install_path.startswith("/"): - install_path = f"/{install_path}" - - return Package( - name=name, - version=version, - description=description, - package_dir=meta_path.parent, - install_path=install_path, - build_command=normalize_command(build.get("command")), - package_command=normalize_command(package_section.get("command")), - clean_command=normalize_command(clean.get("command")), - ) - - -def metadata_file_in_dir(package_dir: Path) -> Optional[Path]: - meta = package_dir / "npkg.conf" - return meta if meta.exists() else None - - -def discover_packages() -> Dict[str, Package]: - root = workspace_root() - packages: Dict[str, Package] = {} - search_roots = [ - root / "bin", - root / "sbin", - root / "toolkits", - root / "lib" / "public", - root / "lib" / "private", - root / "lab", - root / "systems", - ] - - for top in search_roots: - if not top.exists(): - continue - for dirpath, _, filenames in os.walk(top): - if "npkg.conf" not in set(filenames): - continue - package_dir = Path(dirpath) - meta = metadata_file_in_dir(package_dir) - if meta is None: - continue - package = load_package(meta) - if package.name in packages: - first = packages[package.name].package_dir - raise ValueError( - f"Duplicate package name '{package.name}' in {first} and {package.package_dir}" - ) - packages[package.name] = package - - return dict(sorted(packages.items(), key=lambda item: item[0])) - - -def select_package(packages: Dict[str, Package], selector: str) -> Package: - if selector in packages: - return packages[selector] - - root = workspace_root() - normalized = selector.strip().strip("/") - if normalized: - selector_path = (root / normalized).resolve() - for pkg in packages.values(): - if pkg.package_dir.resolve() == selector_path: - return pkg - - raise KeyError(selector) diff --git a/npkg-testing/tools/npkg/paths.py b/npkg-testing/tools/npkg/paths.py deleted file mode 100644 index 3029adf..0000000 --- a/npkg-testing/tools/npkg/paths.py +++ /dev/null @@ -1,39 +0,0 @@ -from pathlib import Path -from typing import List - -from .types import Package - - -def workspace_root() -> Path: - return Path(__file__).resolve().parents[2] - - -def npkg_build_root() -> Path: - return workspace_root() / "npkg-build" - - -def out_root() -> Path: - return npkg_build_root() - - -def package_stage_dir(pkg: Package) -> Path: - return out_root() / "work" / pkg.name / "stage" - - -def package_archive_path(pkg: Package) -> Path: - return out_root() / "packages" / f"{pkg.name}-{pkg.version}.tar.gz" - - -def manifest_root(install_root: Path) -> Path: - return install_root / ".npkg-db" - - -def package_manifest_path(pkg_name: str, install_root: Path) -> Path: - return manifest_root(install_root) / f"{pkg_name}.json" - - -def list_manifest_paths(install_root: Path) -> List[Path]: - db_dir = manifest_root(install_root) - if not db_dir.exists() or not db_dir.is_dir(): - return [] - return sorted(db_dir.glob("*.json")) diff --git a/npkg-testing/tools/npkg/types.py b/npkg-testing/tools/npkg/types.py deleted file mode 100644 index b43c8a2..0000000 --- a/npkg-testing/tools/npkg/types.py +++ /dev/null @@ -1,15 +0,0 @@ -from dataclasses import dataclass -from pathlib import Path -from typing import Optional - - -@dataclass -class Package: - name: str - version: str - description: str - package_dir: Path - install_path: str - build_command: Optional[str] - package_command: Optional[str] - clean_command: Optional[str][COMMIT END](C) 2025 0x4248 (C) 2025 4248 Media and 4248 Systems, All part of 0x4248 See LICENCE files for more information. Not all files are by 0x4248 always check Licencing.