-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd_watchsecrets.py
More file actions
90 lines (71 loc) · 2.8 KB
/
add_watchsecrets.py
File metadata and controls
90 lines (71 loc) · 2.8 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
#!/usr/bin/env python3
"""
Add WatchSecrets.swift to MeuLabApp.xcodeproj
Usage:
python3 add_watchsecrets.py
This script edits project.pbxproj to add WatchSecrets.swift to MeuLabWatch target.
"""
import os
import re
from pathlib import Path
PROJECT_DIR = Path(__file__).parent
PBXPROJ_PATH = PROJECT_DIR / "MeuLabApp.xcodeproj/project.pbxproj"
WATCHSECRETS_PATH = PROJECT_DIR / "MeuLabWatch/Services/WatchSecrets.swift"
def read_pbxproj():
"""Read project.pbxproj content"""
with open(PBXPROJ_PATH, 'r') as f:
return f.read()
def write_pbxproj(content):
"""Write project.pbxproj content"""
with open(PBXPROJ_PATH, 'w') as f:
f.write(content)
def find_file_ref_id(content, filename):
"""Find fileReference ID for given filename"""
# Pattern: /* WatchSecrets.swift */ = {isa = PBXFileReference ...
pattern = rf'/\* {re.escape(filename)} \*/ = [A-Z0-9]+;'
match = re.search(pattern, content)
if match:
line = match.group()
# Extract ID from end of line before ';'
id_match = re.search(r'([A-Z0-9]+);', line)
if id_match:
return id_match.group(1)
return None
def add_file_to_pbxproj():
"""Add WatchSecrets.swift to project"""
print("📝 Reading project.pbxproj...")
content = read_pbxproj()
# Check if already added
if "WatchSecrets.swift" in content:
print("❌ WatchSecrets.swift already in project.pbxproj")
return False
if not WATCHSECRETS_PATH.exists():
print(f"❌ File not found: {WATCHSECRETS_PATH}")
return False
print(f"✅ Found file: {WATCHSECRETS_PATH}")
# Find WatchRadioView (similar file in watch) to use as template
watch_view_ref = find_file_ref_id(content, "WatchRadioView.swift")
if not watch_view_ref:
print("❌ Could not find WatchRadioView.swift reference - cannot determine structure")
print("⚠️ Please add manually via Xcode UI")
return False
print(f"ℹ️ Found reference pattern in {watch_view_ref}")
# For safety, just provide instructions
print("\n⚠️ IMPORTANT: Use Xcode UI for safety")
print("\n1. Open Xcode:")
print(" open MeuLabApp.xcodeproj")
print("\n2. Add file via menu:")
print(" File → Add Files to \"MeuLabApp\"")
print(" Select: MeuLabWatch/Services/WatchSecrets.swift")
print(" Target: ✅ MeuLabWatch")
print("\n3. Verify by running:")
print(" xcodebuild build -scheme MeuLabWatch")
return True
if __name__ == "__main__":
print("🔐 Add WatchSecrets.swift to MeuLabApp project")
print("=" * 50)
if add_file_to_pbxproj():
print("\n✅ Script completed")
else:
print("\n❌ Could not complete automatically")
print(" Use Xcode UI (see instructions above)")