Skip to content

Commit

Permalink
Log write & file renaming successes separately
Browse files Browse the repository at this point in the history
  • Loading branch information
shailshouryya committed Dec 31, 2020
1 parent 2e20d8a commit 8a3e4f2
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 16 deletions.
9 changes: 5 additions & 4 deletions python/dev/file/create_file.py
Expand Up @@ -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

Expand Down
9 changes: 5 additions & 4 deletions python/dev/file/update_file.py
Expand Up @@ -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

Expand Down
9 changes: 5 additions & 4 deletions python/yt_videos_list/file/create_file.py
Expand Up @@ -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):
Expand Down
9 changes: 5 additions & 4 deletions python/yt_videos_list/file/update_file.py
Expand Up @@ -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):
Expand Down

0 comments on commit 8a3e4f2

Please sign in to comment.