hackingtool/constants.py
Hardik Zinzuvadiya 6a32c8ac05 Phase 0: Add foundation files for v2.0.0 restructure
- constants.py: single source of truth for repo URLs, version (2.0.0),
  all paths via Path.home(), UI theme constants, PRIV_CMD auto-detection
- os_detect.py: OSInfo dataclass, auto-detect OS/distro/package manager,
  CURRENT_OS singleton, per-OS install command maps
- config.py: get_tools_dir(), load()/save() config.json, get_sudo_cmd()
- tools/__init__.py, tools/others/__init__.py: make proper Python packages
- IMPLEMENTATION.md: full 18-section restructuring plan (2350+ lines)
- LOG.md: 13-phase progress tracker
2026-03-15 13:53:44 +05:30

65 lines
No EOL
3.3 KiB
Python

from pathlib import Path
import platform
import shutil as _shutil
# ── Repository ────────────────────────────────────────────────────────────────
REPO_OWNER = "Z4nzu"
REPO_NAME = "hackingtool"
REPO_URL = f"https://github.com/{REPO_OWNER}/{REPO_NAME}.git"
REPO_WEB_URL = f"https://github.com/{REPO_OWNER}/{REPO_NAME}"
# ── Versioning ────────────────────────────────────────────────────────────────
VERSION = "2.0.0"
VERSION_DISPLAY = f"v{VERSION}"
# ── Python requirement ────────────────────────────────────────────────────────
MIN_PYTHON = (3, 10)
# ── User-scoped paths (cross-platform, always computed at runtime) ─────────────
# NEVER hardcode /home/username — use Path.home() so it works for any user,
# including root (/root), regular users (/home/alice), macOS (/Users/alice).
USER_CONFIG_DIR = Path.home() / f".{REPO_NAME}"
USER_TOOLS_DIR = USER_CONFIG_DIR / "tools"
USER_CONFIG_FILE = USER_CONFIG_DIR / "config.json"
USER_LOG_FILE = USER_CONFIG_DIR / f"{REPO_NAME}.log"
# ── System install paths (set per OS) ─────────────────────────────────────────
_system = platform.system()
if _system == "Darwin":
# macOS — Homebrew convention
APP_INSTALL_DIR = Path("/usr/local/share") / REPO_NAME
APP_BIN_PATH = Path("/usr/local/bin") / REPO_NAME
elif _system == "Linux":
APP_INSTALL_DIR = Path("/usr/share") / REPO_NAME
APP_BIN_PATH = Path("/usr/bin") / REPO_NAME
else:
# Fallback (Windows, FreeBSD, etc.)
APP_INSTALL_DIR = USER_CONFIG_DIR / "app"
APP_BIN_PATH = USER_CONFIG_DIR / "bin" / REPO_NAME
# ── UI theme ──────────────────────────────────────────────────────────────────
THEME_PRIMARY = "bold magenta"
THEME_BORDER = "bright_magenta"
THEME_SUCCESS = "bold green"
THEME_ERROR = "bold red"
THEME_WARNING = "bold yellow"
THEME_DIM = "dim white"
THEME_ARCHIVED = "dim yellow"
THEME_URL = "underline bright_blue"
THEME_ACCENT = "bold cyan"
# ── Default config values ──────────────────────────────────────────────────────
DEFAULT_CONFIG: dict = {
"tools_dir": str(USER_TOOLS_DIR),
"version": VERSION,
"theme": "magenta",
"show_archived": False,
"sudo_binary": "sudo",
"go_bin_dir": str(Path.home() / "go" / "bin"),
"gem_bin_dir": str(Path.home() / ".gem" / "ruby"),
}
# ── Privilege escalation ───────────────────────────────────────────────────────
# Prefer doas if present (OpenBSD/some Linux setups), else sudo
PRIV_CMD = "doas" if _shutil.which("doas") else "sudo"