-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsync_verify.py
More file actions
executable file
·373 lines (293 loc) · 11.2 KB
/
sync_verify.py
File metadata and controls
executable file
·373 lines (293 loc) · 11.2 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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
#!/usr/bin/env python3
"""
Sync Verification Tool
Checks consistency between Computer A and Computer B.
"""
import sys
import json
from pathlib import Path
from datetime import datetime
from typing import Dict, List, Any
from logger import LogiLogger
logger = LogiLogger.get_logger("sync_verify")
class SyncVerifier:
"""Verify sync integrity across computers"""
def __init__(self):
self.repo_root = Path(__file__).parent
self.issues = []
self.warnings = []
self.checks_passed = 0
self.checks_total = 0
def check(self, name: str, condition: bool, error_msg: str):
"""Run a check and track result"""
self.checks_total += 1
if condition:
self.checks_passed += 1
logger.info(f"✓ {name}")
return True
else:
self.issues.append(f"✗ {name}: {error_msg}")
logger.error(f"✗ {name}: {error_msg}")
return False
def warn(self, name: str, message: str):
"""Record a warning"""
self.warnings.append(f"⚠ {name}: {message}")
logger.warning(f"⚠ {name}: {message}")
def verify_git_status(self) -> bool:
"""Verify git repository status"""
import subprocess
logger.info("\n[Git Status]")
# Check if on correct branch
result = subprocess.run(
["git", "branch", "--show-current"],
capture_output=True,
text=True,
cwd=self.repo_root
)
current_branch = result.stdout.strip()
expected_branch = "claude/setup-user-profile-9LdRn"
self.check(
"Git branch",
current_branch == expected_branch,
f"On {current_branch}, expected {expected_branch}"
)
# Check if working tree is clean
result = subprocess.run(
["git", "status", "--porcelain"],
capture_output=True,
text=True,
cwd=self.repo_root
)
if result.stdout.strip():
self.warn("Working tree", "Uncommitted changes present")
else:
self.check("Working tree", True, "")
# Check if synced with remote
subprocess.run(
["git", "fetch", "origin", expected_branch, "--quiet"],
cwd=self.repo_root
)
local_result = subprocess.run(
["git", "rev-parse", "@"],
capture_output=True,
text=True,
cwd=self.repo_root
)
remote_result = subprocess.run(
["git", "rev-parse", "@{u}"],
capture_output=True,
text=True,
cwd=self.repo_root
)
local_commit = local_result.stdout.strip()
remote_commit = remote_result.stdout.strip()
self.check(
"GitHub sync",
local_commit == remote_commit,
f"Local: {local_commit[:7]}, Remote: {remote_commit[:7]}"
)
return True
def verify_dependencies(self) -> bool:
"""Verify Python dependencies"""
logger.info("\n[Dependencies]")
venv_path = self.repo_root / "venv"
self.check(
"Virtual environment",
venv_path.exists(),
"venv/ not found"
)
requirements_file = self.repo_root / "requirements.txt"
self.check(
"requirements.txt",
requirements_file.exists(),
"requirements.txt not found"
)
return True
def verify_configuration(self) -> bool:
"""Verify configuration files"""
logger.info("\n[Configuration]")
# Check .env
env_file = self.repo_root / ".env"
env_example = self.repo_root / ".env.example"
if env_file.exists():
self.check(".env file", True, "")
else:
self.warn(".env file", "Not found (use .env.example as template)")
self.check(
".env.example",
env_example.exists(),
".env.example not found"
)
# Check credentials
creds_file = self.repo_root / "credentials.json"
creds_template = self.repo_root / "credentials.json.template"
if creds_file.exists():
self.check("credentials.json", True, "")
else:
self.warn("credentials.json", "Not found")
self.check(
"credentials.json.template",
creds_template.exists(),
"Template not found"
)
return True
def verify_8tb_drive(self) -> bool:
"""Verify 8TB drive setup"""
logger.info("\n[8TB Drive]")
drive_path = Path("/mnt/8tb_drive")
if drive_path.exists():
self.check("8TB drive mount", True, "")
# Check Legacy AI directories
legacy_ai_path = drive_path / "legacy_ai"
if legacy_ai_path.exists():
self.check("Legacy AI directory", True, "")
# Check subdirectories
for subdir in ["datasets", "models", "memory", "cache"]:
subdir_path = legacy_ai_path / subdir
if subdir_path.exists():
self.check(f" {subdir}/", True, "")
else:
self.warn(f" {subdir}/", "Not found (will be created on first use)")
else:
self.warn("Legacy AI directory", "Not found")
else:
self.warn("8TB drive mount", "Not mounted at /mnt/8tb_drive")
return True
def verify_ollama(self) -> bool:
"""Verify Ollama installation"""
import subprocess
logger.info("\n[Ollama]")
try:
result = subprocess.run(
["ollama", "--version"],
capture_output=True,
text=True,
timeout=5
)
if result.returncode == 0:
version = result.stdout.strip()
self.check("Ollama installed", True, "")
logger.info(f" Version: {version}")
else:
self.warn("Ollama installed", "Command failed")
except FileNotFoundError:
self.warn("Ollama installed", "Not found (install: curl https://ollama.ai/install.sh | sh)")
except Exception as e:
self.warn("Ollama installed", f"Check failed: {e}")
# Check if Ollama is running
try:
import requests
response = requests.get("http://localhost:11434/api/tags", timeout=5)
if response.status_code == 200:
self.check("Ollama running", True, "")
# List models
data = response.json()
models = data.get("models", [])
if models:
logger.info(f" Models: {len(models)}")
for model in models[:5]: # Show first 5
logger.info(f" - {model['name']}")
else:
self.warn("Ollama models", "No models found")
else:
self.warn("Ollama running", "Service not responding")
except Exception as e:
self.warn("Ollama running", f"Not running (start: ollama serve)")
return True
def verify_file_structure(self) -> bool:
"""Verify expected files exist"""
logger.info("\n[File Structure]")
required_files = [
"google_sheets_sync.py",
"logibot_core.py",
"legacy_ai.py",
"training_data_builder.py",
"model_trainer.py",
"health_monitor.py",
"config.py",
"logger.py",
"requirements.txt",
"setup.sh",
"sync.sh",
"README.md",
"TRAINING.md"
]
for filename in required_files:
file_path = self.repo_root / filename
self.check(
f" {filename}",
file_path.exists(),
"Not found"
)
return True
def generate_report(self) -> Dict[str, Any]:
"""Generate verification report"""
report = {
"timestamp": datetime.utcnow().isoformat(),
"computer": self.get_computer_info(),
"checks_passed": self.checks_passed,
"checks_total": self.checks_total,
"success_rate": (self.checks_passed / self.checks_total * 100) if self.checks_total > 0 else 0,
"issues": self.issues,
"warnings": self.warnings,
"status": "PASS" if len(self.issues) == 0 else "FAIL"
}
return report
def get_computer_info(self) -> Dict[str, str]:
"""Get computer information"""
import platform
import socket
return {
"hostname": socket.gethostname(),
"platform": platform.platform(),
"python_version": platform.python_version()
}
def print_report(self, report: Dict[str, Any]):
"""Print formatted report"""
print("\n" + "=" * 60)
print("SYNC VERIFICATION REPORT")
print("=" * 60)
print(f"Computer: {report['computer']['hostname']}")
print(f"Timestamp: {report['timestamp']}")
print(f"Status: {report['status']}")
print(f"Checks: {report['checks_passed']}/{report['checks_total']} passed ({report['success_rate']:.1f}%)")
print("=" * 60)
if report['warnings']:
print(f"\nWarnings ({len(report['warnings'])}):")
for warning in report['warnings']:
print(f" {warning}")
if report['issues']:
print(f"\nIssues ({len(report['issues'])}):")
for issue in report['issues']:
print(f" {issue}")
print("\n" + "=" * 60)
if report['status'] == "PASS":
print("✓ VERIFICATION PASSED")
else:
print("✗ VERIFICATION FAILED - Fix issues before syncing")
print("=" * 60 + "\n")
def run_all_checks(self) -> bool:
"""Run all verification checks"""
logger.info("Starting sync verification...")
self.verify_git_status()
self.verify_dependencies()
self.verify_configuration()
self.verify_8tb_drive()
self.verify_ollama()
self.verify_file_structure()
report = self.generate_report()
self.print_report(report)
# Save report
report_file = self.repo_root / "logs" / f"sync_verify_{datetime.utcnow().strftime('%Y%m%d_%H%M%S')}.json"
report_file.parent.mkdir(exist_ok=True)
with open(report_file, 'w') as f:
json.dump(report, f, indent=2)
logger.info(f"Report saved: {report_file}")
return report['status'] == "PASS"
def main():
"""Main execution"""
verifier = SyncVerifier()
success = verifier.run_all_checks()
sys.exit(0 if success else 1)
if __name__ == "__main__":
main()