def __addfile(xcproj, targetobj, parentgroup, filepath, settings=None): """ add single file """ if func.hasprefix(os.path.basename(filepath), u'.'): return fileref = None dirname, dirext = os.path.splitext( os.path.basename(os.path.dirname(filepath))) if dirext == u'.lproj': # create variant group group_name = os.path.basename(filepath) group_path = os.path.abspath( os.path.dirname(os.path.dirname(filepath))) vgroup = parentgroup.add_variant_group(group_path, group_name) lproj_ref = vgroup.addfile(filepath) fileref = vgroup else: # create file reference and add to group fileref = parentgroup.addfile(filepath) if not targetobj is None and not fileref is None and fileref.isa == u'PBXFileReference': # create buildfile if not header file bpisa = pbxhelper.buildphase_for_filetype(fileref.filetype()) if not bpisa == u'PBXHeadersBuildPhase': bp = targetobj.get_build_phase(bpisa, create=True) bp.add_file_reference(fileref, settings=settings)
def __setattr__(self, name, value): value = self.canonical_arg(value) if func.hasprefix(name, pbxconsts.PBX_ATTR_PREFIX): super(PBXBaseObject, self).__setattr__(name, value) self.__dirty = True else: super(PBXBaseObject, self).__setattr__(name, value)
def issubpath(subpath, parent): """ return True if 'subpath' is subpath of 'parent' """ import os parent = normalize_path(parent, autocomplete=False) subpath = normalize_path(subpath, autocomplete=False) return func.hasprefix(subpath, parent + os.sep)
def __getattribute__(self, name): if func.hasprefix(name, pbxconsts.PBX_ATTR_PREFIX): try: return super(PBXAbstract, self).__getattribute__(name) except AttributeError as e: return None #attr.getvalue(self, name) else: return super(PBXAbstract, self).__getattribute__(name)
def duplicate(self): """ override """ obj = super(XCConfigurationList, self).duplicate() for attr, val in self.__dict__.items(): if attr == u'pbx_buildConfigurations': for cfg in val: obj.addfile(cfg.duplicate()) elif func.hasprefix(attr, pbxconsts.PBX_ATTR_PREFIX): setattr(obj, attr, val) return obj
def __recursively_add(xcproj, targetobj, parentgroup, path, settings): if func.hasprefix(os.path.basename(path), u'.'): return if os.path.isfile(path): __addfile(xcproj, targetobj, parentgroup, path, settings) elif os.path.isdir(path): dirext = os.path.splitext(path)[1] filetype = pbxconsts.FILETYPE_BY_EXT.get(dirext) if not filetype is None and filetype in pbxconsts.FOLDER_FILE_TYPE: __addfile(xcproj, targetobj, parentgroup, path, settings) else: subgroup = parentgroup.addgroup(path) for fn in os.listdir(path): __recursively_add(xcproj, targetobj, subgroup, os.path.join(path, fn), settings)
def add_str_build_settings(self, name, value, seperator=' '): """ add values to an existed settings. If the value is already exists, ignore. The value of setting is a str, eg: VALID_ARCHS = "armv7 arm64"; examples: add_str_build_settings('VALID_ARCHS', 'armv7s') => VALID_ARCHS = "armv7 arm64 armv7s"; add_str_build_settings('VALID_ARCHS', ['i386', 'x86_64']) => VALID_ARCHS = "armv7 arm64 i386 x86_64"; add_str_build_settings('VALID_ARCHS', ['armv7s', 'arm64']) => VALID_ARCHS = "armv7 arm64 armv7s"; @param name the setting name @param value str or [str] @param seperator the seperator of items in setting value """ arr = [] if func.isseq(value): arr = list(value) elif not value is None: arr = [str(value)] settingval = self.get_build_setting(name, default='') for v in arr: if v is None: continue if settingval == v or func.hasprefix(settingval, v + seperator): continue if func.hassubfix(settingval, seperator + v): continue if seperator + v + seperator in settingval: continue settingval += seperator + v self.pbx_buildSettings[name] = settingval
def deduplicate_paths(self, paths): """ return deduplicate paths complete and normalize the paths, deduplicate the result """ if func.isstr(paths): return paths if not func.isseq(paths): return u'' path_dict = dict() for path in paths: normpath = path while func.hasprefix(normpath, '"') and func.hassubfix( normpath, '"'): normpath = normpath[1:len(normpath) - 1] normpath = pbxpath.normalize_path(normpath) realpath = pbxpath.realpath(self.project(), normpath) if realpath in path_dict: continue if not func.hassubfix(realpath, os.sep + '**'): p = os.path.join(realpath, '**') if p in path_dict: continue else: p = realpath[0:len(realpath) - len(os.sep + '**')] path_dict.pop(p, None) path_dict[realpath] = (path, normpath) return [ p[1] for p in sorted(path_dict.values(), key=lambda p: paths.index(p[0])) ]
def _duplicate_attr(self, attr, val): if func.hasprefix(attr, pbxconsts.PBX_ATTR_PREFIX): setattr(self, attr, val)
def pbxdict(self): """ return dict with pbx-attr and values (exclude guid) """ dic = {k[len(pbxconsts.PBX_ATTR_PREFIX):]:v \ for k, v in self.__dict__.items() if func.hasprefix(k, pbxconsts.PBX_ATTR_PREFIX)} return dic