def run(args): EcsEntry.objects.all().delete() parser = EcsFileParser(args[1]) try: inserter = BulkInserter(EcsEntry) while True: entries = parser.next_ecs_entry() if not entries: break for entry in entries: inserter.save(entry) inserter.close() except Exception: inserter.rollback() raise
def testSave(self): self.dummy_obj.save() generic_inserter = BulkInserter(BulkInserterTestModel) generic_inserter.save(self.obj) generic_inserter.save(self.obj2) generic_inserter.close() tests = BulkInserterTestModel.objects.all() eq_(tests[0].int_field, self.obj.int_field) eq_(tests[0].char_field, self.obj.char_field) eq_(tests[0].fk_field, self.obj.fk_field) eq_(tests[1].int_field, self.obj2.int_field) eq_(tests[1].char_field, self.obj2.char_field) eq_(tests[1].fk_field, self.obj2.fk_field)
def run(args): try: parser = geovision.text_to_db.sample_parser.SamplefileParser(args[1]) except IOError: print "Unable to open file", args[1] sys.exit(1); if ImportedData.objects.filter(type='sample', data=parser.sample).exists(): print("Warning: Not importing sample %s because it already exists" % parser.sample) sys.exit(1) try: inserter = BulkInserter(Read) read_entry = parser.next_read() while read_entry is not None: inserter.save(read_entry) read_entry = parser.next_read() inserter.close() ImportedData.objects.create(type='sample', data=parser.sample) except Exception as e: inserter.rollback() raise
def run(args): try: parser = geovision.text_to_db.db_parser.DbfileParser(args[1], args[2]) except IOError: print("Unable to open file", args[1]) sys.exit(1); if ImportedData.objects.filter(type='dbentry', data=parser.source).exists(): print("Warning: Not importing database %s because it already exists" % args[2]) sys.exit(1) try: inserter = BulkInserter(DbEntry) db_entry = parser.next_db_entry() while db_entry is not None: inserter.save(db_entry) db_entry = parser.next_db_entry() inserter.close() ImportedData.objects.create(type='dbentry', data=parser.source) except Exception as e: inserter.rollback() raise
def testObjToCsv(self): inserter = BulkInserter(BulkInserterTestModel) eq_(inserter.obj_to_csv(inserter, self.obj), "1$42$Foo$27\n") inserter.close()