-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsync_cli.py
More file actions
executable file
·167 lines (134 loc) · 5.3 KB
/
sync_cli.py
File metadata and controls
executable file
·167 lines (134 loc) · 5.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#!/usr/bin/env python3
"""CLI for syncing Claude.ai data."""
import asyncio
import logging
import sys
from pathlib import Path
import argparse
from datetime import datetime
from claude_sync.sync import SyncOrchestrator
from claude_sync.browser import BrowserConfig
# Setup logging
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)
logger = logging.getLogger(__name__)
def progress_callback(progress):
"""Print progress updates."""
if progress.current_file:
print(f"\r[{progress.completed_files}/{progress.total_files}] "
f"{progress.current_project}: {progress.current_file}",
end='', flush=True)
else:
print(f"\r[{progress.completed_projects}/{progress.total_projects}] "
f"Syncing: {progress.current_project or 'Loading...'}",
end='', flush=True)
async def sync_all(args):
"""Sync all projects."""
storage_path = Path(args.storage or "claude_sync_data")
logger.info(f"Storage path: {storage_path}")
config = BrowserConfig(headless=args.headless)
orchestrator = SyncOrchestrator(
storage_path,
browser_config=config,
progress_callback=progress_callback if not args.quiet else None
)
print("Starting sync...")
result = await orchestrator.sync_all()
print() # New line after progress
if result["success"]:
print(f"\n✓ Sync completed successfully!")
print(f" Projects synced: {result['projects_synced']}")
print(f" Files synced: {result['files_synced']}")
print(f" Duration: {result['duration_seconds']:.1f}s")
if result["errors"]:
print(f"\n⚠ {len(result['errors'])} errors occurred:")
for error in result["errors"][:5]: # Show first 5 errors
print(f" - {error['type']}: {error.get('file', error.get('project'))}")
else:
print(f"\n✗ Sync failed: {result.get('error', 'Unknown error')}")
sys.exit(1)
async def sync_project(args):
"""Sync a specific project."""
storage_path = Path(args.storage or "claude_sync_data")
logger.info(f"Storage path: {storage_path}")
config = BrowserConfig(headless=args.headless)
orchestrator = SyncOrchestrator(
storage_path,
browser_config=config,
progress_callback=progress_callback if not args.quiet else None
)
print(f"Syncing project: {args.project}")
result = await orchestrator.sync_project(args.project)
print() # New line after progress
if result["success"]:
print(f"\n✓ Project synced successfully!")
print(f" Files synced: {result['files_synced']}")
print(f" Duration: {result['duration_seconds']:.1f}s")
else:
print(f"\n✗ Sync failed: {result.get('error', 'Unknown error')}")
sys.exit(1)
async def list_projects(args):
"""List synced projects."""
storage_path = Path(args.storage or "claude_sync_data")
config = BrowserConfig(headless=args.headless)
orchestrator = SyncOrchestrator(storage_path, browser_config=config)
status = orchestrator.get_sync_status()
print(f"\nSync Status:")
print(f" Last sync: {status['last_sync'] or 'Never'}")
print(f" Total projects: {status['total_projects']}")
print(f" Total files: {status['total_files']}")
if status['synced_projects']:
print(f"\nSynced Projects:")
for project in status['synced_projects']:
last_synced = project.get('last_synced', 'Unknown')
if last_synced != 'Unknown':
# Parse and format date
dt = datetime.fromisoformat(last_synced)
last_synced = dt.strftime("%Y-%m-%d %H:%M")
print(f" - {project['name']}")
print(f" Last synced: {last_synced}")
print(f" Local path: {project['local_path']}")
def main():
"""Main CLI entry point."""
parser = argparse.ArgumentParser(description="Sync Claude.ai data locally")
parser.add_argument(
"--storage",
help="Storage directory (default: claude_sync_data)",
default="claude_sync_data"
)
parser.add_argument(
"--headless",
action="store_true",
help="Run browser in headless mode"
)
parser.add_argument(
"--quiet",
action="store_true",
help="Suppress progress output"
)
subparsers = parser.add_subparsers(dest="command", help="Commands")
# Sync all command
sync_all_parser = subparsers.add_parser("sync", help="Sync all projects")
# Sync project command
sync_project_parser = subparsers.add_parser(
"sync-project",
help="Sync a specific project"
)
sync_project_parser.add_argument("project", help="Project name to sync")
# List command
list_parser = subparsers.add_parser("list", help="List synced projects")
args = parser.parse_args()
if not args.command:
parser.print_help()
sys.exit(1)
# Run appropriate command
if args.command == "sync":
asyncio.run(sync_all(args))
elif args.command == "sync-project":
asyncio.run(sync_project(args))
elif args.command == "list":
asyncio.run(list_projects(args))
if __name__ == "__main__":
main()