Beispiel #1
0
    def __parseDynamicAttr(self, node, attr, isArray):
        """
        Parse xml-node 'dynamic_attribute' or 'dynamic_array'
        """

        if attr.hasAttribute('name'):
            name = attr.getAttribute('name')
        elif attr.hasAttribute('Name'):
            name = attr.getAttribute('Name')
        else:
            name = ''

        strings = name.split('/')
        if not strings:
            print('error: Dynamic attribute wrong name \"{0}\" for node \"{1}\". It must contain \
                at least one character. Dynamic attribute will not be loaded!'.format(name, node.name))
            return None

        if not strings[-1]:
            print('error: Dynamic attribute wrong name \"{0}\" (full name is \"{1}\") for node \"{2}\". \
                    It must contain at least one character. Dynamic attribute will not be loaded!'
                  .format(strings[-1], name, node.name))
            return None

        if attr.hasAttribute('depend_on'):
            control = attr.getAttribute('depend_on')
        else:
            control = ''

        if not control:
            print('error: Dynamic attribute \"{0}\" for node \"{1}\" have no dependency. \
                    Please, fill xml-attribute \"depend_on\". Dynamic attribute will not be loaded!'
                  .format(name, node.name))
            return None

        if control not in node:
            print('error: No dependent attribute \"{0}\" in node \"{1}\" for dynamic attribute \"{2}\". \
                  Dynamic attribute will not be loaded!'.format(control, node.name, name))
            return None

        dependentAttr = node[control]
        default = dependentAttr.value2str(dependentAttr.defaultValue())
        print('debug: Default key for dynamic attribute \'{0}\' of node \'{1}\' will be \'{2}\''
              .format(name, node.name, default))

        if attr.hasAttribute('description'):
            desc = attr.getAttribute('description')
            desc = processString(desc)
        elif attr.hasAttribute('Description'):
            desc = attr.getAttribute('Description')
            desc = processString(desc)
        else:
            desc = ''

        newDynamicAttr = treenode.DynamicAttrDesc(name, desc, isArray, control, default)

        if not newDynamicAttr.subtags and isArray:
            print('error: There are not sub-tags for dynamic attribute array \"{0}\" for node \"{1}\". \
                    Arrays require at least 1 sub-tag! Dynamic attribute will not be loaded!'
                  .format(name, node.name))
            return None

        units = attr.getElementsByTagName('unit')
        for unit in units:
            newAttr = self.__parseAttr(node, unit, isArray, name, desc)
            if newAttr is not None:
                if unit.hasAttribute('keys'):
                    key = unit.getAttribute('keys')
                    keys = key.split(';')
                    while len(keys) > 1 and not keys[-1]:
                        keys.pop()
                    if not keys:
                        keys.append('')
                else:
                    keys = ['']
                newDynamicAttr.addAttribute(newAttr, keys)

        if newDynamicAttr.empty():
            print('error: There are no units for dynamic attribute \"{0}\" of node \"{1}\"! \
                    Dynamic attribute \"{0}\" will not be loaded!'.format(name, node.name))
            return None

        newDynamicAttr.correctDefault()

        return newDynamicAttr
Beispiel #2
0
    def __parseCodeGen(cls, codeGen):
        if not codeGen.hasAttribute('interface'):
            return

        codegenData = CodeGeneratorData()

        if codeGen.hasAttribute('namespace'):
            codegenData.namespace = codeGen.getAttribute('namespace')

        codegenData.interfaces = codeGen.getAttribute('interface').split()
        if not codegenData.interfaces:
            return

        baseclasses = codeGen.getAttribute('baseclass').split()
        for bc in baseclasses:
            s = bc.split('::')
            if len(s) < 2 or s[0] not in codegenData.interfaces:
                continue
            codegenData.baseClasses[s[0]] = s[1]

        appendix = codeGen.getAttribute('appendix').split()
        for ap in appendix:
            s = ap.split('::')
            if len(s) < 2 or s[0] not in codegenData.interfaces:
                continue
            codegenData.appendix[s[0]] = s[1]

        for i in codegenData.interfaces:
            if i not in codegenData.appendix:
                return

        for i in codegenData.interfaces:
            codegenData.methods[i] = dict()
            for scope in codegenData.scopes:
                codegenData.methods[i][scope] = []

        for i in codeGen.getElementsByTagName('include'):
            if i.hasAttribute('file'):
                codegenData.includes.append(i.getAttribute('file'))

        num_methods = int(0)
        for m in codeGen.getElementsByTagName('method'):
            if not m.hasAttribute('interface') or not m.hasAttribute('name'):
                continue

            iface = m.getAttribute('interface')
            if iface not in codegenData.interfaces:
                continue

            mname = m.getAttribute('name')
            if not mname:
                continue

            if m.hasAttribute('scope'):
                scope = m.getAttribute('scope')
                if scope not in codegenData.scopes:
                    scope = 'public'
            else:
                scope = 'public'

            ret = m.getAttribute('return')
            if ret is None or not ret:
                ret = 'void'

            if m.hasAttribute('modifier'):
                modifier = m.getAttribute('modifier')
            else:
                modifier = ''

            if m.hasAttribute('args'):
                args = m.getAttribute('args')
                if args:
                    args = args.replace('@ref', '&')
                    args = args.replace('@[', '<')
                    args = args.replace('@]', '>')
                    args = args.replace('^', '->')
                    args = args.replace('|', '\n')
            else:
                args = ''

            if m.hasAttribute('impl'):
                impl = m.getAttribute('impl')
                if impl:
                    impl = processString(impl)
                    impl = impl.replace('@ref', '&')
                    impl = impl.replace('@[', '<')
                    impl = impl.replace('@]', '>')
                    impl = impl.replace('^', '->')
                    impl = impl.replace('|', '\n')
            else:
                impl = ''

            if mname == '@ctor' and m.hasAttribute('init'):
                initSection = m.getAttribute('init')
                if initSection:
                    initSection = processString(initSection)
                    initSection = initSection.replace('@ref', '&')
                    initSection = initSection.replace('@[', '<')
                    initSection = initSection.replace('@]', '>')
                    initSection = initSection.replace('^', '->')
                    initSection = initSection.replace('|', '\n')
            else:
                initSection = ''

            if m.hasAttribute('force'):
                f = m.getAttribute('force').lower()
                if f not in ('no', '0', 'false'):
                    force = True
                else:
                    force = False
            else:
                force = False

            if m.hasAttribute('checked'):
                chk = m.getAttribute('checked').lower()
                if chk in ('yes', '1', 'true'):
                    checked = True
                else:
                    checked = False
            else:
                checked = True

            method = CodeGeneratorMethod(checked, force, ret, iface, mname, modifier, args, impl, initSection)
            method.index = int(len(codegenData.methods[iface][scope]))
            codegenData.methods[iface][scope].append(method)

            num_methods += int(1)

        for var in codeGen.getElementsByTagName('variable'):
            if not var.hasAttribute('interface') or not var.hasAttribute('type') or not var.hasAttribute('name'):
                continue

            iface = var.getAttribute('interface')
            if iface not in codegenData.interfaces:
                continue

            vartype = var.getAttribute('type')
            if not vartype:
                continue

            varname = var.getAttribute('name')
            if not varname:
                continue

            vartype = vartype.replace('@ref', '&')
            vartype = vartype.replace('@[', '<')
            vartype = vartype.replace('@]', '>')
            vartype = vartype.replace('^', '->')
            vartype = vartype.replace('|', '\n')

            variable = CodeGeneratorVariable(vartype, varname)
            if iface not in codegenData.variables:
                codegenData.variables[iface] = [variable]
            else:
                codegenData.variables[iface].append(variable)

        if num_methods > 0:
            cls.codegenData = codegenData
