Beispiel #1
0
    def run(self, data_type, file_pattern, xml_file):
        try:
            import progressbar

            progress = progressbar.ProgressBar(
                widgets=["Parsing Files ", progressbar.Percentage(), " ", progressbar.Bar()]
            )
        except:
            progress = list

        catalog = parser.MergedCatalog(
            [
                parser.XmlFileCatalog(xml_file),
                parser.BlockFileCatalog(glob.glob(file_pattern), parser.get_block_parser(data_type)(data_type)),
            ]
        )
        if catalog.has_model(data_type):
            db.session.query(catalog.get_model(data_type)).delete()
            catalog.parse()
            for entry_id in progress(catalog.get_entry_ids()):
                entry = catalog.get_entry_model(entry_id)
                db.session.add(entry)
            print(u"Committing to database...")
            db.session.commit()
        else:
            print("Unknown data type: {}".format(data_type))
 def test_basics(self):
     filenames = [self.get_fixture_filename(f) for f in self.FIXTURES]
     catalog = parser.MergedCatalog([
         parser.XmlFileCatalog(self.get_fixture_filename(self.XML_FILE)),
         parser.BlockFileCatalog(filenames, parser.get_block_parser("power")("power")),
         ])
     catalog.parse()
     for fixture_result in self.FIXTURES.itervalues():
         result = catalog.get_entry_model(fixture_result["id"])
         self.assertEqual(
                 exclude_keys(result.as_dict(), ["text", "sourcebook"]),
                 fixture_result,
                 )