Skip to content

Commit

Permalink
fix getting database attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
khaledk2 committed Aug 19, 2024
1 parent 6b2c208 commit 018c5cc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
5 changes: 2 additions & 3 deletions manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
20 changes: 11 additions & 9 deletions omero_search_engine/database/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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))

0 comments on commit 018c5cc

Please sign in to comment.