Beispiel #3
0
    def __parseNode(self, lib, node):
        nodeClass = ''
        if node.hasAttribute('class'):
            nodeClass = node.getAttribute('class')
        elif node.hasAttribute('Class'):
            nodeClass = node.getAttribute('Class')

        if nodeClass not in self.__alphabet:
            print('error: there are no class \"{0}\" in current alphabet!'.format(nodeClass))
            return False

        cls = self.__alphabet[nodeClass]

        nodeType = ''
        if node.hasAttribute('type'):
            nodeType = node.getAttribute('type')
        elif node.hasAttribute('Type'):
            nodeType = node.getAttribute('Type')

        subType = cls.get(nodeType)
        if subType is None:
            print('error: class \"{0}\" have no type \"{1}\".'.format(cls.name, nodeType))
            return False

        if node.hasAttribute('name'):
            name = node.getAttribute('name')
        elif node.hasAttribute('Name'):
            name = node.getAttribute('Name')
        else:
            name = ''

        if not name:
            print('error: each node must have name!')
            return False
        if name in lib:
            print('warning: node with name \"{0}\" is already exists.'.format(name))
            return False

        if cls.debuggable:
            if node.hasAttribute('debugDefault'):
                dbg = node.getAttribute('debugDefault').lower()
            elif node.hasAttribute('DebugDefault'):
                dbg = node.getAttribute('DebugDefault').lower()
            else:
                dbg = 'no'
            if dbg in ('yes', '1', 'true'):
                defaultDebugState = True
            else:
                defaultDebugState = False
        else:
            defaultDebugState = False

        newNode = treenode.TreeNodeDesc(name, nodeClass, nodeType, lib.libname, defaultDebugState)

        if node.hasAttribute('creator'):
            newNode.creator = node.getAttribute('creator')

        children = node.getElementsByTagName('children')
        children.extend(node.getElementsByTagName('Children'))
        for child in children:
            if child.hasAttribute('class'):
                ch_cls = child.getAttribute('class')
            elif child.hasAttribute('Class'):
                ch_cls = child.getAttribute('Class')
            else:
                ch_cls = ''
            if ch_cls not in self.__alphabet or ch_cls in newNode.childClasses:
                continue
            if child.hasAttribute('use'):
                useStr = child.getAttribute('use').lower()
            elif child.hasAttribute('Use'):
                useStr = child.getAttribute('Use').lower()
            else:
                useStr = 'no'
            if useStr in ('yes', '1', 'true'):
                newNode.childClasses.append(ch_cls)
        newNode.childClasses.sort()

        # Loading node description:---------
        if node.getElementsByTagName('description'):
            descrTag = node.getElementsByTagName('description')[0]
        elif node.getElementsByTagName('Description'):
            descrTag = node.getElementsByTagName('Description')[0]
        else:
            descrTag = None
        if descrTag is not None:
            if descrTag.hasAttribute('text'):
                descr = descrTag.getAttribute('text')
            elif descrTag.hasAttribute('Text'):
                descr = descrTag.getAttribute('Text')
            else:
                descr = ''
            if descr:
                newNode.description = processString(descr)

        # Loading node shape:---------
        if self.__shapeLib is not None:
            shapeName = ''
            if node.getElementsByTagName('shape'):
                shapeTag = node.getElementsByTagName('shape')[0]
            elif node.getElementsByTagName('Shape'):
                shapeTag = node.getElementsByTagName('Shape')[0]
            else:
                shapeTag = None
            if shapeTag is not None:
                if shapeTag.hasAttribute('name'):
                    shapeName = shapeTag.getAttribute('name')
                elif shapeTag.hasAttribute('Name'):
                    shapeName = shapeTag.getAttribute('Name')
            if shapeName in self.__shapeLib:
                newNode.shape = self.__shapeLib[shapeName]
                color = cls.defaultState().colorEnabled
                newNode.icon = newNode.shape.icon(color)

        # Loading node attributes:-------
        attrs = node.getElementsByTagName('attribute')
        attrs.extend(node.getElementsByTagName('Attribute'))
        for attr in attrs:
            newAttr = self.__parseAttr(newNode, attr, False)
            if newAttr is not None:
                newNode.addAttribute(newAttr)

        attrs = node.getElementsByTagName('array')
        attrs.extend(node.getElementsByTagName('Array'))
        for attr in attrs:
            newAttr = self.__parseAttr(newNode, attr, True)
            if newAttr is not None:
                newNode.addAttribute(newAttr)

        attrs = node.getElementsByTagName('dynamic_attribute')
        for attr in attrs:
            newAttr = self.__parseDynamicAttr(newNode, attr, False)
            if newAttr is not None:
                newNode.addAttribute(newAttr)

        attrs = node.getElementsByTagName('dynamic_array')
        for attr in attrs:
            newAttr = self.__parseDynamicAttr(newNode, attr, True)
            if newAttr is not None:
                newNode.addAttribute(newAttr)

        # Loading events:-------------------
        eventsElems = node.getElementsByTagName('events')
        for eventElem in eventsElems:
            incomingEvents = eventElem.getElementsByTagName('incoming')
            outgoingEvents = eventElem.getElementsByTagName('outgoing')
            for ev in incomingEvents:
                if ev.hasAttribute('name'):
                    evname = ev.getAttribute('name')
                    if not evname:
                        print('warning: node with name \"{0}\" has events without name!'.format(name))
                    if evname not in newNode.incomingEvents:
                        newNode.incomingEvents.append(evname)
                else:
                    print('warning: node with name \"{0}\" has events without name!'.format(name))
            for ev in outgoingEvents:
                if ev.hasAttribute('name'):
                    evname = ev.getAttribute('name')
                    if not evname:
                        print('warning: node with name \"{0}\" has events without name!'.format(name))
                    if evname not in newNode.outgoingEvents:
                        newNode.outgoingEvents.append(evname)
                else:
                    print('warning: node with name \"{0}\" has events without name!'.format(name))

        # Saving node:-------------------
        lib.insert(newNode)

        return True
