Three days of intensive work bringing seedgo to full operational status and driving all branches through comprehensive standards compliance. Seedgo v2.0.0: - 22 checkers active (up from 20), standards pack fully operational - New introspection standard researched from Dev-Pass, FPLAN-0017 open - Bypass system for false positives (.seedgo config) - Standards query and audit commands fully functional System-wide audit (FPLAN-0016): - All 14 auditable branches at 99%+ compliance - CLI imports standardized across all branches (console from cli.apps.modules) - handle_command(command, args) → bool contract added to all modules - print_help() function naming fixed for checker pattern matching - Handler extraction: large modules split, file I/O moved to handler layer - New handlers created across ai_mail, backup, daemon, flow, skills, spawn, seedgo Branch-specific highlights: - ai_mail: email.py split 840→420 lines, 4 new handlers - flow: dplan_flow.py 688→591 lines, 4 new handlers - seedgo: massive restructure — standards moved to handlers/aipass_standards/, old standards/ tree removed, bypass system added, diagnostics module - commons: database module added, CLI imports fixed - skills: 5 handle_commands added, help function renamed - trigger: error reporter handler, handle_command routing - All branches: consistent architecture, clean drone routing Culture doc (CLAUDE.md) added — documents AIPass philosophy, identity, memory system, and collaboration principles. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
132 lines
3.9 KiB
Python
132 lines
3.9 KiB
Python
# =================== AIPass ====================
|
|
# Name: drive_sync_ops.py
|
|
# Description: Google Drive Sync Business Operations Handler
|
|
# Version: 1.0.0
|
|
# Created: 2026-02-20
|
|
# Modified: 2026-03-09
|
|
# =============================================
|
|
|
|
"""
|
|
Google Drive Sync Business Operations Handler
|
|
|
|
Implements status, tracker management, and test operations for the
|
|
google_drive_sync module. Called by the module orchestrator.
|
|
"""
|
|
|
|
from pathlib import Path
|
|
from typing import Any, Dict
|
|
|
|
from aipass.backup.apps.handlers.json.drive_sync_json import (
|
|
load_config,
|
|
load_data,
|
|
save_data,
|
|
log_operation,
|
|
)
|
|
|
|
# JSON file paths (resolved relative to backup root)
|
|
_BACKUP_ROOT = Path(__file__).resolve().parents[3] # src/aipass/backup/
|
|
_JSON_DIR = _BACKUP_ROOT / "backup_json"
|
|
_MODULE_NAME = "google_drive_sync"
|
|
_CONFIG_FILE = _JSON_DIR / f"{_MODULE_NAME}_config.json"
|
|
_DATA_FILE = _JSON_DIR / f"{_MODULE_NAME}_data.json"
|
|
_LOG_FILE = _JSON_DIR / f"{_MODULE_NAME}_log.json"
|
|
|
|
|
|
def get_status() -> Dict[str, Any]:
|
|
"""Get current module status for monitoring.
|
|
|
|
Returns:
|
|
Dict with module status fields
|
|
"""
|
|
data = load_data(_DATA_FILE)
|
|
config = load_config(_CONFIG_FILE)
|
|
|
|
return {
|
|
"name": _MODULE_NAME,
|
|
"category": "backup_system",
|
|
"enabled": config.get("config", {}).get("enabled", False),
|
|
"authenticated": data.get("runtime_state", {}).get("authenticated", False),
|
|
"last_sync": data.get("runtime_state", {}).get("last_sync"),
|
|
"statistics": data.get("statistics", {})
|
|
}
|
|
|
|
|
|
def clear_file_tracker() -> bool:
|
|
"""Clear the file tracker cache for a fresh sync.
|
|
|
|
Returns:
|
|
bool: True if cleared successfully, False on error
|
|
"""
|
|
try:
|
|
data = load_data(_DATA_FILE)
|
|
if "runtime_state" in data and "file_tracker" in data["runtime_state"]:
|
|
data["runtime_state"]["file_tracker"] = {}
|
|
save_data(_DATA_FILE, data)
|
|
return True
|
|
except Exception:
|
|
return False
|
|
|
|
|
|
def get_file_tracker_stats() -> Dict[str, Any]:
|
|
"""Get statistics about the file tracker.
|
|
|
|
Returns:
|
|
Dict with tracker count and sample entries
|
|
"""
|
|
try:
|
|
data = load_data(_DATA_FILE)
|
|
tracker = data.get("runtime_state", {}).get("file_tracker", {})
|
|
|
|
sample = []
|
|
for i, (file_key, info) in enumerate(list(tracker.items())[:5]):
|
|
last_sync = info.get("last_sync", "unknown")[:19] if info.get("last_sync") else "unknown"
|
|
sample.append({"file": file_key, "last_sync": last_sync})
|
|
|
|
return {
|
|
"total": len(tracker),
|
|
"sample": sample,
|
|
"truncated": len(tracker) > 5
|
|
}
|
|
except Exception:
|
|
return {"total": 0, "sample": [], "truncated": False}
|
|
|
|
|
|
def test_drive_connection(sync_instance: Any) -> bool:
|
|
"""Test Google Drive connectivity using an authenticated sync instance.
|
|
|
|
Args:
|
|
sync_instance: An authenticated GoogleDriveSync instance
|
|
|
|
Returns:
|
|
bool: True if connection test succeeded, False otherwise
|
|
"""
|
|
try:
|
|
folder_id = sync_instance.get_or_create_backup_folder()
|
|
if folder_id:
|
|
log_operation(
|
|
_LOG_FILE,
|
|
"test_sync",
|
|
{"message": "Drive sync test successful", "folder_id": folder_id},
|
|
success=True
|
|
)
|
|
return True
|
|
else:
|
|
log_operation(
|
|
_LOG_FILE,
|
|
"test_sync",
|
|
{"message": "Failed to create backup folder"},
|
|
success=False
|
|
)
|
|
return False
|
|
except Exception as e:
|
|
log_operation(
|
|
_LOG_FILE,
|
|
"test_sync",
|
|
{
|
|
"message": f"Test failed: {e}",
|
|
"error_details": {"exception_type": type(e).__name__, "stack_trace": str(e)}
|
|
},
|
|
success=False
|
|
)
|
|
return False
|