From 8a3e4f290f35fb04d91e1b93da0c10571d3c4694 Mon Sep 17 00:00:00 2001 From: Shail Shouryya Date: Mon, 28 Dec 2020 23:40:19 -0800 Subject: [PATCH] Log write & file renaming successes separately --- python/dev/file/create_file.py | 9 +++++---- python/dev/file/update_file.py | 9 +++++---- python/yt_videos_list/file/create_file.py | 9 +++++---- python/yt_videos_list/file/update_file.py | 9 +++++---- 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/python/dev/file/create_file.py b/python/dev/file/create_file.py index 35d34cfb..a41a1d8d 100644 --- a/python/dev/file/create_file.py +++ b/python/dev/file/create_file.py @@ -58,11 +58,12 @@ def wrapper_timer(*args, **kwargs): total_time = end_time - start_time temp_file = f'temp_{file_name}_{timestamp}.{extension}' # determine temp_{file_name} for wrapper_timer() scope final_file = f'{file_name}.{extension}' - log(f'Finished writing to'.ljust(38) + f'{temp_file}', logging_output_location) - log(f'{videos_written} videos written to'.ljust(38) + f'{temp_file}', logging_output_location) - log(f'Closing'.ljust(38) + f'{temp_file}', logging_output_location) + log(f'Finished writing to'.ljust(39) + f'{temp_file}', logging_output_location) + log(f'{videos_written} videos written to'.ljust(39) + f'{temp_file}', logging_output_location) + log(f'Closing'.ljust(39) + f'{temp_file}', logging_output_location) + log(f'Successfully completed write, renaming {temp_file} to {final_file}', logging_output_location) os.replace(temp_file, final_file) # rename temp_{file_name} to {file_name}.{extension} here AFTER everything else finishes to ensure atomicity - log(f'Successfully completed write, renamed {temp_file} to {final_file}', logging_output_location) + log(f'Successfully renamed'.ljust(39) + f'{temp_file} to {final_file}', logging_output_location) log(f'It took {total_time} seconds to write all {videos_written} videos to {final_file}{NEWLINE}', logging_output_location) return wrapper_timer diff --git a/python/dev/file/update_file.py b/python/dev/file/update_file.py index a47d7ed1..76931cf0 100644 --- a/python/dev/file/update_file.py +++ b/python/dev/file/update_file.py @@ -56,12 +56,13 @@ def wrapper_timer(*args, **kwargs): total_time = end_time - start_time temp_file = f'temp_{file_name}_{timestamp}.{extension}' # determine temp_{file_name} for wrapper_timer() scope final_file = f'{file_name}.{extension}' - log(f'Finished writing to'.ljust(38) + f'{temp_file}', logging_output_location) - log(f'{new_videos_written} ***NEW*** videos written to'.ljust(38) + f'{temp_file}', logging_output_location) - log(f'Closing'.ljust(38) + f'{temp_file}', logging_output_location) + log(f'Finished writing to'.ljust(39) + f'{temp_file}', logging_output_location) + log(f'{new_videos_written} ***NEW*** videos written to'.ljust(39) + f'{temp_file}', logging_output_location) + log(f'Closing'.ljust(39) + f'{temp_file}', logging_output_location) + log(f'Successfully completed write, renaming {temp_file} to {final_file}', logging_output_location) if reverse_chronological: os.replace(temp_file, final_file) # rename temp_{file_name} to {file_name}.{extension} since the info from the original file was appended to the end of the temp file else: os.remove(temp_file) # remove temp_{file_name} since all new information from the temp file was appended to the end of the original file - log(f'Successfully completed write, renamed {temp_file} to {final_file}', logging_output_location) + log(f'Successfully renamed'.ljust(39) + f'{temp_file} to {final_file}', logging_output_location) log(f'It took {total_time} seconds to write the {new_videos_written} ***NEW*** videos to the pre-existing {final_file} {NEWLINE}', logging_output_location) return wrapper_timer diff --git a/python/yt_videos_list/file/create_file.py b/python/yt_videos_list/file/create_file.py index 1bcace4a..7fc2fc31 100644 --- a/python/yt_videos_list/file/create_file.py +++ b/python/yt_videos_list/file/create_file.py @@ -47,11 +47,12 @@ def wrapper_timer(*args, **kwargs): total_time = end_time - start_time temp_file = f'temp_{file_name}_{timestamp}.{extension}' final_file = f'{file_name}.{extension}' - log(f'Finished writing to'.ljust(38) + f'{temp_file}', logging_output_location) - log(f'{videos_written} videos written to'.ljust(38) + f'{temp_file}', logging_output_location) - log(f'Closing'.ljust(38) + f'{temp_file}', logging_output_location) + log(f'Finished writing to'.ljust(39) + f'{temp_file}', logging_output_location) + log(f'{videos_written} videos written to'.ljust(39) + f'{temp_file}', logging_output_location) + log(f'Closing'.ljust(39) + f'{temp_file}', logging_output_location) + log(f'Successfully completed write, renaming {temp_file} to {final_file}', logging_output_location) os.replace(temp_file, final_file) - log(f'Successfully completed write, renamed {temp_file} to {final_file}', logging_output_location) + log(f'Successfully renamed'.ljust(39) + f'{temp_file} to {final_file}', logging_output_location) log(f'It took {total_time} seconds to write all {videos_written} videos to {final_file}{NEWLINE}', logging_output_location) return wrapper_timer def prepare_output(list_of_videos, reverse_chronological): diff --git a/python/yt_videos_list/file/update_file.py b/python/yt_videos_list/file/update_file.py index f96a6107..bf7a7058 100644 --- a/python/yt_videos_list/file/update_file.py +++ b/python/yt_videos_list/file/update_file.py @@ -47,12 +47,13 @@ def wrapper_timer(*args, **kwargs): total_time = end_time - start_time temp_file = f'temp_{file_name}_{timestamp}.{extension}' final_file = f'{file_name}.{extension}' - log(f'Finished writing to'.ljust(38) + f'{temp_file}', logging_output_location) - log(f'{new_videos_written} ***NEW*** videos written to'.ljust(38) + f'{temp_file}', logging_output_location) - log(f'Closing'.ljust(38) + f'{temp_file}', logging_output_location) + log(f'Finished writing to'.ljust(39) + f'{temp_file}', logging_output_location) + log(f'{new_videos_written} ***NEW*** videos written to'.ljust(39) + f'{temp_file}', logging_output_location) + log(f'Closing'.ljust(39) + f'{temp_file}', logging_output_location) + log(f'Successfully completed write, renaming {temp_file} to {final_file}', logging_output_location) if reverse_chronological: os.replace(temp_file, final_file) else: os.remove(temp_file) - log(f'Successfully completed write, renamed {temp_file} to {final_file}', logging_output_location) + log(f'Successfully renamed'.ljust(39) + f'{temp_file} to {final_file}', logging_output_location) log(f'It took {total_time} seconds to write the {new_videos_written} ***NEW*** videos to the pre-existing {final_file} {NEWLINE}', logging_output_location) return wrapper_timer def find_number_of_new_videos(list_of_videos, videos_set):