def _recreate_database(): print("drop database") drop_database_query = "DROP DATABASE IF EXISTS {};".format( settings.get("DB_NAME")) drop_user_query = "DROP USER IF EXISTS {};".format(settings.get("DB_USER")) exec_sql(drop_database_query, user="******", database="postgres") exec_sql(drop_user_query, user="******", database="postgres") print("create database") init_database()
def _init_and_clear_database(): # creates database if necessary init_database() exec_sql("DROP OWNED BY osm_test") # prepare schema for tests current_directory = os.path.dirname(os.path.realpath(__file__)) exec_sql_from_file('helpers/schema.sql.dump', cwd=current_directory) exec_sql_from_file('helpers/functions.sql', cwd=current_directory) export_osmnames.create_functions() # necessary for export tests if not os.path.exists('/tmp/osmnames/export/'): os.makedirs('/tmp/osmnames/export/')
def run(): wait_for_database() profiler = cProfile.Profile() started_at = datetime.datetime.now() profiler.enable() init_database() import_wikipedia() import_osm() prepare_data() export_osmnames() profiler.dump_stats("data/logs/{}.cprofile".format( started_at.strftime('%Y_%m_%d-%H%M')))
#!/usr/bin/python import cProfile import datetime from osmnames.database.functions import wait_for_database from osmnames.init_database.init_database import init_database from osmnames.import_wikipedia.import_wikipedia import import_wikipedia from osmnames.import_osm.import_osm import import_osm from osmnames.prepare_data.prepare_data import prepare_data from osmnames.export_osmnames.export_osmnames import export_osmnames wait_for_database() profiler = cProfile.Profile() started_at = datetime.datetime.now() profiler.enable() init_database() import_wikipedia() import_osm() prepare_data() export_osmnames() profiler.dump_stats("data/logs/{}.cprofile".format( started_at.strftime('%Y_%m_%d-%H%M')))