# distillery_outputloader ## Overview The `distillery_outputloader.py` script is a crucial component of the [[Distillery]] system, responsible for processing and uploading files, handling image metadata, and creating command strings. It plays a key role in preparing the parsed output for further processing and image generation. The main components of this script include: 1. **OutputLoader class**: The primary class containing methods for loading and processing output. 2. **S3FileHandler class**: A nested class within OutputLoader that handles file operations with AWS S3. 3. **DoFinalProcessing class**: Another nested class within OutputLoader that handles final processing of parsed output. ## Key Functions and Methods ### OutputLoader Class - [[OutputLoader load_output]]: The main method that orchestrates the entire output loading process. ### S3FileHandler Class - [[S3FileHandler download_image_from_s3_to_file_object]]: Downloads an image from [[S3]] to a file object. - [[S3FileHandler download_image_from_web_to_file_object]]: Downloads an image from a web URL to a file object. - [[S3FileHandler upload_file_object_to_S3]]: Uploads a file object to [[S3]]. - [[S3FileHandler collect_image_metadata]]: Extracts metadata from an image file. ### DoFinalProcessing Class - [[DoFinalProcessing process_and_upload_files]]: Processes and uploads files, handling both S3 and web URLs. - [[DoFinalProcessing create_command_dictionary]]: Creates a command dictionary from the processed output. - [[DoFinalProcessing create_command_string]]: Generates a command string from the command dictionary. ## Integration with Other Components The `distillery_outputloader.py` script integrates with other components of the [[Distillery]] system: - It uses the `AWSManager class` from [[distillery_aws]] for interacting with AWS services. - The processed output from this script is likely used by [[Distillery Master]] for further processing and image generation. - It may interact indirectly with [[Distillery Bot]] by preparing the final output that will be sent back to users. ## Configuration The script uses a constant `MAX_IMG_SIZE_LIMIT` to set the maximum allowed image size: ```python MAX_IMG_SIZE_LIMIT=10*1024*1024 # 10 megabytes ``` ## Error Handling The script uses a consistent error handling approach: - Each method is wrapped in a try-except block to catch and raise exceptions. - Errors are logged using the `AWSManager.print_log` method. - Error messages are collected and returned along with the processing results. ## Usage The main entry point for using this script is the `OutputLoader.load_output()` method. It takes the following parameters: - `parsed_input`: The parsed input from the user. - `parsed_output`: The parsed output to be processed. - `allowed_params`: A dictionary of allowed parameters and their rules. - `request_id`: A unique identifier for the request. - `instance_identifier`: An identifier for the current instance. - `extract_main_metadata`: A boolean flag to indicate whether to extract metadata from the main image. Example usage: ```python load_success, error_message, command_dictionary, parsed_output_after_s3_upload, metadata = await OutputLoader.load_output(parsed_input, parsed_output, allowed_params, request_id, instance_identifier) ```