Exemple #1
0
 def __parse_str_attr(self, pbxkey, value):
     if pbxhelper.is_valid_guid(value):
         obj = self.project().get_object(value)
         if not obj is None:
             setattr(self, pbxkey, obj)
             obj.add_referrer(self, pbxkey)
             return
     setattr(self, pbxkey, value)
Exemple #2
0
    def remove_object(self, obj):
        """ remove object from project """
        if pbxhelper.is_valid_guid(obj):
            obj = get_object(obj)

        if isinstance(obj, baseobject.PBXBaseObject):
            for guid, refer in obj.referrers().items():
                obj.remove_referrer(refer)
            self.__objects.pop(obj.guid)
Exemple #3
0
 def __delitem__(self, key):
     if pbxhelper.is_valid_guid(key):
         del self.__objects[key]
         for sec in self.__sections.values():
             sec.pop(key, None)
     else:
         objs = self.__sections.pop(key)
         for obj in objs:
             self.__objects.pop(obj.guid, None)
     assert self.__validate()
Exemple #4
0
    def _validate(self):
        resolved = []
        issues = []

        if not pbxhelper.is_valid_guid(self.guid):
            issues.append(u'illegal guid:{guid}.'.format(self.guid))
        if not self.__xcproj.get_object(self.guid) == self:
            issues.append(
                u'{o} not in project\'s object tree!!!'.format(o=self))
        return resolved, issues
Exemple #5
0
    def __keypaths_for_object(self, attrval):
        guid = None
        if isinstance(attrval, abstract.PBXAbstract):
            guid = attrval.guid
        elif pbxhelper.is_valid_guid(attrval):
            guid = attrval

        if not guid is None and guid in self.__dependencies:
            return list(self.__dependencies[guid])
        return []
Exemple #6
0
    def buildsettings(self, name, target=None, config=None, default=None):
        """ 
        get the project's common build settings,
        :param name:    the name of build setting
        :param target:  the 'PBXTarget' or 'guid' or 'target name', 
                        from which to get the build setting
        :param config:  the 'XCBuildConfiguration' or 'guid' or 'config name'
        """
        if name in [u'PROJECT_DIR', u'SRCROOT', u'SOURCE_ROOT']:
            return self.project_dir()
        elif name == u'PROJECT_NAME':
            return self.project_name()
        elif name == u'PROJECT_FILE_PATH':
            return self.__project_file_path
        else:

            def __get_setting(config, name, cfglist, default):
                cfg = config
                if cfg is None:
                    cfg = cfglist.defaultConfiguration(
                    ) if not cfglist is None else None
                elif pbxhelper.is_valid_guid(config):
                    cfg = self.get_object(config)
                elif func.isstr(config):
                    cfg = cfglist.getconfig(
                        config) if not cfglist is None else None
                if not isinstance(cfg, config_imp.XCBuildConfiguration):
                    return None
                return cfg.get_build_setting(name, default=default)

            # end of __get_setting()

            if not target is None:
                from xcodeproj.pbxproj.objects import target as target_imp
                from xcodeproj.pbxproj.objects import config as config_imp

                tobj = target
                if tobj is None:
                    tobj = func.get_list_item(self.pbx_rootObject.pbx_targets,
                                              0)
                elif pbxhelper.is_valid_guid(target):
                    tobj = self.get_object(target)
                elif func.isstr(target):
                    tobj = self.get_target(target)
                if not isinstance(tobj, target_imp.PBXTarget):
                    return None

                return __get_setting(config, name,
                                     tobj.pbx_buildConfigurationList, default)
            elif not config is None:
                return __get_setting(config, name, None, default)

        if os.getenv(u'PROJECT_FILE_PATH') == self.__project_file_path:
            return os.getenv(name)
        return None
Exemple #7
0
 def __get_setting(config, name, cfglist, default):
     cfg = config
     if cfg is None:
         cfg = cfglist.defaultConfiguration(
         ) if not cfglist is None else None
     elif pbxhelper.is_valid_guid(config):
         cfg = self.get_object(config)
     elif func.isstr(config):
         cfg = cfglist.getconfig(
             config) if not cfglist is None else None
     if not isinstance(cfg, config_imp.XCBuildConfiguration):
         return None
     return cfg.get_build_setting(name, default=default)
Exemple #8
0
 def __parse_dict_attr_val(self, dic, pbxkey):
     for k, v in dic.items():
         depkey = u'{0}.{1}'.format(pbxkey, k)
         if func.isstr(v) and pbxhelper.is_valid_guid(v):
             obj = self.project().get_object(v)
             if not obj is None:
                 obj.add_referrer(self, depkey)
                 dic[k] = obj
             else:
                 dic[k] = v
         elif func.isseq(v):
             dic[k] = self.__parse_arr_attr_val(v, depkey)
         elif func.isdict(v):
             self.__parse_dict_attr_val(v, depkey)
Exemple #9
0
 def pop(self, key, default=None):
     try:
         if pbxhelper.is_valid_guid(key):
             obj = self.__objects.pop(key, default)
             for sec in self.__sections.values():
                 sec.pop(key, None)
             return obj
         else:
             if key in self.__sections:
                 dic = self.__sections[key]
                 for guid, o in dic.items():
                     self.__objects.pop(guid, None)
                 return dic
             else:
                 return default
     finally:
         assert self.__validate()
Exemple #10
0
 def __parse_arr_attr_val(self, arr, pbxkey):
     newarr = []
     for val in arr:
         if func.isstr(val) and pbxhelper.is_valid_guid(val):
             obj = self.project().get_object(val)
             if not obj is None:
                 obj.add_referrer(self, pbxkey)
                 newarr.append(obj)
             else:
                 newarr.append(val)  # error?
         elif func.isseq(val):
             newarr.append(self.__parse_arr_attr_val(val, pbxkey))
         elif func.isdict(val):
             self.__parse_dict_attr_val(val, pbxkey)
             newarr.append(val)
         else:
             newarr.append(val)
     return newarr
Exemple #11
0
 def __contains__(self, key):
     if pbxhelper.is_valid_guid(key):
         return self.__objects.__contains__(key)
     return self.__sections.__contains__(key)
Exemple #12
0
 def __getitem__(self, key):
     if pbxhelper.is_valid_guid(key):
         return self.__objects[key]
     return self.__sections[key]
Exemple #13
0
 def get(self, key, default=None):
     if pbxhelper.is_valid_guid(key):
         return self.__objects.get(key, default)
     return self.__sections.get(key, default)