def main(args): # Initialize the config core.initialize() # clientAgent for Torrents client_agent = core.TORRENT_CLIENTAGENT logger.info('#########################################################') logger.info('## ..::[{0}]::.. ##'.format(os.path.basename(__file__))) logger.info('#########################################################') # debug command line options logger.debug('Options passed into TorrentToMedia: {0}'.format(args)) # Post-Processing Result result = ProcessResult( message='', status_code=0, ) try: input_directory, input_name, input_category, input_hash, input_id = core.parse_args(client_agent, args) except Exception: logger.error('There was a problem loading variables') return -1 if input_directory and input_name and input_hash and input_id: result = process_torrent(input_directory, input_name, input_category, input_hash, input_id, client_agent) else: # Perform Manual Post-Processing logger.warning('Invalid number of arguments received from client, Switching to manual run mode ...') for section, subsections in core.SECTIONS.items(): for subsection in subsections: if not core.CFG[section][subsection].isenabled(): continue for dir_name in core.get_dirs(section, subsection, link='hard'): logger.info('Starting manual run for {0}:{1} - Folder:{2}'.format (section, subsection, dir_name)) logger.info('Checking database for download info for {0} ...'.format (os.path.basename(dir_name))) core.DOWNLOADINFO = core.get_download_info(os.path.basename(dir_name), 0) if core.DOWNLOADINFO: client_agent = text_type(core.DOWNLOADINFO[0].get('client_agent', 'manual')) input_hash = text_type(core.DOWNLOADINFO[0].get('input_hash', '')) input_id = text_type(core.DOWNLOADINFO[0].get('input_id', '')) logger.info('Found download info for {0}, ' 'setting variables now ...'.format(os.path.basename(dir_name))) else: logger.info('Unable to locate download info for {0}, ' 'continuing to try and process this release ...'.format (os.path.basename(dir_name))) client_agent = 'manual' input_hash = '' input_id = '' if client_agent.lower() not in core.TORRENT_CLIENTS: continue try: dir_name = dir_name.encode(core.SYS_ENCODING) except UnicodeError: pass input_name = os.path.basename(dir_name) try: input_name = input_name.encode(core.SYS_ENCODING) except UnicodeError: pass results = process_torrent(dir_name, input_name, subsection, input_hash or None, input_id or None, client_agent) if results.status_code != 0: logger.error('A problem was reported when trying to perform a manual run for {0}:{1}.'.format (section, subsection)) result = results if result.status_code == 0: logger.info('The {0} script completed successfully.'.format(args[0])) else: logger.error('A problem was reported in the {0} script.'.format(args[0])) del core.MYAPP return result.status_code
def main(args): # Initialize the config core.initialize() # clientAgent for Torrents client_agent = core.TORRENT_CLIENTAGENT logger.info('#########################################################') logger.info('## ..::[{0}]::.. ##'.format(os.path.basename(__file__))) logger.info('#########################################################') # debug command line options logger.debug('Options passed into TorrentToMedia: {0}'.format(args)) # Post-Processing Result result = ProcessResult( message='', status_code=0, ) try: input_directory, input_name, input_category, input_hash, input_id = core.parse_args(client_agent, args) except Exception: logger.error('There was a problem loading variables') return -1 if input_directory and input_name and input_hash and input_id: result = process_torrent(input_directory, input_name, input_category, input_hash, input_id, client_agent) else: # Perform Manual Post-Processing logger.warning('Invalid number of arguments received from client, Switching to manual run mode ...') for section, subsections in core.SECTIONS.items(): for subsection in subsections: if not core.CFG[section][subsection].isenabled(): continue for dir_name in core.get_dirs(section, subsection, link='hard'): logger.info('Starting manual run for {0}:{1} - Folder:{2}'.format (section, subsection, dir_name)) logger.info('Checking database for download info for {0} ...'.format (os.path.basename(dir_name))) core.DOWNLOADINFO = core.get_download_info(os.path.basename(dir_name), 0) if core.DOWNLOADINFO: client_agent = text_type(core.DOWNLOADINFO[0].get('client_agent', 'manual')) input_hash = text_type(core.DOWNLOADINFO[0].get('input_hash', '')) input_id = text_type(core.DOWNLOADINFO[0].get('input_id', '')) logger.info('Found download info for {0}, ' 'setting variables now ...'.format(os.path.basename(dir_name))) else: logger.info('Unable to locate download info for {0}, ' 'continuing to try and process this release ...'.format (os.path.basename(dir_name))) client_agent = 'manual' input_hash = '' input_id = '' if client_agent.lower() not in core.TORRENT_CLIENTS: continue try: dir_name = dir_name.encode(core.SYS_ENCODING) except UnicodeError: pass input_name = os.path.basename(dir_name) try: input_name = input_name.encode(core.SYS_ENCODING) except UnicodeError: pass results = process_torrent(dir_name, input_name, subsection, input_hash or None, input_id or None, client_agent) if results[0] != 0: logger.error('A problem was reported when trying to perform a manual run for {0}:{1}.'.format (section, subsection)) result = results if result.status_code == 0: logger.info('The {0} script completed successfully.'.format(args[0])) else: logger.error('A problem was reported in the {0} script.'.format(args[0])) del core.MYAPP return result.status_code