Esempio n. 1
0
 def sort_attribute_names(classes):
     if classes is not None:
         for i in range(0, len(classes)):
             attribs = classes[i]['attribs']
             for j in range(0, len(attribs)):
                 name = attribs[j]['name']
                 texname = strFunctions.texify(name)
                 attribs[j]['texname'] = texname
         for i in range(0, len(classes)):
             if 'lo_attribs' in classes[i]:
                 lo_attribs = classes[i]['lo_attribs']
                 for j in range(0, len(lo_attribs)):
                     name = lo_attribs[j]['name']
                     texname = strFunctions.texify(name)
                     lo_attribs[j]['texname'] = texname
    def __init__(self, spec_name, number, package, pkg_ref, level, version,
                 pkg_version, reqd_status):
        # members from object
        self.fullname = spec_name
        self.number = number
        self.offset = number
        self.package = package.lower()
        self.pkg_ref = pkg_ref
        self.up_package = strFunctions.upper_first(self.package)
        if reqd_status:
            self.reqd_status = 'true'
        else:
            self.reqd_status = 'false'

        self.full_pkg_command = \
            '\\{0}Package'.format(strFunctions.texify(self.fullname))
        # useful repeated text strings
        self.valid = '\\validRule{'
        self.start_b = '{'
        self.end_b = '}'

        self.level = level
        self.version = version
        self.pkg_version = pkg_version

        self.rules = []
        self.tc = 'TBC'
Esempio n. 3
0
    def __init__(self, spec_name, number, package, pkg_ref, level, version,
                 pkg_version, reqd_status):
        # members from object
        self.fullname = spec_name
        self.number = number
        self.offset = number
        self.package = package.lower()
        self.pkg_ref = pkg_ref
        self.up_package = strFunctions.upper_first(self.package)
        if reqd_status:
            self.reqd_status = 'true'
        else:
            self.reqd_status = 'false'

        self.full_pkg_command = \
            '\\{0}Package'.format(strFunctions.texify(self.fullname))
        # useful repeated text strings
        self.valid = '\\validRule{'
        self.start_b = '{'
        self.end_b = '}'

        self.level = level
        self.version = version
        self.pkg_version = pkg_version

        self.rules = []
        self.tc = 'TBC'
Esempio n. 4
0
    def __init__(self, name, extension, object_desc):
        BaseFile.BaseFile.__init__(self, name, extension)

        # change the comment delimiter and line length
        self.comment = '%'
        self.line_length = 72

        self.package = object_desc['name']
        self.fullname = object_desc['fullname']
        self.sbml_classes = object_desc['baseElements']
        self.offset = object_desc['offset']
        self.plugins = object_desc['plugins']
        self.enums = object_desc['enums']
        self.level = object_desc['base_level']
        self.version = object_desc['base_version']
        self.pkg_version = object_desc['pkg_version']
        if object_desc['required']:
            self.reqd_status = 'true'
        else:
            self.reqd_status = 'false'

        self.prim_class = []

        self.start_b = '{'
        self.end_b = '}'

        # expand the information for the classes
        self.fulltexname = strFunctions.texify(self.fullname)
        self.upper_package = strFunctions.upper_first(self.package)
        self.sort_class_names(self.sbml_classes)
        self.sort_attribute_names(self.sbml_classes)
        self.sort_enum_names(self.enums)

        self.full_pkg_command = '\\{0}Package'.format(self.fulltexname)
        self.brief_pkg_command = '\\{0}'.format(self.upper_package)
Esempio n. 5
0
    def sort_enum_names(enums):
        """
        Function to create texnames for enums

        :param enums:
        """
        if enums is not None:
            for i in range(0, len(enums)):
                name = enums[i]['name']
                texname = strFunctions.texify(name)
                enums[i]['texname'] = texname
Esempio n. 6
0
 def sort_class_names(self, classes):
     if classes is not None:
         for i in range(0, len(classes)):
             name = classes[i]['name']
             texname = strFunctions.texify(name)
             classes[i]['texname'] = texname
             # hack for render
             if name == 'Ellipse' or name == 'Rectangle':
                 texname = 'Render' + name
                 classes[i]['texname'] = texname
             if name == 'RelAbsVector':
                 self.prim_class.append(classes[i])
Esempio n. 7
0
    def update_attrib_dicts(my_list):
        """
        Update a list of attribute dictionaries.

        :param my_list: the list which we update.
        """
        for j in range(0, len(my_list)):
            if my_list[j]['type'] in [
                    'lo_element', 'element', 'inline_lo_element'
            ]:
                name = my_list[j]['element']
            else:
                name = my_list[j]['name']
            texname = strFunctions.texify(name)
            my_list[j]['texname'] = texname
