コード例 #1
0
    def _parseConstraints(self, xml):
        """

        Create list of constraint (objects Constraint)

        :param xml:
        :return:
        """
        if xml.nodeName != "table":
            raise ParseError("Element is not a table", "_parseConstraints")

        list = []
        xmlConstraints = xml.getElementsByTagName("constraint")
        for item in xmlConstraints:
            constraint = Constraint()
            attributes = item.attributes.items()
            for name, val in attributes:
                if name.lower() == "name":
                    constraint.name = val
                elif name.lower() == "kind":
                    constraint.kind = val
                elif name.lower() == "items":
                    detail = ConstraintDetail()
                    detail.value = val
                    constraint.details.append(detail)
                    constraint.items = val
                elif name.lower() == "props":
                    for prop in val.split(", "):
                        if prop == "has_value_edit":
                            constraint.has_value_edit = True
                        elif prop == "cascading_delete":
                            constraint.cascading_delete = False
                        elif prop == "full_cascading_delete":
                            constraint.cascading_delete = True
                        else:
                            raise ParseError(
                                "Invalid format of propertiess: \"{}\"".format(
                                    val), self)
                elif name.lower() == "reference":
                    constraint.reference = val
                elif name.lower() == 'expression':
                    constraint.expression = val
                else:
                    raise ParseError(
                        "Invalid attribute name \"{}\"".format(name), self)
            list.append(constraint)

            for detail_node in item.childNodes:
                if detail_node.tagName != 'item':
                    raise ParseError("item not found")
                detail = self._create_constraint_detail(detail_node._attrs)
                constraint.details.append(detail)

        return list
コード例 #2
0
    def _parseIndexes(self, xml):
        """

        Create list of indexes (object Index)

        :param xml:
        :return:
        """
        if xml.nodeName != "table":
            raise TypeError("Element is not a table")

        list = []
        xml_indexes = xml.getElementsByTagName("index")
        for item in xml_indexes:
            tmp = Index()

            attributes = item.attributes.items()
            for name, val in attributes:
                if name.lower() == "field":
                    detail = IndexDetail()
                    detail.value = val

                    tmp.details.append(detail)
                elif name.lower() == "items":
                    tmp.items = val
                elif name.lower() == "name":
                    tmp.items = val
                elif name.lower() == "props":
                    for prop in val.split(", "):
                        if prop == 'local':
                            tmp.local = True
                        if prop == "fulltext":
                            tmp.kind = "fulltext"
                        elif prop == "uniqueness":
                            tmp.kind = "uniqueness"
                        else:
                            raise ParseError(
                                "Invalid format of propertiess: \"{}\"".format(
                                    val), self)
                else:
                    raise ParseError(
                        "Invalid attribute name \"{}\"".format(name), self)

            for detail_node in item.childNodes:
                if detail_node.tagName != 'item':
                    raise Exception()
                detail = self._create_index_detail(detail_node._attrs)
                tmp.details.append(detail)
            list.append(tmp)
        return list
コード例 #3
0
    def _parseTable(self, item):
        """

        Parse table from xml

        :param xml: xml.dom.minidom.Document
        :return:
        """

        table = Table()
        attributes = item.attributes.items()
        for name, val in attributes:
            if name.lower() == "name":
                table.name = val
            elif name.lower() == "description":
                table.descr = val
            elif name.lower() == "props":
                for prop in val.split(", "):
                    if prop == "add":
                        table.add = True
                    elif prop == "edit":
                        table.edit = True
                    elif prop == "delete":
                        table.delete = True
                    else:
                        raise ParseError(
                            "Invalid format of propertiess: \"{}\" ".format(
                                val), self)
        return table
