"""Reads assets from S3 bucket. Rename and move them to the ripper.""" import argparse from datetime import datetime import os # basic os operations like paths from integration_scripts import logger from constants import paths as asset_paths from logic.ripper_feeder_logic import process_audio_folder, \ process_cover_folder, add_stopfiles from util.logic_utils import check_for_stopfile, check_free_space import config # Begin main control if __name__ == '__main__': # Setup commandline args parser = argparse.ArgumentParser( description='Copy asset files from S3 to target table', add_help=False) parser.add_argument( '-?', '--help', action='help', help='Show this help message and exit') parser.add_argument( '-t', '--tablenum', default=None, type=int, help='Override config table with new table ' '"ASSET_AUDIO/COVER_RIPPER_TABLE_#"' ) parser.add_argument( '-n', '--tablename', default=None, type=str, help='Override config table with passed table.' ) # Generate app begin time for logs log_date = datetime.today().strftime('%Y%m%d%H%M%S') # Create log file path log_path = os.path.join(asset_paths.target, asset_paths.log_path) # if owslogger: # owslogger.info('logging test') # get args arguments = parser.parse_args() # TERMINAL CONDITIONS logger.info('Checking free space.') check_free_space(asset_paths.target, config.MIN_FREE_SPACE_GB) # If we're doing automated runs via commandline args logger.info('Checking for stopfiles.') check_for_stopfile(arguments.tablenum) # Create log path if needed logger.info('Making log directory if needed.') os.makedirs(log_path, exist_ok=True) skipped_all_audio = False skipped_all_covers = False # Process assets if config.DO_AUDIO: logger.info('Begin processing audio.') skipped_all_audio = process_audio_folder(arguments, log_path, log_date) else: logger.info('Audio processing skipped at user request.') if config.DO_COVERS: logger.info('Begin processing covers.') skipped_all_covers = process_cover_folder( arguments, log_path, log_date) else: logger.info('Cover processing skipped at user request.') logger.info('Checking if all files skipped.') skipped_all_assets = skipped_all_audio and skipped_all_covers if arguments.tablenum and skipped_all_assets: logger.info('Adding stopfile for table {}.', arguments.tablenum) add_stopfiles(arguments.tablenum, log_path)