Skip to content

Commit

Permalink
more accurate PBXProject name with backward compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
临寒 committed Aug 18, 2014
1 parent 173aa08 commit b4ae2ff
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion xUnique.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ def __init__(self, target_path, verbose=False):
raise SystemExit("Path must be dir '.xcodeproj' or file 'project.pbxproj'")
self.verbose = verbose
self.vprint = print if self.verbose else lambda *a, **k: None
self.proj_root = path.basename(self.xcodeproj_path) # example MyProject.xpbproj
self.proj_root = self.get_proj_root()
if not self.proj_root:
self.vprint('PBXProject name not found, using .xcodeproj dir name instead')
self.proj_root = path.basename(self.xcodeproj_path) # example MyProject.xpbproj
self.proj_json = self.pbxproj_to_json()
self.nodes = self.proj_json['objects']
self.root_hex = self.proj_json['rootObject']
Expand Down Expand Up @@ -97,6 +100,19 @@ def unique_pbxproj(self):
self.unique_project()
self.sort_pbxproj()

def get_proj_root(self):
'''PBXProject name,the root node'''
pbxproject_ptn = re_compile('(?<=PBXProject ").*(?=")')
with open(self.xcode_pbxproj_path) as pbxproj_file:
for line in pbxproj_file:
# project.pbxproj is an utf-8 encoded file
line = line.decode('utf-8')
result = pbxproject_ptn.search(line)
if result:
# Backward compatibility using suffix
return '{}.xcodeproj'.format(result.group())
return None

def unique_project(self):
"""iterate all nodes in pbxproj file:
Expand Down

0 comments on commit b4ae2ff

Please sign in to comment.