Example #1
0
    def load(self, path):
        """Loads the structure from an XML file

        :param path: path of the file to load"""
        cls = self.__class__
        b = Bag()
        b.fromXml(path, bagcls=cls, empty=cls)
        self[''] = self.merge(b)
Example #2
0
 def load(self, path):
     """Loads the structure from an XML file
     
     :param path: path of the file to load"""
     cls = self.__class__
     b = Bag()
     b.fromXml(path, bagcls=cls, empty=cls)
     self[''] = self.merge(b)
Example #3
0
    def _structFix4D(self, struct, path):
        cnv_file = '%s_conv%s' % os.path.splitext(path)
        if os.path.isfile(cnv_file):
            return cnv_file
        cls = struct.__class__
        b = Bag()
        b.fromXml(path, bagcls=cls, empty=cls)

        convdict = {'ci_relation': None,
                    'o_name': None,
                    'o_name_short': None,
                    'o_name_full': None,
                    'o_name_long': None,
                    'many_name_short': None,
                    'many_name_full': None,
                    'many_name_long': None,
                    'eager_relation': None,
                    'len_max': None,
                    'len_min': None,
                    'len_show': None,
                    'relation': None,
                    'comment': None
        }
        #relate_attrs = set(('ci_relation', 'o_name', 'o_name_short', 'o_name_full', 'o_name_long',
        #                    'many_name_short','many_name_full','many_name_long','eager_relation'))

        for pkg in b['packages']:
            for tbl in pkg.value['tables']:
                for col in tbl.value['columns']:
                    newattrs = {}
                    for k, v in col.attr.items():
                        if v is not None:
                            lbl = convdict.get(k, k)
                            if lbl:
                                newattrs[lbl] = v
                    name_long = newattrs.get('name_long')
                    if name_long:
                        if name_long[0] == name_long[0].lower():
                            newattrs['group'] = '_'
                        if name_long.endswith('_I'):
                            name_long = name_long[:-2]
                        elif not 'indexed' in newattrs:
                            newattrs['group'] = '*'
                        if len(name_long) > 2 and name_long[2] == '_':
                            name_long = name_long[3:]
                        newattrs['name_long'] = name_long.replace('_', ' ')

                    if 'len_max' in col.attr:
                        newattrs['size'] = '%s:%s' % (col.attr.get('len_min', '0'), col.attr['len_max'])
                    if 'relation' in col.attr:
                        mode = None
                        if col.attr.get('ci_relation'):
                            mode = 'insensitive'
                        col.value = Bag()
                        col.value.setItem('relation', None, related_column=col.attr['relation'], mode=mode)
                    col.attr = newattrs
        b.toXml(cnv_file,mode4d=True)
        return cnv_file