diff --git a/cellpack/autopack/loaders/recipe_loader.py b/cellpack/autopack/loaders/recipe_loader.py index fd21717e..cf0be99b 100644 --- a/cellpack/autopack/loaders/recipe_loader.py +++ b/cellpack/autopack/loaders/recipe_loader.py @@ -132,16 +132,6 @@ def _sanitize_format_version(recipe_data): format_version = recipe_data["format_version"] return format_version - def get_only_recipe_metadata(self): - recipe_meta_data = { - "format_version": self.recipe_data["format_version"], - "version": self.recipe_data["version"], - "name": self.recipe_data["name"], - "bounding_box": self.recipe_data["bounding_box"], - "composition": {}, - } - return recipe_meta_data - def _migrate_version(self, old_recipe): converted = False if old_recipe["format_version"] == "1.0": diff --git a/cellpack/bin/upload.py b/cellpack/bin/upload.py index 62f1b9f1..9a932ae1 100644 --- a/cellpack/bin/upload.py +++ b/cellpack/bin/upload.py @@ -8,6 +8,25 @@ from cellpack.autopack.loaders.recipe_loader import RecipeLoader +def get_recipe_metadata(loader): + """ + Extracts and returns essential metadata from a recipe for uploading + """ + try: + recipe_meta_data = { + "format_version": loader.recipe_data["format_version"], + "version": loader.recipe_data["version"], + "name": loader.recipe_data["name"], + "bounding_box": loader.recipe_data["bounding_box"], + "composition": {}, + } + if "grid_file_path" in loader.recipe_data: + recipe_meta_data["grid_file_path"] = loader.recipe_data["grid_file_path"] + return recipe_meta_data + except KeyError as e: + sys.exit(f"Recipe metadata is missing. {e}") + + def upload( recipe_path, db_id=DATABASE_IDS.FIREBASE, @@ -23,7 +42,7 @@ def upload( if FirebaseHandler._initialized: recipe_loader = RecipeLoader(recipe_path) recipe_full_data = recipe_loader._read(resolve_inheritance=False) - recipe_meta_data = recipe_loader.get_only_recipe_metadata() + recipe_meta_data = get_recipe_metadata(recipe_loader) recipe_db_handler = DBUploader(db_handler) recipe_db_handler.upload_recipe(recipe_meta_data, recipe_full_data) else: