def privCompileAttribDescs(entTypeClass):
        if '_attribDescs' in entTypeClass.__dict__:
            return
        c = entTypeClass
        EntityTypeDesc.notify.debug('compiling attrib descriptors for %s' %
                                    c.__name__)
        for base in c.__bases__:
            EntityTypeDesc.privCompileAttribDescs(base)

        blockAttribs = c.__dict__.get('blockAttribs', [])
        baseADs = []
        bases = list(c.__bases__)
        mostDerivedLast(bases)
        for base in bases:
            for desc in base._attribDescs:
                if desc.getName() in blockAttribs:
                    continue
                for d in baseADs:
                    if desc.getName() == d.getName():
                        EntityTypeDesc.notify.warning(
                            '%s inherits attrib %s from multiple bases' %
                            (c.__name__, desc.getName()))
                        break
                else:
                    baseADs.append(desc)

        attribDescs = []
        if 'attribs' in c.__dict__:
            for attrib in c.attribs:
                desc = AttribDesc.AttribDesc(*attrib)
                if desc.getName(
                ) == 'type' and entTypeClass.__name__ != 'Entity':
                    EntityTypeDesc.notify.error(
                        "(%s): '%s' is a reserved attribute name" %
                        (entTypeClass.__name__, desc.getName()))
                for ad in baseADs:
                    if ad.getName() == desc.getName():
                        baseADs.remove(ad)
                        break

                attribDescs.append(desc)

        c._attribDescs = baseADs + attribDescs
Ejemplo n.º 2
0
    def __init__(self, entityTypeModule):
        self.entTypeModule = entityTypeModule
        hv = HashVal()
        import EntityTypes
        reload(EntityTypes)
        reload(self.entTypeModule)

        def getPyExtVersion(filename):
            base, ext = os.path.splitext(filename)
            if ext == '.pyc' or ext == '.pyo':
                filename = base + '.py'
            return filename

        fileLines = file(getPyExtVersion(EntityTypes.__file__)).readlines()
        hv.hashString(string.join(fileLines))
        s = str(hv.asHex())
        s += '.'
        fileLines = file(getPyExtVersion(
            self.entTypeModule.__file__)).readlines()
        hv.hashString(string.join(fileLines))
        s += str(hv.asHex())
        self.hashStr = s
        getPyExtVersion = None
        classes = []
        for key, value in entityTypeModule.__dict__.items():
            if type(value) is types.ClassType:
                if issubclass(value, EntityTypeDesc.EntityTypeDesc):
                    classes.append(value)

        self.entTypeName2typeDesc = {}
        mostDerivedLast(classes)
        for c in classes:
            if c.__dict__.has_key('type'):
                if self.entTypeName2typeDesc.has_key(c.type):
                    EntityTypeRegistry.notify.debug(
                        "replacing %s with %s for entity type '%s'" %
                        (self.entTypeName2typeDesc[c.type].__class__, c,
                         c.type))
                self.entTypeName2typeDesc[c.type] = c()

        self.output2typeNames = {}
        for typename, typeDesc in self.entTypeName2typeDesc.items():
            if typeDesc.isConcrete():
                if hasattr(typeDesc, 'output'):
                    outputType = typeDesc.output
                    self.output2typeNames.setdefault(outputType, [])
                    self.output2typeNames[outputType].append(typename)

        self.permanentTypeNames = []
        for typename, typeDesc in self.entTypeName2typeDesc.items():
            if typeDesc.isPermanent():
                self.permanentTypeNames.append(typename)

        self.typeName2derivedTypeNames = {}
        for typename, typeDesc in self.entTypeName2typeDesc.items():
            typenames = []
            for tn, td in self.entTypeName2typeDesc.items():
                if td.isConcrete():
                    if issubclass(td.__class__, typeDesc.__class__):
                        typenames.append(tn)

            self.typeName2derivedTypeNames[typename] = typenames

        return