-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfix_all_duplicates.py
More file actions
263 lines (235 loc) · 9.36 KB
/
fix_all_duplicates.py
File metadata and controls
263 lines (235 loc) · 9.36 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
#!/usr/bin/env python3
import re
import os
import shutil
def fix_all_duplicate_files():
project_path = "Sources/swift/Pets Therapy.xcodeproj/project.pbxproj"
# List of files that are showing as duplicates in the warning
duplicate_files = [
"CommandLineUseCase.swift",
"NotificationsService.swift",
"App.swift",
"DistributedNotificationsService.swift",
"AnalyticsEvent.swift",
"AnalyticsService.swift",
"AppAnalyticsEvent.swift",
"FirebaseAnalyticsService.swift",
"AnalyticsConsentView.swift",
"AnalyticsConsentViewModel.swift",
"AnalyticsSettingsView.swift",
"AboutView.swift",
"AppPages.swift",
"ContentView.swift",
"ContributorsView.swift",
"AppWindowManager.swift",
"MacContentView.swift",
"MainScene.swift",
"CustomPetsResources.swift",
"DeletePetButtonCoordinator.swift",
"DeletePetUseCase.swift",
"DeletePetUseCaseImpl.swift",
"ExportPetButtonCoordinator.swift",
"ExportPetUseCase.swift",
"ExportPetUseCaseImpl.swift",
"ImportPetDragAndDropCoordinator.swift",
"ImportPetDragAndDropUseCase.swift",
"ImportVerifier.swift",
"ImportPetUseCaseImpl.swift",
"RenamePetButtonCoordinator.swift",
"Dependencies.swift",
"LaunchAtLogin.swift",
"SwinjectUtils.swift",
"Blur.swift",
"Buttons.swift",
"Colors.swift",
"Config.swift",
"IconButton.swift",
"PageTitle.swift",
"Spacing.swift",
"Stacks.swift",
"TabBar.swift",
"Themes.swift",
"Typography.swift",
"AppConfig.swift",
"AppConfigStorage.swift",
"Constants.swift",
"Contributors.swift",
"Lang.swift",
"PetPersonality.swift",
"PetsAssets.swift",
"SpeciesNames.swift",
"SpeciesProvider.swift",
"PetAISpeechCoordinator.swift",
"OnScreenCoordinator.swift",
"ScreenEnvironment.swift",
"WorldElementsService.swift",
"OnScreenCoordinatorImpl.swift",
"FantozziCloud.swift",
"GetsAngryWhenMeetingOtherCats.swift",
"LeavesPoopStains.swift",
"LeavesTracesWhileWalking.swift",
"RandomPlatformJumper.swift",
"SleepingPlace.swift",
"UfoAbduction.swift",
"DesktopObstaclesService.swift",
"MouseChaser.swift",
"MouseTrackingUseCase.swift",
"ShowsMenuOnRightClick.swift",
"Capabilities.swift",
"PetEntity.swift",
"PetSize.swift",
"PetsSpritesProvider.swift",
"CoordinateSystem.swift",
"EntityViewModel.swift",
"ImageInterpolationUseCase.swift",
"RenderingDependencies.swift",
"WorldViewModel.swift",
"ImageManupilation.swift",
"PixelArtEntityView.swift",
"WorldWindow.swift",
"ScreenshotService.swift",
"SpeechBubbleView.swift",
"Onboarding.swift",
"PetDetailsHeader.swift",
"PetDetailsView.swift",
"PetDetailsViewModel.swift",
"Filters.swift",
"PetPreview.swift",
"PetsGrid.swift",
"PetsSelectionView.swift",
"PetsSelectionViewModel.swift",
"ScreensaverElementsServiceImpl.swift",
"ScreensaverEntityView.swift",
"ScreensaverView.swift",
"ScreensaverViewModel.swift",
"BackgroundSettings.swift",
"Settings.swift",
"AISettings.swift",
"DesktopInteractionsSettings.swift",
"LaunchAtLoginSettings.swift",
"LaunchSilentlySettings.swift",
"MenuBarSwitch.swift",
"ScreensSettings.swift",
"ShopView.swift",
"ShopViewModel.swift",
"StatusBar.swift",
"AnimatedSprite.swift",
"AnimationsProvider.swift",
"AnimationsScheduler.swift",
"AutoRespawn.swift",
"BounceOnLateralCollisions.swift",
"Draggable.swift",
"FlipHorizontallyWhenGoingLeft.swift",
"Gravity.swift",
"LinearMovement.swift",
"Rotating.swift",
"Seeker.swift",
"ShapeShifter.swift",
"SpritesProvider.swift",
"WallCrawler.swift",
"Animations.swift",
"Capability.swift",
"Collisions.swift",
"Entity.swift",
"EntityState.swift",
"Hotspots.swift",
"Species.swift",
"World.swift"
]
# Backup the original file
backup_path = project_path + ".backup2"
shutil.copy2(project_path, backup_path)
print(f"Created backup at: {backup_path}")
with open(project_path, 'r') as f:
content = f.read()
# Find all file references (more comprehensive pattern)
file_refs = {}
pattern = r'([A-F0-9]{24})\s*/\*\s+([^*]+\.swift)\s+\*/\s+=\s+\{[^}]*?path\s*=\s*"?([^";]+)"?[^}]*?\}'
for match in re.finditer(pattern, content, re.DOTALL):
file_id = match.group(1)
file_name = match.group(2).strip()
file_path = match.group(3).strip()
file_refs[file_id] = (file_name, file_path)
print(f"Found {len(file_refs)} file references")
# Find build files
build_files = {}
pattern = r'([A-F0-9]{24})\s*/\*\s+([^*]+)\s+in\s+Sources\s+\*/\s+=\s+\{[^}]*?fileRef\s*=\s*([A-F0-9]{24})'
for match in re.finditer(pattern, content, re.DOTALL):
build_id = match.group(1)
build_name = match.group(2).strip()
file_ref = match.group(3)
build_files[build_id] = (build_name, file_ref)
print(f"Found {len(build_files)} build files")
# Find all PBXSourcesBuildPhase sections
def process_build_phase(content):
modified = False
pattern = r'(/\* Begin PBXSourcesBuildPhase section \*/.*?/\* End PBXSourcesBuildPhase section \*/)'
def process_section(match):
nonlocal modified
section = match.group(1)
# Find all files arrays in this section
files_pattern = r'(files\s*=\s*\()(.*?)(\);)'
def process_files(files_match):
nonlocal modified
prefix = files_match.group(1)
files_content = files_match.group(2)
suffix = files_match.group(3)
# Parse file entries
entries = re.findall(r'([A-F0-9]{24})\s*/\*[^*]+\*/', files_content)
# Track seen files by base name
seen = {}
unique_entries = []
removed_count = 0
for entry_id in entries:
if entry_id in build_files:
build_name, file_ref = build_files[entry_id]
if file_ref in file_refs:
file_name, file_path = file_refs[file_ref]
base_name = os.path.basename(file_path)
# Check if this is a duplicate file from our list
if any(dup in base_name for dup in duplicate_files):
if base_name not in seen:
seen[base_name] = entry_id
unique_entries.append(entry_id)
else:
removed_count += 1
print(f" Removing duplicate: {base_name}")
modified = True
else:
unique_entries.append(entry_id)
else:
unique_entries.append(entry_id)
else:
unique_entries.append(entry_id)
if removed_count > 0:
# Rebuild the files content
new_entries = []
for entry_id in unique_entries:
# Find the original entry line
entry_pattern = f'{entry_id}\\s*/\\*[^*]+\\*/,'
entry_match = re.search(entry_pattern, files_content)
if entry_match:
new_entries.append('\t\t\t\t' + entry_match.group(0))
if new_entries:
new_content = '\n' + '\n'.join(new_entries) + '\n\t\t\t'
else:
new_content = ''
return prefix + new_content + suffix
return files_match.group(0)
# Process all files arrays in this section
new_section = re.sub(files_pattern, process_files, section, flags=re.DOTALL)
return new_section
new_content = re.sub(pattern, process_section, content, flags=re.DOTALL)
return new_content, modified
print("\nProcessing build phases...")
new_content, was_modified = process_build_phase(content)
if was_modified:
# Write the fixed content back
with open(project_path, 'w') as f:
f.write(new_content)
print(f"\nFixed project file written to: {project_path}")
else:
print("\nNo duplicates found to remove.")
print("Original file backed up to:", backup_path)
if __name__ == "__main__":
fix_all_duplicate_files()