Beispiel #4
0
    def __parseAttr(self, node, attr, isArray, externalName=None, externalDescription=None):
        """ Parse xml-node 'attribute' or 'array' """

        if externalName is not None and externalName:
            name = externalName
        elif attr.hasAttribute('name'):
            name = attr.getAttribute('name')
        elif attr.hasAttribute('Name'):
            name = attr.getAttribute('Name')
        else:
            name = ''

        strings = name.split('/')
        if not strings:
            print('error: Wrong attribute name \"{0}\" for node \"{1}\". It must contain at least one character. \
                Attribute will not be loaded!'.format(name, node.name))
            return None

        if not strings[-1]:
            print('error: Wrong attribute name \"{0}\" (full name is \"{1}\") for node \"{2}\". \
                It must contain at least one character. Attribute will not be loaded!'
                  .format(strings[-1], name, node.name))
            return None

        if attr.hasAttribute('type'):
            atype = attr.getAttribute('type').lower()
        elif attr.hasAttribute('Type'):
            atype = attr.getAttribute('Type').lower()
        else:
            atype = ''

        if atype not in treenode.TYPE_INFO_ALIAS:
            print('error: Attribute type \"{0}\" is not allowed! Attribute \"{1}\" for node \"{2}\" \
                will not be loaded!'.format(atype, name, node.name))
            return None

        atype = treenode.TYPE_INFO_ALIAS[atype]

        if attr.hasAttribute('description'):
            desc = attr.getAttribute('description')
            desc = processString(desc)
        elif attr.hasAttribute('Description'):
            desc = attr.getAttribute('Description')
            desc = processString(desc)
        elif externalDescription is not None:
            desc = externalDescription
        else:
            desc = ''

        newAttr = treenode.NodeAttrDesc(name, atype, isArray)
        newAttr.description = desc

        if newAttr.typeName() != atype:
            print('warning: Attribute type \"{0}\" changed to \"{1}\"! See attribute \"{2}\" in node \"{3}\"'
                  .format(atype, newAttr.typeName(), name, node.name))

        if not newAttr.subtags and isArray:
            print('error: There are no sub-tags for array \"{0}\" in node \"{1}\"! (Require at least 1 sub-tag) \
                Attribute \"{0}\" will not be loaded!'.format(name, node.name))
            return None

        if attr.hasAttribute('default'):
            defaultValue = attr.getAttribute('default')
        elif attr.hasAttribute('Default'):
            defaultValue = attr.getAttribute('Default')
        else:
            defaultValue = ''

        if attr.hasAttribute('available'):
            vals = attr.getAttribute('available')
        elif attr.hasAttribute('Available'):
            vals = attr.getAttribute('Available')
        else:
            vals = ''

        if vals:
            vals = vals.split(';')
            availableValues = []
            for v in vals:
                if not v:
                    continue
                if '|' in v:
                    value_and_text = v.split('|', 1)
                    if len(value_and_text) > 1:
                        text = value_and_text[1]
                        if '|' in text:
                            text_and_hint = text.split('|', 1)
                            text = text_and_hint[0]
                            hint = text_and_hint[1]
                        else:
                            hint = ''
                        availableValues.append((value_and_text[0], text, hint))
                    else:
                        availableValues.append((value_and_text[0], '', ''))
                else:
                    availableValues.append((v, '', ''))
            newAttr.setAvailableValuesByText(availableValues)

        if not newAttr.availableValues():
            if attr.hasAttribute('min'):
                minValue = attr.getAttribute('min')
            elif attr.hasAttribute('Min'):
                minValue = attr.getAttribute('Min')
            else:
                minValue = None
            if minValue is not None:
                newAttr.setMin(minValue)

            if attr.hasAttribute('max'):
                maxValue = attr.getAttribute('max')
            elif attr.hasAttribute('Max'):
                maxValue = attr.getAttribute('Max')
            else:
                maxValue = None
            if maxValue is not None:
                newAttr.setMax(maxValue)

        if defaultValue:
            newAttr.setDefaultValue(defaultValue)

        return newAttr
