95 lines
3.2 KiB
Python
95 lines
3.2 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Utilities for managing symbolic links and directory setup.
|
|
"""
|
|
|
|
import os
|
|
import logging
|
|
from pathlib import Path
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
def setup_deepagents_symlink():
|
|
"""
|
|
Create a symbolic link from projects/robot to ~/.deepagents
|
|
if it doesn't already exist.
|
|
"""
|
|
try:
|
|
# Get paths
|
|
project_root = Path(__file__).parent.parent
|
|
robot_dir = project_root / "projects" / "robot"
|
|
deepagents_dir = Path.home() / ".deepagents"
|
|
|
|
# Create robot directory if it doesn't exist
|
|
robot_dir.mkdir(parents=True, exist_ok=True)
|
|
|
|
# If ~/.deepagents already exists and is not a symlink, backup and remove it
|
|
if deepagents_dir.exists() and not deepagents_dir.is_symlink():
|
|
backup_dir = deepagents_dir.parent / f"{deepagents_dir.name}.backup"
|
|
logger.warning(f"~/.deepagents directory exists but is not a symlink.")
|
|
logger.warning(f"Creating backup at {backup_dir}")
|
|
|
|
try:
|
|
# Create backup
|
|
import shutil
|
|
if backup_dir.exists():
|
|
shutil.rmtree(backup_dir)
|
|
shutil.move(str(deepagents_dir), str(backup_dir))
|
|
logger.info(f"Successfully backed up existing directory to {backup_dir}")
|
|
except Exception as backup_error:
|
|
logger.error(f"Failed to backup existing directory: {backup_error}")
|
|
logger.error("Please manually remove or backup ~/.deepagents to proceed")
|
|
return False
|
|
|
|
# If ~/.deepagents is already a symlink pointing to the right place, do nothing
|
|
if deepagents_dir.is_symlink():
|
|
target = deepagents_dir.resolve()
|
|
if target == robot_dir.resolve():
|
|
logger.info(f"~/.deepagents already points to {robot_dir}")
|
|
return True
|
|
else:
|
|
# Remove existing symlink pointing elsewhere
|
|
deepagents_dir.unlink()
|
|
logger.info(f"Removed existing symlink pointing to {target}")
|
|
|
|
# Create the symbolic link
|
|
os.symlink(robot_dir, deepagents_dir, target_is_directory=True)
|
|
logger.info(f"Created symbolic link: {deepagents_dir} -> {robot_dir}")
|
|
return True
|
|
|
|
except Exception as e:
|
|
logger.error(f"Failed to create symbolic link: {e}")
|
|
return False
|
|
|
|
|
|
def setup_project_directories():
|
|
"""
|
|
Set up all necessary directories and symbolic links for the project.
|
|
"""
|
|
logger.info("Setting up project directories...")
|
|
|
|
# Setup ~/.deepagents symlink
|
|
symlink_success = setup_deepagents_symlink()
|
|
|
|
if symlink_success:
|
|
logger.info("Project directories setup completed successfully")
|
|
else:
|
|
logger.warning("Project directories setup completed with warnings")
|
|
|
|
return symlink_success
|
|
|
|
|
|
if __name__ == "__main__":
|
|
# Set up basic logging for standalone testing
|
|
logging.basicConfig(
|
|
level=logging.INFO,
|
|
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
|
|
)
|
|
|
|
# Test the function
|
|
success = setup_deepagents_symlink()
|
|
if success:
|
|
print("✅ Symbolic link setup successful")
|
|
else:
|
|
print("❌ Symbolic link setup failed") |