#!/usr/bin/env python3 """ Debian Forge Configuration Manager CLI Helps collaborators manage their local configuration settings """ import os import sys import argparse from pathlib import Path # Add the project root to the path so we can import our modules project_root = Path(__file__).parent.parent sys.path.insert(0, str(project_root)) try: from osbuild.config_manager import config except ImportError: print("Error: Could not import configuration manager") sys.exit(1) def setup_local_config(): """Set up local configuration file for the user""" config_dir = Path("config") local_config = config_dir / "debian-forge.local.conf" example_config = config_dir / "debian-forge.local.conf.example" if local_config.exists(): print(f"Local configuration already exists at {local_config}") return if not example_config.exists(): print(f"Example configuration not found at {example_config}") return # Copy example to local config import shutil shutil.copy(example_config, local_config) print(f"Created local configuration at {local_config}") print("Please edit this file to customize your settings") def show_config(): """Show current configuration""" config.print_config() def set_apt_proxy(proxy_url): """Set apt-cacher-ng proxy URL""" config_dir = Path("config") local_config = config_dir / "debian-forge.local.conf" # Create local config if it doesn't exist if not local_config.exists(): setup_local_config() # Read current config import configparser cfg = configparser.ConfigParser() cfg.read(local_config) # Ensure apt-cacher-ng section exists if "apt-cacher-ng" not in cfg: cfg.add_section("apt-cacher-ng") # Set the proxy URL if proxy_url.lower() in ["none", "disable", ""]: cfg["apt-cacher-ng"]["url"] = "" print("apt-cacher-ng proxy disabled") else: cfg["apt-cacher-ng"]["url"] = proxy_url print(f"apt-cacher-ng proxy set to: {proxy_url}") # Write back to file with open(local_config, 'w') as f: cfg.write(f) def set_build_setting(section, key, value): """Set a build setting""" config_dir = Path("config") local_config = config_dir / "debian-forge.local.conf" # Create local config if it doesn't exist if not local_config.exists(): setup_local_config() # Read current config import configparser cfg = configparser.ConfigParser() cfg.read(local_config) # Ensure section exists if section not in cfg: cfg.add_section(section) # Set the value cfg[section][key] = value print(f"Set {section}.{key} = {value}") # Write back to file with open(local_config, 'w') as f: cfg.write(f) def main(): parser = argparse.ArgumentParser(description="Debian Forge Configuration Manager") subparsers = parser.add_subparsers(dest="command", help="Available commands") # Setup command setup_parser = subparsers.add_parser("setup", help="Set up local configuration") # Show command show_parser = subparsers.add_parser("show", help="Show current configuration") # Set apt-proxy command apt_proxy_parser = subparsers.add_parser("apt-proxy", help="Set apt-cacher-ng proxy") apt_proxy_parser.add_argument("url", nargs="?", default="", help="Proxy URL (or 'none' to disable)") # Set build setting command set_parser = subparsers.add_parser("set", help="Set a configuration value") set_parser.add_argument("section", help="Configuration section (e.g., build, stages)") set_parser.add_argument("key", help="Configuration key") set_parser.add_argument("value", help="Configuration value") args = parser.parse_args() if not args.command: parser.print_help() return if args.command == "setup": setup_local_config() elif args.command == "show": show_config() elif args.command == "apt-proxy": set_apt_proxy(args.url) elif args.command == "set": set_build_setting(args.section, args.key, args.value) else: parser.print_help() if __name__ == "__main__": main()