Skip to content

Commit

Permalink
add default_db for S3 metadata storage
Browse files Browse the repository at this point in the history
  • Loading branch information
rugeli committed Feb 28, 2024
1 parent f178de3 commit 329f9f5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
12 changes: 7 additions & 5 deletions cellpack/autopack/FirebaseHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ class FirebaseHandler(object):
_initialized = False
_db = None

def __init__(self):
def __init__(self, default_db=None):
# check if firebase is already initialized
if not FirebaseHandler._initialized:
db_choice = FirebaseHandler.which_db()
db_choice = FirebaseHandler.which_db(default_db=default_db)
if db_choice == "staging":
cred = FirebaseHandler.get_staging_creds()
else:
Expand All @@ -34,14 +34,16 @@ def __init__(self):

# common utility methods
@staticmethod
def which_db():
def which_db(default_db=None):
options = {"1": "dev", "2": "staging"}
print("Choose database:")
if default_db in options.values():
print(f"Using {default_db} database -------------")
return default_db
for key, value in options.items():
print(f"[{key}] {value}")
choice = input("Enter number: ").strip()
print(f"Using {options.get(choice, 'dev')} database -------------")
return options.get(choice, "dev") # default to dev db
return options.get(choice, "dev") # default to dev db for recipe uploads

@staticmethod
def doc_to_dict(doc):
Expand Down
5 changes: 4 additions & 1 deletion cellpack/autopack/interface_objects/database_ids.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ def create_aws_handler(bucket_name, sub_folder_name, region_name):
region_name=region_name,
)

def create_firebase_handler(default_db):
return FirebaseHandler(default_db=default_db)

handlers_dict = {
cls.FIREBASE: FirebaseHandler(),
cls.FIREBASE: create_firebase_handler,
cls.AWS: create_aws_handler,
}
return handlers_dict
8 changes: 6 additions & 2 deletions cellpack/autopack/upy/simularium/simularium_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -1423,8 +1423,12 @@ def store_result_file(file_path, storage=None):
@staticmethod
def store_metadata(file_name, url, db=None):
if db == "firebase":
db_handler = DBUploader(DATABASE_IDS.handlers().get(db))
db_handler.upload_result_metadata(file_name, url)
handler = DATABASE_IDS.handlers().get(db)
initialized_db = handler(
default_db="staging"
) # default to staging for metadata uploads
db_uploader = DBUploader(initialized_db)
db_uploader.upload_result_metadata(file_name, url)

@staticmethod
def open_in_simularium(aws_url):
Expand Down

0 comments on commit 329f9f5

Please sign in to comment.