Beispiel #5
0
    def __parseDynamicAttr(self, node, attr, isArray):
        """
        Parse xml-node 'dynamic_attribute' or 'dynamic_array'
        """

        if attr.hasAttribute("name"):
            name = attr.getAttribute("name")
        elif attr.hasAttribute("Name"):
            name = attr.getAttribute("Name")
        else:
            name = ""

        strings = name.split("/")
        if not strings:
            print(
                'error: Dynamic attribute wrong name "{0}" for node "{1}". It must contain \
                at least one character. Dynamic attribute will not be loaded!'.format(
                    name, node.name
                )
            )
            return None

        if not strings[-1]:
            print(
                'error: Dynamic attribute wrong name "{0}" (full name is "{1}") for node "{2}". \
                    It must contain at least one character. Dynamic attribute will not be loaded!'.format(
                    strings[-1], name, node.name
                )
            )
            return None

        if attr.hasAttribute("depend_on"):
            control = attr.getAttribute("depend_on")
        else:
            control = ""

        if not control:
            print(
                'error: Dynamic attribute "{0}" for node "{1}" have no dependency. \
                    Please, fill xml-attribute "depend_on". Dynamic attribute will not be loaded!'.format(
                    name, node.name
                )
            )
            return None

        if control not in node:
            print(
                'error: No dependent attribute "{0}" in node "{1}" for dynamic attribute "{2}". \
                  Dynamic attribute will not be loaded!'.format(
                    control, node.name, name
                )
            )
            return None

        dependentAttr = node[control]
        default = dependentAttr.value2str(dependentAttr.defaultValue())
        print(
            "debug: Default key for dynamic attribute '{0}' of node '{1}' will be '{2}'".format(
                name, node.name, default
            )
        )

        if attr.hasAttribute("description"):
            desc = attr.getAttribute("description")
            desc = processString(desc)
        elif attr.hasAttribute("Description"):
            desc = attr.getAttribute("Description")
            desc = processString(desc)
        else:
            desc = ""

        newDynamicAttr = treenode.DynamicAttrDesc(name, desc, isArray, control, default)

        if not newDynamicAttr.subtags and isArray:
            print(
                'error: There are not sub-tags for dynamic attribute array "{0}" for node "{1}". \
                    Arrays require at least 1 sub-tag! Dynamic attribute will not be loaded!'.format(
                    name, node.name
                )
            )
            return None

        units = attr.getElementsByTagName("unit")
        for unit in units:
            newAttr = self.__parseAttr(node, unit, isArray, name, desc)
            if newAttr is not None:
                if unit.hasAttribute("keys"):
                    key = unit.getAttribute("keys")
                    keys = key.split(";")
                    while len(keys) > 1 and not keys[-1]:
                        keys.pop()
                    if not keys:
                        keys.append("")
                else:
                    keys = [""]
                newDynamicAttr.addAttribute(newAttr, keys)

        if newDynamicAttr.empty():
            print(
                'error: There are no units for dynamic attribute "{0}" of node "{1}"! \
                    Dynamic attribute "{0}" will not be loaded!'.format(
                    name, node.name
                )
            )
            return None

        newDynamicAttr.correctDefault()

        return newDynamicAttr
Beispiel #6
0
    def __parseCodeGen(cls, codeGen):
        if not codeGen.hasAttribute('interface'):
            return

        codegenData = CodeGeneratorData()

        if codeGen.hasAttribute('namespace'):
            codegenData.namespace = codeGen.getAttribute('namespace')

        codegenData.interfaces = codeGen.getAttribute('interface').split()
        if not codegenData.interfaces:
            return

        baseclasses = codeGen.getAttribute('baseclass').split()
        for bc in baseclasses:
            s = bc.split('::')
            if len(s) < 2 or s[0] not in codegenData.interfaces:
                continue
            codegenData.baseClasses[s[0]] = s[1]

        appendix = codeGen.getAttribute('appendix').split()
        for ap in appendix:
            s = ap.split('::')
            if len(s) < 2 or s[0] not in codegenData.interfaces:
                continue
            codegenData.appendix[s[0]] = s[1]

        for i in codegenData.interfaces:
            if i not in codegenData.appendix:
                return

        for i in codegenData.interfaces:
            codegenData.methods[i] = dict()
            for scope in codegenData.scopes:
                codegenData.methods[i][scope] = []

        for i in codeGen.getElementsByTagName('include'):
            if i.hasAttribute('file'):
                codegenData.includes.append(i.getAttribute('file'))

        num_methods = int(0)
        for m in codeGen.getElementsByTagName('method'):
            if not m.hasAttribute('interface') or not m.hasAttribute('name'):
                continue

            iface = m.getAttribute('interface')
            if iface not in codegenData.interfaces:
                continue

            mname = m.getAttribute('name')
            if not mname:
                continue

            if m.hasAttribute('scope'):
                scope = m.getAttribute('scope')
                if scope not in codegenData.scopes:
                    scope = 'public'
            else:
                scope = 'public'

            ret = m.getAttribute('return')
            if ret is None or not ret:
                ret = 'void'

            if m.hasAttribute('modifier'):
                modifier = m.getAttribute('modifier')
            else:
                modifier = ''

            if m.hasAttribute('override_modifier'):
                override_modifier = m.getAttribute('override_modifier')
            else:
                override_modifier = ''

            if m.hasAttribute('args'):
                args = m.getAttribute('args')
                if args:
                    args = args.replace('@ref', '&')
                    args = args.replace('@[', '<')
                    args = args.replace('@]', '>')
                    args = args.replace('^', '->')
                    args = args.replace('|', '\n')
            else:
                args = ''

            if m.hasAttribute('impl'):
                impl = m.getAttribute('impl')
                if impl:
                    impl = processString(impl)
                    impl = impl.replace('@ref', '&')
                    impl = impl.replace('@[', '<')
                    impl = impl.replace('@]', '>')
                    impl = impl.replace('^', '->')
                    impl = impl.replace('|', '\n')
            else:
                impl = ''

            if mname == '@ctor' and m.hasAttribute('init'):
                initSection = m.getAttribute('init')
                if initSection:
                    initSection = processString(initSection)
                    initSection = initSection.replace('@ref', '&')
                    initSection = initSection.replace('@[', '<')
                    initSection = initSection.replace('@]', '>')
                    initSection = initSection.replace('^', '->')
                    initSection = initSection.replace('|', '\n')
            else:
                initSection = ''

            if m.hasAttribute('force'):
                f = m.getAttribute('force').lower()
                if f not in ('no', '0', 'false'):
                    force = True
                else:
                    force = False
            else:
                force = False

            if m.hasAttribute('checked'):
                chk = m.getAttribute('checked').lower()
                if chk in ('yes', '1', 'true'):
                    checked = True
                else:
                    checked = False
            else:
                checked = True

            method = CodeGeneratorMethod(checked, force, ret, iface, mname,
                                         modifier, args, impl, initSection)
            method.overrideModifier = override_modifier
            method.index = int(len(codegenData.methods[iface][scope]))
            codegenData.methods[iface][scope].append(method)

            num_methods += int(1)

        for var in codeGen.getElementsByTagName('variable'):
            if not var.hasAttribute('interface') or not var.hasAttribute(
                    'type') or not var.hasAttribute('name'):
                continue

            iface = var.getAttribute('interface')
            if iface not in codegenData.interfaces:
                continue

            vartype = var.getAttribute('type')
            if not vartype:
                continue

            varname = var.getAttribute('name')
            if not varname:
                continue

            vartype = vartype.replace('@ref', '&')
            vartype = vartype.replace('@[', '<')
            vartype = vartype.replace('@]', '>')
            vartype = vartype.replace('^', '->')
            vartype = vartype.replace('|', '\n')

            variable = CodeGeneratorVariable(vartype, varname)
            if iface not in codegenData.variables:
                codegenData.variables[iface] = [variable]
            else:
                codegenData.variables[iface].append(variable)

        if num_methods > 0:
            cls.codegenData = codegenData
