Last active
March 17, 2023 16:42
-
-
Save izmcm/652088bc637e6a9525416b160e5d462d to your computer and use it in GitHub Desktop.
List files that are in your code folder but are not referenced in your Xcode project or duplicate files that were created by wrong git rebases
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pbxproj import XcodeProject | |
import os | |
from glob import glob | |
import collections | |
import sys | |
TYPE_OF_FILE = 'swift' | |
# Get all files in project folder | |
project_folder_path = sys.argv[1] | |
paths_from_project_folder = [y for x in os.walk(project_folder_path) for y in glob(os.path.join(x[0], '*.' + TYPE_OF_FILE))] | |
files_in_project_folder = [] | |
for path in paths_from_project_folder: | |
filename = path.split('/')[-1] | |
filename_and_path = (filename, path) | |
files_in_project_folder.append(filename_and_path) | |
# Get all files in pbxproj | |
pbxproj_file = XcodeProject.load(sys.argv[2]) | |
ids_from_pbxproj = pbxproj_file.get_ids() | |
pbxproj_filenames = [] | |
for id_file in ids_from_pbxproj: | |
id_filename = id_file._get_comment() | |
try: | |
if id_filename.split('.')[-1] == TYPE_OF_FILE: | |
pbxproj_filenames.append(id_filename) | |
except: | |
pass | |
print("Files not referenced in pbxproj") | |
for filename, path in files_in_project_folder: | |
if filename not in pbxproj_filenames: | |
print(path) | |
folder_filesnames = [i[0] for i in files_in_project_folder] | |
repeated_files = [item for item, count in collections.Counter(folder_filesnames).items() if count > 1] | |
indices = [] | |
for filename in repeated_files: | |
indices += [i for i, x in enumerate(files_in_project_folder) if x[1] == filename] | |
print() | |
print("Repeated files") | |
for index in indices: | |
print(files_in_project_folder[indexFile][1]) |
I'm getting this error:
Traceback (most recent call last):
File "xcodeproj_cleaner.py", line 1, in <module>
from pbxproj import XcodeProject
ModuleNotFoundError: No module named 'pbxproj'
I don't have that python module installed, how can I (or how should I) install it?
@rogerluan try sudo pip install pbxproj
. Other options you can see in https://github.com/kronenthaler/mod-pbxproj
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To use:
python3 xcodeproj_cleaner.py '<code-folder-path>' '<pbxproj-path>'