Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def process_file(handler, torrent_name, file_path):
"""
Processes a single file with the given handler.
:param handler: The handler to use.
:param torrent_name: The relevant torrent name.
:param file_path: The file path to process.
"""
filename = os.path.basename(file_path)
category_path = get_categorized_path(os.path.join(torrent_name, filename))
if category_path is not None:
destination_dir = os.path.join(category_path, torrent_name)
# Creates target directory (of category path).
_create_destination_path(destination_dir)
destination_path = os.path.join(destination_dir, filename)
try:
# Move\Copy all relevant files to their location (keep original files for uploading).
handler(file_path, destination_path)
logger.info('{} {} to {}'.format(handler.__name__, file_path, destination_path))
if os.name != 'nt':
subprocess.check_output(['chmod', config.EXTRACTION_FILES_MASK, '-R', destination_dir])
# Get subtitles.
subtitles_paths = None
if config.SHOULD_FIND_SUBTITLES:
subtitles_paths = find_file_subtitles(destination_path)
# Upload files to Amazon.