コード例 #4
0
    def create_constraint(self, attr_dict):
        constraint = Constraint()

        if attr_dict is None:
            return constraint

        constraint_id = None
        table_id = None

        for attr in attr_dict:
            if attr == 'name':
                constraint.name = attr_dict[attr]
            elif attr == 'constraint_type':
                constraint.kind = attr_dict[attr]
            elif attr == 'items':
                detail = ConstraintDetail()
                detail.value = attr_dict[attr]
                constraint.details.append(detail)
            elif attr == 'reference':
                constraint.reference = attr_dict[attr]
            elif attr == 'unique_key_id':
                constraint.constraint = attr_dict[attr]
            elif attr == 'expression':
                constraint.expression = attr_dict[attr]
            elif attr == 'has_value_edit':
                constraint.has_value_edit = attr_dict[attr]
            elif attr == 'cascading_delete':
                constraint.cascading_delete = attr_dict[attr]
            elif attr == 'id':
                constraint_id = attr_dict[attr]
            elif attr == 'table_id':
                table_id = attr_dict[attr]
            else:
                raise ParseError("Unsupported attribute {}".format(attr), self)
        return constraint, constraint_id, table_id
コード例 #5
0
    def create_index(self, attr_dict):
        index = Index()

        if attr_dict is None:
            return index

        index_id = None
        table_id = None

        for attr in attr_dict:
            if attr == 'name':
                index.name = attr_dict[attr]
            elif attr == 'field':
                detail = IndexDetail()
                detail.value = attr_dict[attr]
                index.details.append(detail)
            elif attr == 'kind':
                index.kind = attr_dict[attr]
            elif attr == 'local':
                index.local = attr_dict[attr]
            elif attr == 'uniqueness':
                index.uniqueness = attr_dict[attr]
            elif attr == 'fulltext':
                index.fulltext = attr_dict[attr]
            elif attr == 'id':
                index_id = attr_dict[attr]
            elif attr == 'table_id':
                table_id = attr_dict[attr]
            else:
                raise ParseError("Unsupported attribute {}".format(attr), self)
        return index, index_id, table_id
コード例 #6
0
    def create_table(self, attr_dict):
        table = Table()

        table_id = None
        schema_id = None

        for attr in attr_dict:
            if attr == 'name':
                table.name = attr_dict[attr]
            elif attr == 'description':
                table.descr = attr_dict[attr]
            elif attr == 'temporal_mode':
                table.ht_table_flags = attr_dict[attr]
            elif attr == 'access_level':
                table.access_level = attr_dict[attr]
            elif attr == 'can_add':
                table.add = attr_dict[attr]
            elif attr == 'can_edit':
                table.edit = attr_dict[attr]
            elif attr == 'can_delete':
                table.delete = attr_dict[attr]
            elif attr == 'means':
                table.means = attr_dict[attr]
            elif attr == 'schema_id':
                schema_id = attr_dict[attr]
            elif attr == 'id':
                table_id = attr_dict[attr]
            else:
                raise ParseError("Unsupported attribute {}".format(attr), self)
        return table, table_id, schema_id
コード例 #7
0
    def convertRam2Xml(self, schema, xml_path):
        """
        Create ram representation of incoming Schema object
        :param schema:
        :param xml_path:
        :return:
        """
        if schema is None:
            raise ParseError("Schema not found", self)
        node = self.create_schema(schema)
        node.appendChild(self.xml.createElement("custom"))
        if schema.domains:
            domains = self.xml.createElement("domains")
            for domain in self.create_domain(schema.domains):
                domains.appendChild(domain)
            node.appendChild(domains)

        tables = self.xml.createElement("tables")
        for table in self.create_table(schema.tables):
            tables.appendChild(table)

        node.appendChild(tables)
        try:
            self.xml.appendChild(node)
            if xml_path:
                Writer.write_xml(xml_path, self.xml)
        except Exception:
            raise ItemNotFoundException("domains, tables", schema.name)
コード例 #8
0
    def _parseDomains(self):
        """

        Create list of domains (objects Domain)

        :param xml: xml.dom.minidom.Document
        :return:
        """
        list = []
        domain_parent = self.xml.getElementsByTagName("domain")
        for item in domain_parent:
            domain = Domain()
            attributes = item.attributes.items()
            for name, val in attributes:
                if name.lower() == "name":
                    domain.name = val
                elif name.lower() == "description":
                    domain.descr = val
                elif name.lower() == "type":
                    domain.type = val
                elif name.lower() == "align":
                    domain.align = val
                elif name.lower() == "width":
                    domain.width = val
                elif name.lower() == "precision":
                    domain.precision = val
                elif name.lower() == "char_length":
                    domain.char_length = val
                elif name.lower() == "length":
                    domain.length = val
                elif name.lower() == "scale":
                    domain.scale = val
                elif name.lower() == "props":
                    for prop in val.split(", "):
                        if prop == "show_null":
                            domain.show_null = True
                        elif prop == "summable":
                            domain.summable = True
                        elif prop == "case_sensitive":
                            domain.case_sensitive = True
                        elif prop == "show_lead_nulls":
                            domain.show_lead_nulls = True
                        elif prop == "thousands_separator":
                            domain.thousands_separator = True
                        else:
                            raise ParseError(
                                "Invalid format of propertiess: \"{}\"".format(
                                    val), self)
            list.append(domain)
        return list
コード例 #9
0
 def _create_constraint_detail(self, attr_dict):
     """
     Create detail of constraint
     :param attr_dict:
     :return:
     """
     detail = ConstraintDetail()
     for attr, val in attr_dict:
         if attr == 'value':
             detail.value = val
         else:
             raise ParseError("Invalid attribute name \"{}\"".format(attr),
                              self)
     return detail
コード例 #10
0
    def create_constraint_detail(self, attr_dict):
        detail = ConstraintDetail()

        detail_id = None
        constraint_id = None

        for attr in attr_dict:
            if attr == 'field_name':
                detail.value = attr_dict[attr]
            elif attr == 'id':
                detail_id = attr_dict[attr]
            elif attr == 'constraint_id':
                constraint_id = attr_dict[attr]
            else:
                raise ParseError("Unsupported attribute {}".format(attr), self)
        return detail, detail_id, constraint_id
コード例 #11
0
 def create_schema(self, schema_row):
     schema = Schema()
     schema_id = None
     for attr in schema_row:
         if attr == 'name':
             schema.name = schema_row[attr]
         elif attr == 'fulltext_engine':
             schema.fulltext_engine = schema_row[attr]
         elif attr == 'version':
             schema.version = schema_row[attr]
         elif attr == 'description':
             schema.descr = schema_row[attr]
         elif attr == 'id':
             schema_id = schema_row[attr]
         else:
             raise ParseError("Unsupported attribute {}".format(attr), self)
     return schema, schema_id
コード例 #12
0
 def _create_index_detail(self, attr_dict):
     """
     Create detail of index
     :param attr_dict:
     :return:
     """
     detail = IndexDetail()
     for attr, val in attr_dict:
         if attr == 'value':
             detail.value = val
         elif attr == 'expression':
             detail.expression = val
         elif attr == 'descend':
             detail.descend = val
         else:
             raise ParseError("Invalid attribute name \"{}\"".format(attr),
                              self)
     return detail
コード例 #13
0
    def create_index_detail(self, attr_dict):
        detail = IndexDetail()

        detail_id = None
        index_id = None

        for attr in attr_dict:
            if attr == 'field_name':
                detail.value = attr_dict[attr]
            elif attr == 'expression':
                detail.expression = attr_dict[attr]
            elif attr == 'descend':
                detail.descend = attr_dict[attr]
            elif attr == 'id':
                detail_id = attr_dict[attr]
            elif attr == 'index_id':
                index_id = attr_dict[attr]
            else:
                raise ParseError("Unsupported attribute {}".format(attr), self)
        return detail, detail_id, index_id
コード例 #14
0
 def _parseSchema(self):
     """
     Create schema from xml
     :param xml: xml.dom.minidom.Document
     :return: Schema
     """
     schema = Schema()
     attributes = self.xml.documentElement.attributes.items()
     for name, val in attributes:
         if name.lower() == "name":
             schema.name = val
         elif name.lower() == "version":
             schema.version = val
         elif name.lower() == "fulltext_engine":
             schema.fulltext_engine = val
         elif name.lower() == "description":
             schema.descr = val
         else:
             raise ParseError("Invalid attribute name \"{}\"".format(name),
                              self)
     return schema
コード例 #15
0
    def create_domain(self, attr_dict):
        domain = Domain()

        domain_id = None
        for attr in attr_dict:
            if attr == 'name':
                domain.name = attr_dict[attr]
            elif attr == 'data_type_name':
                domain.type = attr_dict[attr]
            elif attr == 'data_type_id':
                domain.type = attr_dict[attr]
            elif attr == 'align':
                domain.align = attr_dict[attr]
            elif attr == 'width':
                domain.width = attr_dict[attr]
            elif attr == 'char_length':
                domain.char_length = attr_dict[attr]
            elif attr == 'description':
                domain.descr = attr_dict[attr]
            elif attr == 'length':
                domain.length = attr_dict[attr]
            elif attr == 'scale':
                domain.scale = attr_dict[attr]
            elif attr == 'precision':
                domain.precision = attr_dict[attr]
            elif attr == 'case_sensitive':
                domain.case_sensitive = attr_dict[attr]
            elif attr == 'show_null':
                domain.show_null = attr_dict[attr]
            elif attr == 'show_lead_nulls':
                domain.show_lead_nulls = attr_dict[attr]
            elif attr == 'thousands_separator':
                domain.thousands_separator = attr_dict[attr]
            elif attr == 'summable':
                domain.summable = attr_dict[attr]
            elif attr == 'id':
                domain_id = attr_dict[attr]
            else:
                raise ParseError("Unsupported attribute {}".format(attr), self)
        return domain, domain_id
コード例 #16
0
    def create_field(self, attr_dict):
        field = Field()

        field_id = None
        table_id = None

        for attr in attr_dict:
            if attr == 'name':
                field.name = attr_dict[attr]
            elif attr == 'russian_short_name':
                field.rname = attr_dict[attr]
            elif attr == 'domain_name':
                field.domain = attr_dict[attr]
            elif attr == 'type':
                field.type = attr_dict[attr]
            elif attr == 'description':
                field.descr = attr_dict[attr]
            elif attr == 'can_input':
                field.input = attr_dict[attr]
            elif attr == 'can_edit':
                field.edit = attr_dict[attr]
            elif attr == 'show_in_grid':
                field.show_in_grid = attr_dict[attr]
            elif attr == 'show_in_details':
                field.show_in_details = attr_dict[attr]
            elif attr == 'is_mean':
                field.is_mean = attr_dict[attr]
            elif attr == 'autocalculated':
                field.autocalculated = attr_dict[attr]
            elif attr == 'required':
                field.required = attr_dict[attr]
            elif attr == 'id':
                field_id = attr_dict[attr]
            elif attr == 'table_id':
                table_id = attr_dict[attr]
            else:
                raise ParseError("Unsupported attribute {}".format(attr), self)
        return field, field_id, table_id
コード例 #17
0
ファイル: gpx_import.py プロジェクト: ervbrian/GpxProcessor
 def import_gpx(filename: PathLike):
     try:
         return ET.parse(filename)
     except Exception as e:
         raise ParseError(f"GPX file {filename} could not be parsed. {e}")
コード例 #18
0
    def _parseFields(self, xml):
        """

        Create list of fields (objects Field)

        :param xml:
        :return:
        """
        if xml.nodeName != "table":
            raise ParseError("Element is not a table", "_parseFields")

        list = []
        xml_fields = xml.getElementsByTagName("field")
        for item in xml_fields:
            field = Field()
            domain = Domain()
            attributes = item.attributes.items()
            for name, val in attributes:
                if name.lower() == "name":
                    field.name = val
                elif name.lower() == "rname":
                    field.rname = val
                elif name.lower() == "domain":
                    field.domain = val
                elif name.lower() == "props":
                    for prop in val.split(", "):
                        if prop == "input":
                            field.input = True
                        elif prop == "edit":
                            field.edit = True
                        elif prop == "show_in_grid":
                            field.show_in_grid = True
                        elif prop == "show_in_details":
                            field.show_in_details = True
                        elif prop == "is_mean":
                            field.is_mean = True
                        elif prop == "autocalculated":
                            field.autocalculated = True
                        elif prop == "required":
                            field.required = True
                        else:
                            raise ParseError(
                                "Invalid format of propertiess: \"{}\"".format(
                                    val), self)
                elif name.lower() == "description":
                    field.descr = val
                elif name.lower() == "domain.char_length":
                    domain.char_length = val
                elif name.lower() == "domain.precision":
                    domain.precision = val
                elif name.lower() == "domain.scale":
                    domain.scale = val
                elif name.lower() == "domain.type":
                    domain.type = val
                else:
                    raise ParseError(
                        "Invalid attribute name \"{}\"".format(name), self)
            field.domain = domain
            list.append(field)

        return list