From b4ae2ff11902f76e67be5a1be5bcc1e54cdad096 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=B4=E5=AF=92?= Date: Mon, 18 Aug 2014 12:51:22 +0800 Subject: [PATCH] more accurate PBXProject name with backward compatibility --- xUnique.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/xUnique.py b/xUnique.py index d9b52d6..c12ec4a 100755 --- a/xUnique.py +++ b/xUnique.py @@ -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'] @@ -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: