diff --git a/README.md b/README.md index 84a68a4..32e3923 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,8 @@ Data shipping script for airborne products - `python3 -m pip install -e .` - `python3 main.py` +For running locally, add "storageMode": "local" to config.json + ## Generating build - `pyinstaller main.py --onefile -n airborne-dsa` diff --git a/main.py b/main.py index 31ebaf9..dec5e97 100644 --- a/main.py +++ b/main.py @@ -12,6 +12,7 @@ from services.config_manager import ConfigManager from services.file_watcher import FileWatcher +from services.local_file_manager import LocalFileManager from services.s3_file_manager import S3FileManager # from airborne_dsa.config_manager import ConfigManager @@ -159,14 +160,18 @@ def main() -> None: # Setup config = ConfigManager("config.json") - s3_client = S3FileManager( - config.aws_access_key_id, config.aws_secret_access_key, config.bucket + file_manager = ( + S3FileManager( + config.aws_access_key_id, config.aws_secret_access_key, config.bucket + ) + if config.storage_mode == "remote" + else LocalFileManager() ) mission_name, mission_time = get_mission_details() # Create mission file try: - s3_client.upload_empty_file( + file_manager.upload_empty_file( f"MISSION/{mission_name}_{mission_time.strftime('%Y%m%d_%H%M')}Z.txt" ) print(f"Created mission: {mission_name}") @@ -185,7 +190,7 @@ def upload_product(file_path: str) -> None: ) print(f"Uploading {os.path.basename(file_path)}") - s3_client.upload_file(file_path, key) + file_manager.upload_file(file_path, key) print( f"Successfully uploaded {os.path.basename(file_path)} as {key} to {config.bucket}" ) @@ -217,3 +222,4 @@ def upload_product(file_path: str) -> None: log_file = open("ERROR.txt", "w") log_file.write(str(error)) log_file.close() + print(error) diff --git a/services/config_manager.py b/services/config_manager.py index bbe1f9f..8565e1a 100644 --- a/services/config_manager.py +++ b/services/config_manager.py @@ -1,6 +1,7 @@ """Loads and validates config.json file against a config json schema""" import locale import json +from typing import Literal import jsonschema @@ -14,6 +15,7 @@ def __init__(self, file_path: str) -> None: "bucket": {"type": "string"}, "awsAccessKeyId": {"type": "string"}, "awsSecretAccessKey": {"type": "string"}, + "storageMode": {"type": "string", "enum": ["local", "remote"]}, }, "required": ["bucket", "awsAccessKeyId", "awsSecretAccessKey"], "additionalProperties": False, @@ -39,3 +41,10 @@ def aws_access_key_id(self) -> str: def aws_secret_access_key(self) -> str: """Your AWS secret key""" return self.config["awsSecretAccessKey"] + + @property + def storage_mode(self) -> Literal["local", "remote"]: + """Whether to use local or remote storage""" + return ( + "remote" if "storageMode" not in self.config else self.config["storageMode"] + ) diff --git a/services/local_file_manager.py b/services/local_file_manager.py new file mode 100644 index 0000000..5415dcc --- /dev/null +++ b/services/local_file_manager.py @@ -0,0 +1,10 @@ +class LocalFileManager: + def __init__(self) -> None: + print("Using faux file manager. No files will be uploaded") + print() + + def upload_file(self, file_path: str, key: str): + pass + + def upload_empty_file(self, file_key: str) -> None: + pass