Esempio n. 1
0
    def _getFields(self, xml):
        if xml.nodeName != "table":
            raise ValueError("Is not a table")

        fields = []
        for field in xml.getElementsByTagName("field"):
            tmp = Field()
            domain = Domain()
            for attributeName, attributeValue in field.attributes.items():
                if attributeName.lower() == "name":
                    tmp.name = attributeValue
                elif attributeName.lower() == "rname":
                    tmp.rname = attributeValue
                elif attributeName == "domain":
                    tmp.domain = attributeValue
                elif attributeName.lower() == "domain.name":
                    domain.name = attributeValue
                elif attributeName.lower() == "domain.char_length":
                    domain.char_length = attributeValue
                elif attributeName.lower() == "domain.precision":
                    domain.precision = attributeValue
                elif attributeName.lower() == "domain.scale":
                    domain.scale = attributeValue
                elif attributeName.lower() == "domain.type":
                    domain.type = attributeValue
                elif attributeName.lower() == "description":
                    tmp.description = attributeValue
                elif attributeName.lower() == "props":
                    for prop in attributeValue.split(", "):
                        if prop == "input":
                            tmp.input = True
                        elif prop == "edit":
                            tmp.edit = True
                        elif prop == "show_in_grid":
                            tmp.show_in_grid = True
                        elif prop == "show_in_details":
                            tmp.show_in_details = True
                        elif prop == "is_mean":
                            tmp.is_mean = True
                        elif prop == "autocalculated":
                            tmp.autocalculated = True
                        elif prop == "required":
                            tmp.required = True
                        else:
                            raise ValueError(
                                "Invalid format of props string: {}".format(
                                    attributeValue))
                else:
                    raise ValueError(
                        "Incorrect attribute name \"{}\" in tag \"{}\" ".
                        format(attributeName, field.nodeName))
            if tmp.domain is None:
                tmp.domain = domain
            fields.append(tmp)
        return fields
Esempio n. 2
0
    def _getDomains(self):
        domains = []
        for domain in self.xml.getElementsByTagName("domain"):
            tmp = Domain()

            for attributeName, attributeValue in domain.attributes.items():
                if attributeName.lower() == "name":
                    tmp.name = attributeValue
                elif attributeName.lower() == "description":
                    tmp.description = attributeValue
                elif attributeName.lower() == "type":
                    tmp.type = attributeValue
                    tmp.type_id = postgres_utils.get_type_in_postgres(tmp)
                elif attributeName.lower() == "align":
                    tmp.align = attributeValue
                elif attributeName.lower() == "width":
                    tmp.width = attributeValue
                elif attributeName.lower() == "precision":
                    tmp.precision = attributeValue
                elif attributeName.lower() == "props":
                    for prop in attributeValue.split(", "):
                        if prop == "show_null":
                            tmp.show_null = True
                        elif prop == "summable":
                            tmp.summable = True
                        elif prop == "case_sensitive":
                            tmp.case_sensitive = True
                        elif prop == "show_lead_nulls":
                            tmp.show_lead_nulls = True
                        elif prop == "thousands_separator":
                            tmp.thousands_separator = True
                        else:
                            raise ValueError(
                                "Invalid format of props string: {}".format(
                                    attributeValue))
                elif attributeName.lower() == "char_length":
                    tmp.char_length = attributeValue
                elif attributeName.lower() == "length":
                    tmp.length = attributeValue
                elif attributeName.lower() == "scale":
                    tmp.scale = attributeValue
                else:
                    raise ValueError(
                        "Incorrect attribute name \"{}\" in tag \"{}\" ".
                        format(attributeName, domain.nodeName))

            domains.append(tmp)
        return domains