def cache2(): from elixr.sax.export.importer import XRefResolver def initdb(session): from elixr.sax.address import Country, State ca = Country(code='CA', name='Canada') ng = Country(code='NG', name='Nigeria') session.add_all([ ca, ng, State(code='KN', name='Kano', country=ng), # wrong code ;-D ]) from elixr.sax.party import OrganizationType ot1 = OrganizationType(name='hq', title='Headquarters', is_root=True) ot2 = OrganizationType(name='branch', title='Branch') session.add_all([ot1, ot2]) session.commit() ## setup resx = utils.make_session(initdb_callback=initdb) yield XRefResolver(resx.session) ## teardown utils.drop_tables(resx.engine)
def imp_sl(): def initdb(session): cn = Country(code='CN', name='Country') org = Organisation(identifier="Org0", name="Org.Main", short_name="Org0") session.add_all([ ## voltages Voltage(value=415), Voltage(value=11000), Voltage(value=33000), ## states State(code='S1', name='State 1', country=cn), State(code='S2', name='State 2', country=cn), ## organisations Organisation(identifier="Org1", name="Child1", short_name="Org1", parent=org), Organisation(identifier="Org2", name="Child2", short_name="Org2", parent=org), ]) session.commit() ## setup resx = utils.make_session(initdb_callback=initdb) cache = XRefResolver(resx.session) return StationLineImporter(AttrDict(db=resx.session, cache=cache)) ## teardown utils.drop_tables(resx.engine)
def _process(db, options): # check that the file exists if not os.path.exists(options['file']): print('File not found: %s' % options['file']) sys.exit(0) from openpyxl import load_workbook wb = load_workbook(options['file'], read_only=True) importer = MegaImporter(AttrDict(db=db, cache=XRefResolver(db))) importer.import_data(wb) if importer.has_errors: _log_errors(importer.summarise_errors(), *os.path.split(options['file'])) print('View error log for details...')
def cache(): from elixr.sax.export.importer import XRefResolver def initdb(session): from elixr.sax.address import Country, State ca = Country(code='CA', name='Canada') ng = Country(code='NG', name='Nigeria') session.add_all([ ca, ng, State(code='BC', name='British Columbia', country=ca), State(code='BC', name='Bauchi', country=ng), # wrong code ;-D ]) session.commit() ## setup resx = utils.make_session(initdb_callback=initdb) yield XRefResolver(resx.session) ## teardown utils.drop_tables(resx.engine)
def imp_adb(): from conftest import db, cache _db = next(db()) cache = XRefResolver(_db) return AdminBoundaryImporter({'db': _db, 'cache': cache})