示例#1
0
def pbxobj_set_pbxlist_attr(obj, objclass, attr, value, validator):
    """
    obj.attr is type of [PBXBaseObject] 
    """
    assert value is None or func.isseq(value)
    value = value if not value is None else []

    oldvalue = getattr(obj, attr, None)
    if not oldvalue is None:
        for oldv in oldvalue:
            oldv.remove_referrer(obj)

    if not value is None:
        rejects = []
        if func.isseq(value):
            value, rejects = func.filter_items(validator, value)
        else:
            value, rejects = ([], value)
        if len(rejects) > 0:
            logger.warn(u'{obj} ignore invalid {attr}:\n\t{v}'\
                .format(obj=obj, attr=attr[len(pbxconsts.PBX_ATTR_PREFIX):], \
                    v='\n\t'.join([str(v) for v in rejects])))

        super(objclass, obj).__setattr__(attr, value)
        for v in value:
            v.add_referrer(obj, attr)
示例#2
0
 def new_object(self, isa):
     """ create new object with 'isa' and add to the project """
     try:
         return self.__new_object(isa)
     except Exception as e:
         logger.warn(func.exception_msg(e))
         raise
         return None
示例#3
0
    def __set_project_references(self, value):
        if not func.isseq(value):
            return

        value, rejects = func.filter_items(self.is_valid_project_reference, value)
        if len(rejects) > 0:
            logger.warn(u'{0} ignore invalid project reference:\n\t{1}'\
                .format(self, u'\n\t'.join(map(lambda o: str(o), rejects))))

        super(PBXProject, self).__setattr__(u'pbx_projectReferences', value)
示例#4
0
def get_filetype(filepath):
    """ return file type for file with 'filepath' """
    ext = os.path.splitext(filepath)[1]
    if len(ext) > 0 and ext in pbxconsts.FILETYPE_BY_EXT:
        return pbxconsts.FILETYPE_BY_EXT[ext]

    mimetype, charset = get_file_info(filepath)
    if not mimetype is None and mimetype in pbxconsts.MIME_TO_FILETYPE:
        return pbxconsts.MIME_TO_FILETYPE[mimetype]
    else:
        logger.warn(u'not found PBXFileType for mimetype: {m}, path:{p}'\
            .format(m=mimetype, p=filepath))
        return u'file'
示例#5
0
    def __parse(self, plist_dict):
        objects = plist_dict.pop(u'objects', None)
        self.__plist_objects = objects if func.isdict(objects) else None

        for k, v in plist_dict.items():
            plist_dict.pop(k)
            pbxkey = u'pbx_{name}'.format(name=k)
            if k == u'rootObject':
                v = self.get_object(v)
            setattr(self, pbxkey, v)

        if len(self.__plist_objects) > 0:
            logger.warn(u'[XcodeProj] isolate objects are not be parsed:\n\t{0}'\
                .format(u'\n\t'.join([u'{0}:{1}'.format(k, v.get(u'isa')) \
                    for k, v in self.__plist_objects.items()])))
        self.__plist_objects = None  # process complete
示例#6
0
def pbxobj_set_pbxobj_attr(obj, objclass, attr, value, validator):
    """
    set value for attribute 'name'. the value is instance of PBXBaseObject
    """
    oldval = getattr(obj, attr, None)
    if not oldval is None:
        oldval.remove_referrer(obj)

    if validator(value):
        super(objclass, obj).__setattr__(attr, value)
        value.add_referrer(obj, attr)
    elif value is None:
        delattr(obj, attr)
    else:
        logger.warn(u'{obj} illegal {attr}:{val}'\
            .format(obj=obj, attr=attr[len(pbxconsts.PBX_ATTR_PREFIX):], val=value))
示例#7
0
    def validate(self):
        """
        validate project's objects,  remove the invalid objects.
        canonize the pbxproj by removing duplcated objects, resolve the object tree.
        """
        self.__validate_files()

        while self.need_validate():
            for guid, obj in self.__objects.guid_items():
                try:
                    obj.validate()
                except PBXValidationError as e:
                    self.remove_object(obj)

        isolate_objs = [obj for guid, obj in self.__objects.guid_items() \
            if not obj == self.pbx_rootObject and len(obj.referrers()) == 0]
        if len(isolate_objs) > 0:
            logger.warn(u'[XcodeProj] isolate objects:\n\t{0}'\
                .format(u'\n\t'.join([str(o) for o in isolate_objs])))
示例#8
0
 def get_object(self, guid):
     """ 
     get pbx-object with specified guid
     :param guid:    the object's guid
     """
     obj = self.__objects.get(guid)
     if obj is None and not self.__plist_objects is None:
         # self.__plist_objects is None indicates that the parsing process is finished
         objdict = self.__plist_objects.pop(guid, None)
         if func.isdict(objdict):
             objcls = objdict.pop(u'isa', None)
             if not objcls is None:
                 try:
                     obj = self.__new_object(objcls, guid)
                     obj.parse(objdict)
                 except Exception as e:
                     logger.warn(e)
                     raise
             else:
                 logger.warn(u'[XcodeProj] Bad format. "isa" not found for object:{guid}'\
                     .format(guid=guid))
         elif not objdict is None:
             logger.warn(\
                 u'[XcodeProj] {guid} invalid object dict:{dic}'.format(guid=guid, dic=objdict))
     return obj