Improved logging and reduced exceptions.
	
		
			
	
		
	
	
		
	
		
			All checks were successful
		
		
	
	
		
			
				
	
				ydeng/renamebycsv/pipeline/head This commit looks good
				
			
		
		
	
	
				
					
				
			
		
			All checks were successful
		
		
	
	ydeng/renamebycsv/pipeline/head This commit looks good
				
			Also bumped version.
This commit is contained in:
		| @@ -8,15 +8,16 @@ from renamebycsv.renamer import find_all_candidates, rename_by_csv | |||||||
|  |  | ||||||
| def run(args): | def run(args): | ||||||
|     candidates = find_all_candidates(args.input_dir, args.pattern, args.recursive) |     candidates = find_all_candidates(args.input_dir, args.pattern, args.recursive) | ||||||
|     rename_by_csv( |     if len(candidates): | ||||||
|         args.csv, |         rename_by_csv( | ||||||
|         candidates, |             args.csv, | ||||||
|         args.current, |             candidates, | ||||||
|         args.become, |             args.current, | ||||||
|         args.dry, |             args.become, | ||||||
|         args.extension, |             args.dry, | ||||||
|         args.keep_extension, |             args.extension, | ||||||
|     ) |             args.keep_extension, | ||||||
|  |         ) | ||||||
|  |  | ||||||
|  |  | ||||||
| def main(): | def main(): | ||||||
|   | |||||||
| @@ -32,6 +32,8 @@ def find_all_candidates(input_dir: str, regex: str, recursive: bool): | |||||||
|             regex, |             regex, | ||||||
|             input_dir, |             input_dir, | ||||||
|         ) |         ) | ||||||
|  |     else: | ||||||
|  |         logging.info("Collected %d files to rename.", len(results)) | ||||||
|     return results |     return results | ||||||
|  |  | ||||||
|  |  | ||||||
| @@ -51,6 +53,10 @@ def rename_by_csv( | |||||||
|         become_col_ind = None |         become_col_ind = None | ||||||
|         for row in reader: |         for row in reader: | ||||||
|             if current_col_ind is None and become_col_ind is None: |             if current_col_ind is None and become_col_ind is None: | ||||||
|  |                 if current not in row: | ||||||
|  |                     logging.error("\"%s\" not in header %s.", current, list(row)) | ||||||
|  |                 if become not in row: | ||||||
|  |                     logging.error("\"%s\" not in header %s.", become, list(row)) | ||||||
|                 current_col_ind = row.index(current) |                 current_col_ind = row.index(current) | ||||||
|                 become_col_ind = row.index(become) |                 become_col_ind = row.index(become) | ||||||
|                 continue |                 continue | ||||||
| @@ -80,7 +86,7 @@ def rename_by_csv( | |||||||
|         logging.info(f'Will rename "{original}" to "{os.path.basename(objective)}"') |         logging.info(f'Will rename "{original}" to "{os.path.basename(objective)}"') | ||||||
|         if os.path.exists(objective): |         if os.path.exists(objective): | ||||||
|             logging.error( |             logging.error( | ||||||
|                 f'Path at "{objective}" exists, not continuing. ' |                 f'Path at "{objective}" already exists, not continuing. ' | ||||||
|                 "Use -f to overwrite instead of stopping." |                 "Use -f to overwrite instead of stopping." | ||||||
|             ) |             ) | ||||||
|             exit(1) |             exit(1) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user