diff --git a/manage.py b/manage.py index eb561d2..d59d825 100644 --- a/manage.py +++ b/manage.py @@ -111,13 +111,12 @@ def create_index(resource="all"): def sql_results_to_panda(): pass - +@manager.command @manager.option( "-s", "--source", - help="data source name, ndexeing all the data sources is the default", # noqa + help="data source name, restore all the data sources is the default", # noqa ) -@manager.command def restore_postgresql_database(source="all"): from omero_search_engine.database.utils import restore_database restore_database(source) diff --git a/omero_search_engine/database/utils.py b/omero_search_engine/database/utils.py index 060a096..7186aa3 100644 --- a/omero_search_engine/database/utils.py +++ b/omero_search_engine/database/utils.py @@ -34,18 +34,20 @@ def restore_database(source): sys.path.append(mm) dat_file_name = os.path.join(mm, "app_data/omero.pgdump") print(dat_file_name) - for data_source in search_omero_app.config.database_connectors.keys(): - if source.lower() != "all" and data_source.lower() != source.lower(): + print (search_omero_app.config.get("DATA_SOURCES")) + print (search_omero_app.config.database_connectors.keys()) + for data_source in search_omero_app.config.get("DATA_SOURCES"): + print(data_source["name"]) + if source and source.lower() != "all" and data_source["name"].lower() != source.lower(): continue - conn = search_omero_app.config.database_connectors[data_source] restore_command = "psql --username %s --host %s --port %s -d %s -f %s" % ( - search_omero_app.config.get("DATA_SOURCES").get("DATABASE_USER"), - search_omero_app.config.get("DATA_SOURCES").get("DATABASE_SERVER_URI"), - search_omero_app.config.get("DATA_SOURCES").get("DATABASE_PORT"), - search_omero_app.config.get("DATA_SOURCES").get("DATABASE_NAME"), + data_source.get("DATABASE").get("DATABASE_USER"), + data_source.get("DATABASE").get("DATABASE_SERVER_URI"), + data_source.get("DATABASE").get("DATABASE_PORT"), + data_source.get("DATABASE").get("DATABASE_NAME"), dat_file_name, ) - print(restore_command) + print("Resore command: %s"%restore_command) try: proc = subprocess.Popen( restore_command, @@ -54,4 +56,4 @@ def restore_database(source): ) proc.wait() except Exception as e: - print("Exception happened during dump %s" % (e)) + print("Error, exception happened during dump %s" % (e))