Beispiel #7
0
    def __parseAttr(self, node, attr, isArray, externalName=None, externalDescription=None):
        """ Parse xml-node 'attribute' or 'array' """

        if externalName is not None and externalName:
            name = externalName
        elif attr.hasAttribute("name"):
            name = attr.getAttribute("name")
        elif attr.hasAttribute("Name"):
            name = attr.getAttribute("Name")
        else:
            name = ""

        strings = name.split("/")
        if not strings:
            print(
                'error: Wrong attribute name "{0}" for node "{1}". It must contain at least one character. \
                Attribute will not be loaded!'.format(
                    name, node.name
                )
            )
            return None

        if not strings[-1]:
            print(
                'error: Wrong attribute name "{0}" (full name is "{1}") for node "{2}". \
                It must contain at least one character. Attribute will not be loaded!'.format(
                    strings[-1], name, node.name
                )
            )
            return None

        if attr.hasAttribute("type"):
            atype = attr.getAttribute("type").lower()
        elif attr.hasAttribute("Type"):
            atype = attr.getAttribute("Type").lower()
        else:
            atype = ""

        if atype not in treenode.TYPE_INFO_ALIAS:
            print(
                'error: Attribute type "{0}" is not allowed! Attribute "{1}" for node "{2}" \
                will not be loaded!'.format(
                    atype, name, node.name
                )
            )
            return None

        atype = treenode.TYPE_INFO_ALIAS[atype]

        if attr.hasAttribute("description"):
            desc = attr.getAttribute("description")
            desc = processString(desc)
        elif attr.hasAttribute("Description"):
            desc = attr.getAttribute("Description")
            desc = processString(desc)
        elif externalDescription is not None:
            desc = externalDescription
        else:
            desc = ""

        newAttr = treenode.NodeAttrDesc(name, atype, isArray)
        newAttr.description = desc

        if newAttr.typeName() != atype:
            print(
                'warning: Attribute type "{0}" changed to "{1}"! See attribute "{2}" in node "{3}"'.format(
                    atype, newAttr.typeName(), name, node.name
                )
            )

        if not newAttr.subtags and isArray:
            print(
                'error: There are no sub-tags for array "{0}" in node "{1}"! (Require at least 1 sub-tag) \
                Attribute "{0}" will not be loaded!'.format(
                    name, node.name
                )
            )
            return None

        if attr.hasAttribute("default"):
            defaultValue = attr.getAttribute("default")
        elif attr.hasAttribute("Default"):
            defaultValue = attr.getAttribute("Default")
        else:
            defaultValue = ""

        if attr.hasAttribute("available"):
            vals = attr.getAttribute("available")
        elif attr.hasAttribute("Available"):
            vals = attr.getAttribute("Available")
        else:
            vals = ""

        if vals:
            vals = vals.split(";")
            availableValues = []
            for v in vals:
                if not v:
                    continue
                if "|" in v:
                    value_and_text = v.split("|", 1)
                    if len(value_and_text) > 1:
                        text = value_and_text[1]
                        if "|" in text:
                            text_and_hint = text.split("|", 1)
                            text = text_and_hint[0]
                            hint = text_and_hint[1]
                        else:
                            hint = ""
                        availableValues.append((value_and_text[0], text, hint))
                    else:
                        availableValues.append((value_and_text[0], "", ""))
                else:
                    availableValues.append((v, "", ""))
            newAttr.setAvailableValuesByText(availableValues)

        if not newAttr.availableValues():
            if attr.hasAttribute("min"):
                minValue = attr.getAttribute("min")
            elif attr.hasAttribute("Min"):
                minValue = attr.getAttribute("Min")
            else:
                minValue = None
            if minValue is not None:
                newAttr.setMin(minValue)

            if attr.hasAttribute("max"):
                maxValue = attr.getAttribute("max")
            elif attr.hasAttribute("Max"):
                maxValue = attr.getAttribute("Max")
            else:
                maxValue = None
            if maxValue is not None:
                newAttr.setMax(maxValue)

        if defaultValue:
            newAttr.setDefaultValue(defaultValue)

        return newAttr
