Some checks failed
Compile apt-layer (v2) / compile (push) Has been cancelled
- Added 20-daemon-integration.sh scriptlet for D-Bus and daemon lifecycle management - Updated 99-main.sh with new daemon subcommands (start, stop, status, install, uninstall, test, layer, deploy, upgrade, rollback) - Enhanced help and usage text for daemon integration - Fixed bash syntax errors in daemon integration scriptlet - Updated compile.sh to include daemon integration in build process - Updated .gitignore to exclude src/rpm-ostree/ reference source - Updated CHANGELOG.md and TODO.md to document daemon integration milestone - Removed src/rpm-ostree/ from git tracking (reference only, not committed)
137 lines
No EOL
3.8 KiB
Python
137 lines
No EOL
3.8 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
apt-ostree main entry point
|
|
|
|
This module provides the main entry point for apt-ostree, supporting both
|
|
daemon mode and CLI client mode with 1:1 rpm-ostree compatibility.
|
|
"""
|
|
|
|
import sys
|
|
import argparse
|
|
import logging
|
|
from pathlib import Path
|
|
|
|
# Add the current directory to Python path
|
|
sys.path.insert(0, str(Path(__file__).parent))
|
|
|
|
from apt_ostree import AptOstreeDaemon
|
|
from apt_ostree_cli import AptOstreeCLI
|
|
|
|
|
|
def setup_logging(level=logging.INFO):
|
|
"""Setup logging configuration"""
|
|
logging.basicConfig(
|
|
level=level,
|
|
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
|
handlers=[
|
|
logging.StreamHandler(),
|
|
logging.FileHandler('/var/log/apt-ostree.log')
|
|
]
|
|
)
|
|
|
|
|
|
def run_daemon():
|
|
"""Run the apt-ostree daemon"""
|
|
setup_logging()
|
|
logger = logging.getLogger('apt-ostree')
|
|
|
|
try:
|
|
logger.info("Starting apt-ostree daemon")
|
|
daemon = AptOstreeDaemon()
|
|
daemon.run()
|
|
except KeyboardInterrupt:
|
|
logger.info("Shutting down daemon (interrupted)")
|
|
except Exception as e:
|
|
logger.error(f"Daemon error: {e}")
|
|
sys.exit(1)
|
|
|
|
|
|
def run_cli():
|
|
"""Run the apt-ostree CLI client"""
|
|
from apt_ostree_cli import create_parser
|
|
|
|
parser = create_parser()
|
|
args = parser.parse_args()
|
|
|
|
if not args.command:
|
|
parser.print_help()
|
|
sys.exit(1)
|
|
|
|
setup_logging()
|
|
|
|
try:
|
|
cli = AptOstreeCLI()
|
|
|
|
# Route commands
|
|
if args.command == 'status':
|
|
sys.exit(cli.status(args))
|
|
elif args.command == 'install':
|
|
sys.exit(cli.install(args))
|
|
elif args.command == 'uninstall':
|
|
sys.exit(cli.uninstall(args))
|
|
elif args.command == 'upgrade':
|
|
sys.exit(cli.upgrade(args))
|
|
elif args.command == 'rollback':
|
|
sys.exit(cli.rollback(args))
|
|
elif args.command == 'deploy':
|
|
sys.exit(cli.deploy(args))
|
|
elif args.command == 'rebase':
|
|
sys.exit(cli.rebase(args))
|
|
elif args.command == 'db':
|
|
if args.db_command == 'list':
|
|
sys.exit(cli.db_list(args))
|
|
elif args.db_command == 'diff':
|
|
sys.exit(cli.db_diff(args))
|
|
else:
|
|
print("Error: Invalid db subcommand")
|
|
sys.exit(1)
|
|
elif args.command == 'kargs':
|
|
sys.exit(cli.kargs(args))
|
|
elif args.command == 'cleanup':
|
|
sys.exit(cli.cleanup(args))
|
|
elif args.command == 'cancel':
|
|
sys.exit(cli.cancel(args))
|
|
elif args.command == 'initramfs':
|
|
sys.exit(cli.initramfs(args))
|
|
elif args.command == 'usroverlay':
|
|
sys.exit(cli.usroverlay(args))
|
|
else:
|
|
print(f"Error: Unknown command '{args.command}'")
|
|
sys.exit(1)
|
|
|
|
except Exception as e:
|
|
print(f"Error: {e}")
|
|
sys.exit(1)
|
|
|
|
|
|
def main():
|
|
"""Main entry point"""
|
|
parser = argparse.ArgumentParser(
|
|
description='apt-ostree - Hybrid image/package system for Debian/Ubuntu',
|
|
add_help=False
|
|
)
|
|
parser.add_argument('--daemon', action='store_true', help='Run as daemon')
|
|
parser.add_argument('--help', '-h', action='store_true', help='Show help')
|
|
|
|
# Parse just the first few arguments to determine mode
|
|
args, remaining = parser.parse_known_args()
|
|
|
|
if args.help:
|
|
# Show help for CLI mode
|
|
from apt_ostree_cli import create_parser
|
|
cli_parser = create_parser()
|
|
cli_parser.print_help()
|
|
return
|
|
|
|
if args.daemon:
|
|
# Run as daemon
|
|
run_daemon()
|
|
else:
|
|
# Run as CLI client
|
|
# Reset sys.argv to include the remaining arguments
|
|
sys.argv = [sys.argv[0]] + remaining
|
|
run_cli()
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main() |