95 lines
2.6 KiB
Python
95 lines
2.6 KiB
Python
# =================== AIPass ====================
|
|
# Name: drive_clear.py
|
|
# Description: Drive clear module — clears Drive file tracker (requires --force)
|
|
# Version: 1.0.0
|
|
# Created: 2026-04-17
|
|
# Modified: 2026-06-12
|
|
# =============================================
|
|
|
|
"""Drive Clear Module — clears the Drive file tracker for a project."""
|
|
|
|
import sys
|
|
|
|
from aipass.prax import logger
|
|
from aipass.cli.apps.modules import console
|
|
|
|
from aipass.backup.apps.handlers.json import json_handler
|
|
|
|
|
|
MODULE_NAME = "drive_clear"
|
|
PRIMARY_COMMAND = "drive_clear"
|
|
|
|
|
|
def print_introspection():
|
|
"""Display module info and connected handlers."""
|
|
console.print(f"[bold cyan]{MODULE_NAME} Module[/bold cyan]")
|
|
console.print(f" Primary command: [yellow]{PRIMARY_COMMAND}[/yellow]")
|
|
console.print(" Status: Phase 4 -- tracker clear")
|
|
console.print(" Handlers: drive/tracker (requires --force)")
|
|
|
|
|
|
def print_help():
|
|
"""Display help for this module."""
|
|
print_introspection()
|
|
console.print()
|
|
console.print("Usage: drive_clear <project_root> --force")
|
|
console.print(" --force Required to confirm tracker deletion")
|
|
|
|
|
|
def run_drive_clear(project_root: str, force: bool = False) -> bool:
|
|
"""Clear Drive tracker. Requires force=True.
|
|
|
|
Args:
|
|
project_root: Absolute path to the project.
|
|
force: Must be True to proceed.
|
|
|
|
Returns:
|
|
True if cleared, False otherwise.
|
|
"""
|
|
from aipass.backup.apps.handlers.drive.tracker import clear_all
|
|
|
|
if not force:
|
|
console.print("[dim]Use --force to confirm tracker deletion.[/dim]")
|
|
return False
|
|
|
|
success = clear_all(project_root)
|
|
if success:
|
|
console.print("[green]Drive tracker cleared.[/green]")
|
|
logger.info(f"[backup] Drive tracker cleared for {project_root}")
|
|
else:
|
|
console.print("[red]Failed to clear Drive tracker.[/red]")
|
|
|
|
json_handler.log_operation(
|
|
"drive_clear_complete",
|
|
{"project_root": project_root, "success": success},
|
|
)
|
|
return success
|
|
|
|
|
|
def handle_command(command: str, args: list) -> bool:
|
|
"""Handle the drive-clear-tracker command. Returns True if handled."""
|
|
if command != PRIMARY_COMMAND:
|
|
return False
|
|
|
|
if not args:
|
|
print_introspection()
|
|
return True
|
|
|
|
if args[0] in ("--help", "-h", "help"):
|
|
print_help()
|
|
return True
|
|
|
|
project_root = args[0]
|
|
force = "--force" in args
|
|
run_drive_clear(project_root, force=force)
|
|
return True
|
|
|
|
|
|
# =============================================
|
|
|
|
if __name__ == "__main__":
|
|
if len(sys.argv) < 2:
|
|
print_introspection()
|
|
sys.exit(0)
|
|
handle_command(PRIMARY_COMMAND, sys.argv[1:])
|