Beispiel #8
0
    def __parseNode(self, lib, node):
        nodeClass = ""
        if node.hasAttribute("class"):
            nodeClass = node.getAttribute("class")
        elif node.hasAttribute("Class"):
            nodeClass = node.getAttribute("Class")

        if nodeClass not in self.__alphabet:
            print('error: there are no class "{0}" in current alphabet!'.format(nodeClass))
            return False

        cls = self.__alphabet[nodeClass]

        nodeType = ""
        if node.hasAttribute("type"):
            nodeType = node.getAttribute("type")
        elif node.hasAttribute("Type"):
            nodeType = node.getAttribute("Type")

        subType = cls.get(nodeType)
        if subType is None:
            print('error: class "{0}" have no type "{1}".'.format(cls.name, nodeType))
            return False

        if node.hasAttribute("name"):
            name = node.getAttribute("name")
        elif node.hasAttribute("Name"):
            name = node.getAttribute("Name")
        else:
            name = ""

        if not name:
            print("error: each node must have name!")
            return False
        if name in lib:
            print('warning: node with name "{0}" is already exists.'.format(name))
            return False

        if cls.debuggable:
            if node.hasAttribute("debugDefault"):
                dbg = node.getAttribute("debugDefault").lower()
            elif node.hasAttribute("DebugDefault"):
                dbg = node.getAttribute("DebugDefault").lower()
            else:
                dbg = "no"
            if dbg in ("yes", "1", "true"):
                defaultDebugState = True
            else:
                defaultDebugState = False
        else:
            defaultDebugState = False

        newNode = treenode.TreeNodeDesc(name, nodeClass, nodeType, lib.libname, defaultDebugState)

        if node.hasAttribute("creator"):
            newNode.creator = node.getAttribute("creator")

        children = node.getElementsByTagName("children")
        children.extend(node.getElementsByTagName("Children"))
        for child in children:
            if child.hasAttribute("class"):
                ch_cls = child.getAttribute("class")
            elif child.hasAttribute("Class"):
                ch_cls = child.getAttribute("Class")
            else:
                ch_cls = ""
            if ch_cls not in self.__alphabet or ch_cls in newNode.childClasses:
                continue
            if child.hasAttribute("use"):
                useStr = child.getAttribute("use").lower()
            elif child.hasAttribute("Use"):
                useStr = child.getAttribute("Use").lower()
            else:
                useStr = "no"
            if useStr in ("yes", "1", "true"):
                newNode.childClasses.append(ch_cls)
        newNode.childClasses.sort()

        # Loading node description:---------
        if node.getElementsByTagName("description"):
            descrTag = node.getElementsByTagName("description")[0]
        elif node.getElementsByTagName("Description"):
            descrTag = node.getElementsByTagName("Description")[0]
        else:
            descrTag = None
        if descrTag is not None:
            if descrTag.hasAttribute("text"):
                descr = descrTag.getAttribute("text")
            elif descrTag.hasAttribute("Text"):
                descr = descrTag.getAttribute("Text")
            else:
                descr = ""
            if descr:
                newNode.description = processString(descr)

        # Loading node shape:---------
        if self.__shapeLib is not None:
            shapeName = ""
            if node.getElementsByTagName("shape"):
                shapeTag = node.getElementsByTagName("shape")[0]
            elif node.getElementsByTagName("Shape"):
                shapeTag = node.getElementsByTagName("Shape")[0]
            else:
                shapeTag = None
            if shapeTag is not None:
                if shapeTag.hasAttribute("name"):
                    shapeName = shapeTag.getAttribute("name")
                elif shapeTag.hasAttribute("Name"):
                    shapeName = shapeTag.getAttribute("Name")
            if shapeName in self.__shapeLib:
                newNode.shape = self.__shapeLib[shapeName]
                color = cls.defaultState().colorEnabled
                newNode.icon = newNode.shape.icon(color)

        # Loading node attributes:-------
        attrs = node.getElementsByTagName("attribute")
        attrs.extend(node.getElementsByTagName("Attribute"))
        for attr in attrs:
            newAttr = self.__parseAttr(newNode, attr, False)
            if newAttr is not None:
                newNode.addAttribute(newAttr)

        attrs = node.getElementsByTagName("array")
        attrs.extend(node.getElementsByTagName("Array"))
        for attr in attrs:
            newAttr = self.__parseAttr(newNode, attr, True)
            if newAttr is not None:
                newNode.addAttribute(newAttr)

        attrs = node.getElementsByTagName("dynamic_attribute")
        for attr in attrs:
            newAttr = self.__parseDynamicAttr(newNode, attr, False)
            if newAttr is not None:
                newNode.addAttribute(newAttr)

        attrs = node.getElementsByTagName("dynamic_array")
        for attr in attrs:
            newAttr = self.__parseDynamicAttr(newNode, attr, True)
            if newAttr is not None:
                newNode.addAttribute(newAttr)

        # Loading events:-------------------
        eventsElems = node.getElementsByTagName("events")
        for eventElem in eventsElems:
            incomingEvents = eventElem.getElementsByTagName("incoming")
            outgoingEvents = eventElem.getElementsByTagName("outgoing")
            for ev in incomingEvents:
                if ev.hasAttribute("name"):
                    evname = ev.getAttribute("name")
                    if not evname:
                        print('warning: node with name "{0}" has events without name!'.format(name))
                    if evname not in newNode.incomingEvents:
                        newNode.incomingEvents.append(evname)
                else:
                    print('warning: node with name "{0}" has events without name!'.format(name))
            for ev in outgoingEvents:
                if ev.hasAttribute("name"):
                    evname = ev.getAttribute("name")
                    if not evname:
                        print('warning: node with name "{0}" has events without name!'.format(name))
                    if evname not in newNode.outgoingEvents:
                        newNode.outgoingEvents.append(evname)
                else:
                    print('warning: node with name "{0}" has events without name!'.format(name))

        # Saving node:-------------------
        lib.insert(newNode)

        return True
