示例#1
0
文件: utils.py 项目: pard68/fraqbot
def set_properties(cls, properties, source_file):
    for property in properties:
        if not isinstance(property, dict) or 'name' not in property:
            continue

        if 'file' in property:
            file_atts = property['file']
            path = os.path.join(os.path.abspath(os.path.dirname(source_file)),
                                file_atts.pop('path', ''))
            value = load_file(path, **file_atts)
        else:
            value = property.get('data')

        setattr(cls, property['name'], value)
示例#2
0
    def process_seeds(self, seeds):
        insert = None
        if seeds:
            for table_name, info in seeds.items():
                if table_name in self.tables:
                    table = getattr(self, table_name)

                    if table.count() == 0:
                        if isinstance(info, list):
                            insert = table.bulk_insert(info)
                        elif isinstance(info, dict):
                            if 'file' in info:
                                load_kwargs = info.get('load_kwargs', {})
                                data = load_file(info['file'], **load_kwargs)
                            else:
                                data = info.get('data', [])

                            transform = info.get('transform')
                            if transform:
                                data = jsearch(transform, data)

                            insert = table.bulk_insert(data)

        return insert
 def rollback(self):
     self.__input = load_file("sh_in")
     self.__target = load_file("sh_tar")
示例#4
0
 def rollback(self):
     self.__sequences = load_file("mh_seq")