Esempio n. 8
0
    def sort_class_names(self, classes):
        """
        Function to create texnames for classes.

        :param classes: list of objects (dictionaries) representing classes.
        """
        if classes is not None:
            for i in range(0, len(classes)):
                name = classes[i]['name']
                texname = strFunctions.texify(name)
                classes[i]['texname'] = texname
                # hack for render
                if name == 'Ellipse' or name == 'Rectangle':
                    texname = 'Render' + name
                    classes[i]['texname'] = texname
                if name == 'RelAbsVector':
                    self.prim_class.append(classes[i])
    def write_attribute_type_rule(self, attribute, lo=None):
        if lo:
            formatted_name = lo['formatted_name']
            refname = lo['name']
            abbrev = strFunctions.abbrev_lo_name(refname)
        else:
            formatted_name = self.formatted_name
            refname = self.name
            abbrev = self.name
        att_type = attribute['type']
        att_name = strFunctions.upper_first(attribute['name'])
        name = strFunctions.wrap_token(attribute['texname'], self.package)
        rule_type = 'String'
        if att_type == 'SId':
            return
        elif att_type == 'SIdRef':
            [ref_name, ref_type] = \
                strFunctions.get_sid_refs(attribute['element'])
            # hack for render
            if ref_name == 'StartHead' or ref_name == 'EndHead':
                ref_name = 'LineEnding'
            text = 'The value of the attribute {0} of {1} {2} object must be ' \
                   'the identifier of an existing \{3} object defined in the ' \
                   'enclosing \Model object.'\
                .format(name, self.indef, formatted_name, ref_name)
            rule_type = ref_type
        elif att_type == 'string' or att_type == 'IDREF':
            text = 'The attribute {0} on {1} {2} must have a value of data ' \
                   'type {3}.'\
                .format(name, self.indef, formatted_name,
                        strFunctions.wrap_token('string'))
        elif att_type == 'int' or att_type == 'uint':
            text = 'The attribute {0} on {1} {2} must have a value of data ' \
                   'type {3}.'\
                .format(name, self.indef, formatted_name,
                        strFunctions.wrap_token('integer'))
            rule_type = 'Integer' if att_type == 'int' else 'UnInteger'
        elif att_type == 'double':
            text = 'The attribute {0} on {1} {2} must have a value of data ' \
                   'type {3}.'\
                .format(name, self.indef, formatted_name,
                        strFunctions.wrap_token('double'))
            rule_type = 'Double'
        elif att_type == 'boolean' or att_type == 'bool':
            text = 'The attribute {0} on {1} {2} must have a value of data ' \
                   'type {3}.'\
                .format(name, self.indef, formatted_name,
                        strFunctions.wrap_token('boolean'))
            rule_type = 'Boolean'
        elif att_type == 'UnitSId' or att_type == 'UnitSIdRef':
            text = 'The value of the attribute {0} on {1} {2} must have a ' \
                   'taken from the following: the identifier of a ' \
                   '\\UnitDefinition object in the enclosing \Model, or one ' \
                   'of the base units in SBML.'.format(name,
                                                       self.indef,
                                                       formatted_name)
            rule_type = 'Unit'
        elif att_type == 'enum':
            enum_name = strFunctions.texify(attribute['element'])
            enums = attribute['parent']['root']['enums']
            enum_values = self.parse_enum_values(attribute['element'], enums)
            text = 'The value of the attribute {0} of {1} {2} object must ' \
                   'conform to the syntax of SBML data type {3} and ' \
                   'may only take on the allowed values of {3} defined ' \
                   'in SBML; that is, the value must be one of the ' \
                   'following: {4}.'.format(name, self.indef,
                                            formatted_name,
                                            strFunctions.wrap_enum(enum_name),
                                            enum_values)
            rule_type = '{0}Enum'.format(attribute['element'])
        elif att_type == 'array':
            text = 'The value of the attribute {0} of {1} {2} object must ' \
                   'be an array of values of type {3}.'\
                .format(name, self.indef, formatted_name,
                        strFunctions.wrap_token(attribute['element']))
        elif att_type == 'element' and attribute['element'] == 'RelAbsVector':
            text = 'The value of the attribute {0} of {1} {2} object must ' \
                   'conform to the syntax of SBML data type \\RelAbsVector ' \
                   'i.e. a string encoding optionally an absolute number ' \
                   'followed by an optional relative number followed ' \
                   'by a \\% sign. Adding spaces between the ' \
                   'coordinates is encouraged, but not required.'\
                .format(name, self.indef, formatted_name)
        else:
            text = 'FIXME: Encountered an unknown attribute type {0} in ' \
                   'ValidationRulesForClass'\
                .format(att_type)
#            global_variables.code_returned = \
#                global_variables.return_codes['unknown type used']

        ref = '{0}, {1}.'\
            .format(self.pkg_ref, strFunctions.wrap_section(refname))
        sev = 'ERROR'
        lib_sev = '{0}_SEV_ERROR'.format(global_variables.up_full_lib)
        short = '{0} attribute must be {1}.'.format(att_name, rule_type)
        lib_ref = 'L3V1 {0} V1 Section'.format(self.up_package)
        tc = '{0}{1}{2}MustBe{3}'.format(self.up_package, abbrev, att_name,
                                         rule_type)
        return dict({'number': self.number, 'text': text,
                     'reference': ref, 'severity': sev, 'typecode': tc,
                     'lib_sev': lib_sev, 'short': short, 'lib_ref': lib_ref,
                     'object': refname, 'attrib': att_name,
                     'attrib_type': att_type})
Esempio n. 10
0
 def sort_enum_names(enums):
     if enums is not None:
         for i in range(0, len(enums)):
             name = enums[i]['name']
             texname = strFunctions.texify(name)
             enums[i]['texname'] = texname