Beispiel #9
0
    def __parseDynamicAttr(self, node, attr, isArray):
        """
        Parse xml-node 'dynamic_attribute' or 'dynamic_array'
        """

        if attr.hasAttribute('name'):
            name = attr.getAttribute('name')
        elif attr.hasAttribute('Name'):
            name = attr.getAttribute('Name')
        else:
            name = ''

        strings = name.split('/')
        if not strings:
            print(
                'error: Dynamic attribute wrong name \"{0}\" for node \"{1}\". It must contain \
                at least one character. Dynamic attribute will not be loaded!'.
                format(name, node.name))
            return None

        if not strings[-1]:
            print(
                'error: Dynamic attribute wrong name \"{0}\" (full name is \"{1}\") for node \"{2}\". \
                    It must contain at least one character. Dynamic attribute will not be loaded!'
                .format(strings[-1], name, node.name))
            return None

        if attr.hasAttribute('depend_on'):
            control = attr.getAttribute('depend_on')
        else:
            control = ''

        if not control:
            print(
                'error: Dynamic attribute \"{0}\" for node \"{1}\" have no dependency. \
                    Please, fill xml-attribute \"depend_on\". Dynamic attribute will not be loaded!'
                .format(name, node.name))
            return None

        if control not in node:
            print(
                'error: No dependent attribute \"{0}\" in node \"{1}\" for dynamic attribute \"{2}\". \
                  Dynamic attribute will not be loaded!'.format(
                    control, node.name, name))
            return None

        dependentAttr = node[control]
        default = dependentAttr.value2str(dependentAttr.defaultValue())
        print(
            'debug: Default key for dynamic attribute \'{0}\' of node \'{1}\' will be \'{2}\''
            .format(name, node.name, default))

        if attr.hasAttribute('description'):
            desc = attr.getAttribute('description')
            desc = processString(desc)
        elif attr.hasAttribute('Description'):
            desc = attr.getAttribute('Description')
            desc = processString(desc)
        else:
            desc = ''

        newDynamicAttr = treenode.DynamicAttrDesc(name, desc, isArray, control,
                                                  default)

        if not newDynamicAttr.subtags and isArray:
            print(
                'error: There are not sub-tags for dynamic attribute array \"{0}\" for node \"{1}\". \
                    Arrays require at least 1 sub-tag! Dynamic attribute will not be loaded!'
                .format(name, node.name))
            return None

        units = attr.getElementsByTagName('unit')
        for unit in units:
            newAttr = self.__parseAttr(node, unit, isArray, name, desc)
            if newAttr is not None:
                if unit.hasAttribute('keys'):
                    key = unit.getAttribute('keys')
                    keys = key.split(';')
                    while len(keys) > 1 and not keys[-1]:
                        keys.pop()
                    if not keys:
                        keys.append('')
                else:
                    keys = ['']
                newDynamicAttr.addAttribute(newAttr, keys)

        if newDynamicAttr.empty():
            print(
                'error: There are no units for dynamic attribute \"{0}\" of node \"{1}\"! \
                    Dynamic attribute \"{0}\" will not be loaded!'.format(
                    name, node.name))
            return None

        newDynamicAttr.correctDefault()

        return newDynamicAttr
Beispiel #10
0
    def __parseAttr(self,
                    node,
                    attr,
                    isArray,
                    externalName=None,
                    externalDescription=None):
        """ Parse xml-node 'attribute' or 'array' """

        if externalName is not None and externalName:
            name = externalName
        elif attr.hasAttribute('name'):
            name = attr.getAttribute('name')
        elif attr.hasAttribute('Name'):
            name = attr.getAttribute('Name')
        else:
            name = ''

        strings = name.split('/')
        if not strings:
            print(
                'error: Wrong attribute name \"{0}\" for node \"{1}\". It must contain at least one character. \
                Attribute will not be loaded!'.format(name, node.name))
            return None

        if not strings[-1]:
            print(
                'error: Wrong attribute name \"{0}\" (full name is \"{1}\") for node \"{2}\". \
                It must contain at least one character. Attribute will not be loaded!'
                .format(strings[-1], name, node.name))
            return None

        if attr.hasAttribute('type'):
            atype = attr.getAttribute('type').lower()
        elif attr.hasAttribute('Type'):
            atype = attr.getAttribute('Type').lower()
        else:
            atype = ''

        if atype not in treenode.TYPE_INFO_ALIAS:
            print(
                'error: Attribute type \"{0}\" is not allowed! Attribute \"{1}\" for node \"{2}\" \
                will not be loaded!'.format(atype, name, node.name))
            return None

        atype = treenode.TYPE_INFO_ALIAS[atype]

        if attr.hasAttribute('description'):
            desc = attr.getAttribute('description')
            desc = processString(desc)
        elif attr.hasAttribute('Description'):
            desc = attr.getAttribute('Description')
            desc = processString(desc)
        elif externalDescription is not None:
            desc = externalDescription
        else:
            desc = ''

        newAttr = treenode.NodeAttrDesc(name, atype, isArray)
        newAttr.description = desc

        if newAttr.typeName() != atype:
            print(
                'warning: Attribute type \"{0}\" changed to \"{1}\"! See attribute \"{2}\" in node \"{3}\"'
                .format(atype, newAttr.typeName(), name, node.name))

        if not newAttr.subtags and isArray:
            print(
                'error: There are no sub-tags for array \"{0}\" in node \"{1}\"! (Require at least 1 sub-tag) \
                Attribute \"{0}\" will not be loaded!'.format(name, node.name))
            return None

        if attr.hasAttribute('default'):
            defaultValue = attr.getAttribute('default')
        elif attr.hasAttribute('Default'):
            defaultValue = attr.getAttribute('Default')
        else:
            defaultValue = ''

        if attr.hasAttribute('available'):
            vals = attr.getAttribute('available')
        elif attr.hasAttribute('Available'):
            vals = attr.getAttribute('Available')
        else:
            vals = ''

        if vals:
            vals = vals.split(';')
            availableValues = []
            for v in vals:
                if not v:
                    continue
                if '|' in v:
                    value_and_text = v.split('|', 1)
                    if len(value_and_text) > 1:
                        text = value_and_text[1]
                        if '|' in text:
                            text_and_hint = text.split('|', 1)
                            text = text_and_hint[0]
                            hint = text_and_hint[1]
                        else:
                            hint = ''
                        availableValues.append((value_and_text[0], text, hint))
                    else:
                        availableValues.append((value_and_text[0], '', ''))
                else:
                    availableValues.append((v, '', ''))
            newAttr.setAvailableValuesByText(availableValues)

        if not newAttr.availableValues():
            if attr.hasAttribute('min'):
                minValue = attr.getAttribute('min')
            elif attr.hasAttribute('Min'):
                minValue = attr.getAttribute('Min')
            else:
                minValue = None
            if minValue is not None:
                newAttr.setMin(minValue)

            if attr.hasAttribute('max'):
                maxValue = attr.getAttribute('max')
            elif attr.hasAttribute('Max'):
                maxValue = attr.getAttribute('Max')
            else:
                maxValue = None
            if maxValue is not None:
                newAttr.setMax(maxValue)

        if defaultValue:
            newAttr.setDefaultValue(defaultValue)

        return newAttr
