2323import os
2424import pathlib
2525
26+ # Configure logging so entries are sent to STDOUT.
27+ logging .basicConfig (stream = sys .stdout )
28+
29+ # Create a logger for this module.
30+ log = logging .getLogger ("main" )
31+
2632
2733def get_file_paths_within_folder (path_to_folder ):
2834 """Returns a list containing the path of each file within the specified folder and all of its descendant folders."""
@@ -54,8 +60,8 @@ def get_file_paths_from_csv_file(path_to_csv_file):
5460 else :
5561 folder_col_idx = [idx for (idx , s ) in enumerate (header ) if s == "Folder" ][0 ]
5662 filename_col_idx = [idx for (idx , s ) in enumerate (header ) if s == "Filename" ][0 ]
57- logging .debug (f"Index of CSV column containing folder : { folder_col_idx } " )
58- logging .debug (f"Index of CSV column containing filename : { filename_col_idx } " )
63+ log .debug (f"Index of CSV column containing folder : { folder_col_idx } " )
64+ log .debug (f"Index of CSV column containing filename : { filename_col_idx } " )
5965
6066 # Build a file path from each non-empty row (reminder: In Python, empty strings are False-y).
6167 for row in reader :
@@ -72,29 +78,30 @@ def get_file_paths_from_csv_file(path_to_csv_file):
7278def main (path_to_folder , path_to_csv_file , path_to_output_file = None , log_level = logging .NOTSET ):
7379 """Entrypoint to the script."""
7480
75- # Configure logging so entries are sent to STDOUT and so the threshold level is the one specified.
81+ # Configure the logger so the threshold logging level is the one specified.
7682 level = logging .getLevelName (log_level ) if type (log_level ) is str else log_level
77- logging .basicConfig (stream = sys .stdout , level = level )
83+ log .setLevel (level )
84+ log .debug (f"Log level : { log_level } ({ level } )" )
7885
79- logging .info (f'Folder : { path_to_folder } ' )
80- logging .info (f'dupeGuru CSV : { path_to_csv_file } ' )
81- logging .info (f'Output file : { path_to_output_file } ' )
86+ log .info (f'Folder : { path_to_folder } ' )
87+ log .info (f'dupeGuru CSV : { path_to_csv_file } ' )
88+ log .info (f'Output file : { path_to_output_file } ' )
8289
8390 # Get a list of file paths from each source.
8491 file_paths_from_folder = get_file_paths_within_folder (path_to_folder )
8592 file_paths_from_csv_file = get_file_paths_from_csv_file (path_to_csv_file )
86- logging .debug (f"Number of file paths from folder : { len (file_paths_from_folder )} " )
87- logging .debug (f"Number of file paths from CSV file : { len (file_paths_from_csv_file )} " )
93+ log .debug (f"Number of file paths from folder : { len (file_paths_from_folder )} " )
94+ log .debug (f"Number of file paths from CSV file : { len (file_paths_from_csv_file )} " )
8895
8996 # Eliminate duplicate file paths from each list.
9097 distinct_file_paths_from_folder = set (file_paths_from_folder )
9198 distinct_file_paths_from_csv_file = set (file_paths_from_csv_file )
92- logging .debug (f"Number of distinct file paths from folder : { len (distinct_file_paths_from_folder )} " )
93- logging .debug (f"Number of distinct file paths from CSV file : { len (distinct_file_paths_from_csv_file )} " )
99+ log .debug (f"Number of distinct file paths from folder : { len (distinct_file_paths_from_folder )} " )
100+ log .debug (f"Number of distinct file paths from CSV file : { len (distinct_file_paths_from_csv_file )} " )
94101
95102 # Determine which file paths from the folder are not in the set of file paths from the CSV file.
96103 differences = distinct_file_paths_from_folder .difference (distinct_file_paths_from_csv_file )
97- logging .info (f"Number of differences : { len (differences )} " )
104+ log .info (f"Number of differences : { len (differences )} " )
98105
99106 sorted_differences = sorted (list (differences ))
100107
@@ -117,8 +124,6 @@ def main(path_to_folder, path_to_csv_file, path_to_output_file=None, log_level=l
117124 else :
118125 print ('\n ' .join (sorted_differences ))
119126
120- print ("\n Done.\n " )
121-
122127
123128if __name__ == '__main__' :
124129 parser = argparse .ArgumentParser (description = 'Compares a folder to a CSV file exported from dupeGuru. Displays the '
0 commit comments