Beispiel #11
0
    def __parseNode(self, lib, node):
        nodeClass = ''
        if node.hasAttribute('class'):
            nodeClass = node.getAttribute('class')
        elif node.hasAttribute('Class'):
            nodeClass = node.getAttribute('Class')

        if nodeClass not in self.__alphabet:
            print('error: there are no class \"{0}\" in current alphabet!'.
                  format(nodeClass))
            return False

        cls = self.__alphabet[nodeClass]

        nodeType = ''
        if node.hasAttribute('type'):
            nodeType = node.getAttribute('type')
        elif node.hasAttribute('Type'):
            nodeType = node.getAttribute('Type')

        subType = cls.get(nodeType)
        if subType is None:
            print('error: class \"{0}\" have no type \"{1}\".'.format(
                cls.name, nodeType))
            return False

        if node.hasAttribute('name'):
            name = node.getAttribute('name')
        elif node.hasAttribute('Name'):
            name = node.getAttribute('Name')
        else:
            name = ''

        if not name:
            print('error: each node must have name!')
            return False
        if name in lib:
            print('warning: node with name \"{0}\" is already exists.'.format(
                name))
            return False

        if cls.debuggable:
            if node.hasAttribute('debugDefault'):
                dbg = node.getAttribute('debugDefault').lower()
            elif node.hasAttribute('DebugDefault'):
                dbg = node.getAttribute('DebugDefault').lower()
            else:
                dbg = 'no'
            if dbg in ('yes', '1', 'true'):
                defaultDebugState = True
            else:
                defaultDebugState = False
        else:
            defaultDebugState = False

        newNode = treenode.TreeNodeDesc(name, nodeClass, nodeType, lib.libname,
                                        defaultDebugState)

        if node.hasAttribute('creator'):
            newNode.creator = node.getAttribute('creator')

        children = node.getElementsByTagName('children')
        children.extend(node.getElementsByTagName('Children'))
        for child in children:
            if child.hasAttribute('class'):
                ch_cls = child.getAttribute('class')
            elif child.hasAttribute('Class'):
                ch_cls = child.getAttribute('Class')
            else:
                ch_cls = ''
            if ch_cls not in self.__alphabet or ch_cls in newNode.childClasses:
                continue
            if child.hasAttribute('use'):
                useStr = child.getAttribute('use').lower()
            elif child.hasAttribute('Use'):
                useStr = child.getAttribute('Use').lower()
            else:
                useStr = 'no'
            if useStr in ('yes', '1', 'true'):
                newNode.childClasses.append(ch_cls)
        newNode.childClasses.sort()

        # Loading node description:---------
        if node.getElementsByTagName('description'):
            descrTag = node.getElementsByTagName('description')[0]
        elif node.getElementsByTagName('Description'):
            descrTag = node.getElementsByTagName('Description')[0]
        else:
            descrTag = None
        if descrTag is not None:
            if descrTag.hasAttribute('text'):
                descr = descrTag.getAttribute('text')
            elif descrTag.hasAttribute('Text'):
                descr = descrTag.getAttribute('Text')
            else:
                descr = ''
            if descr:
                newNode.description = processString(descr)

        # Loading node shape:---------
        if self.__shapeLib is not None:
            shapeName = ''
            if node.getElementsByTagName('shape'):
                shapeTag = node.getElementsByTagName('shape')[0]
            elif node.getElementsByTagName('Shape'):
                shapeTag = node.getElementsByTagName('Shape')[0]
            else:
                shapeTag = None
            if shapeTag is not None:
                if shapeTag.hasAttribute('name'):
                    shapeName = shapeTag.getAttribute('name')
                elif shapeTag.hasAttribute('Name'):
                    shapeName = shapeTag.getAttribute('Name')
            if shapeName in self.__shapeLib:
                newNode.shape = self.__shapeLib[shapeName]
                color = cls.defaultState().colorEnabled
                newNode.icon = newNode.shape.icon(color)

        # Loading node attributes:-------
        attrs = node.getElementsByTagName('attribute')
        attrs.extend(node.getElementsByTagName('Attribute'))
        for attr in attrs:
            newAttr = self.__parseAttr(newNode, attr, False)
            if newAttr is not None:
                newNode.addAttribute(newAttr)

        attrs = node.getElementsByTagName('array')
        attrs.extend(node.getElementsByTagName('Array'))
        for attr in attrs:
            newAttr = self.__parseAttr(newNode, attr, True)
            if newAttr is not None:
                newNode.addAttribute(newAttr)

        attrs = node.getElementsByTagName('dynamic_attribute')
        for attr in attrs:
            newAttr = self.__parseDynamicAttr(newNode, attr, False)
            if newAttr is not None:
                newNode.addAttribute(newAttr)

        attrs = node.getElementsByTagName('dynamic_array')
        for attr in attrs:
            newAttr = self.__parseDynamicAttr(newNode, attr, True)
            if newAttr is not None:
                newNode.addAttribute(newAttr)

        # Loading events:-------------------
        eventsElems = node.getElementsByTagName('events')
        for eventElem in eventsElems:
            incomingEvents = eventElem.getElementsByTagName('incoming')
            outgoingEvents = eventElem.getElementsByTagName('outgoing')
            for ev in incomingEvents:
                if ev.hasAttribute('name'):
                    evname = ev.getAttribute('name')
                    if not evname:
                        print(
                            'warning: node with name \"{0}\" has events without name!'
                            .format(name))
                    if evname not in newNode.incomingEvents:
                        newNode.incomingEvents.append(evname)
                else:
                    print(
                        'warning: node with name \"{0}\" has events without name!'
                        .format(name))
            for ev in outgoingEvents:
                if ev.hasAttribute('name'):
                    evname = ev.getAttribute('name')
                    if not evname:
                        print(
                            'warning: node with name \"{0}\" has events without name!'
                            .format(name))
                    if evname not in newNode.outgoingEvents:
                        newNode.outgoingEvents.append(evname)
                else:
                    print(
                        'warning: node with name \"{0}\" has events without name!'
                        .format(name))

        # Saving node:-------------------
        lib.insert(newNode)

        return True