- Timestamp:
- Oct 3, 2019, 11:51:21 AM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ipp-132_automate_jira_conf_backups/utils/python/generic_utils.py
r40895 r40897 16 16 17 17 if source_file is None or destination_path is None: 18 print("Error: source for copy cannot be None type") 19 raise ValidationError 18 raise ValidationError("Error: source for copy cannot be None type") 20 19 if destination_path is None: 21 print("Error: copy destination cannot be None type") 22 raise ValidationError 20 raise ValidationError("Error: copy destination cannot be None type") 23 21 if not path.exists(source_file): 24 print("Error: Copy Failure: source does not exist: ", source_file) 25 raise ValidationError 22 raise ValidationError(f"Error: Copy Failure: source does not exist: {source_file}") 26 23 if not path.exists(destination_path) or not path.isdir(destination_path): 27 24 print("Error: Copy Failure: destination path does not exist: ", destination_path) 28 raise ValidationError 25 raise ValidationError(f"Error: Copy Failure: destination path does not exist: {destination_path}") 29 26 30 27 try: 31 28 if verbose: 32 print( "Copying: {0} to {1}".format(source_file, destination_path))29 print(f"Copying: {source_file} to {destination_path}") 33 30 if path.isdir(source_file): 34 31 copy_tree(source_file, destination_path) … … 36 33 shutil.copy2(source_file, destination_path) 37 34 except IOError as e: 38 print("Error: copy failure.\n copying: {0}\n to: {1}".format(e.filename, e.filename2)) 39 print(e) 40 raise IOError 35 msg = f"Error: copy failure.\n copying: {source_file}\n to: {destination_path}" 36 raise IOError(msg) from e 41 37 return 0 42 38 … … 48 44 49 45 if source_paths is None: 50 print("Error: source for copy cannot be None type") 51 raise ValidationError 46 raise ValidationError("Error: source for copy cannot be None type") 52 47 if destination_paths is None: 53 print("Error: copy destination cannot be None type") 54 raise ValidationError 48 raise ValidationError("Error: copy destination cannot be None type") 55 49 56 50 if type(source_paths) is not list or len(source_paths) == 0: 57 print("Error: sources must be given as a list with at least one entry") 58 raise ValidationError 51 raise ValidationError("Error: sources must be given as a list with at least one entry") 59 52 if type(destination_paths) is not list or len(destination_paths) == 0: 60 print("Error: destinations must be given as a list with at least one entry") 61 raise ValidationError 53 raise ValidationError("Error: destinations must be given as a list with at least one entry") 62 54 63 55 for dpath in destination_paths: 64 56 if not path.exists(dpath): 65 print("Copy Warning: target path does not exist (skipping): ", dpath) 57 if verbose: 58 print("Copy Warning: target path does not exist (skipping): ", dpath) 66 59 continue 67 60 if not path.isdir(dpath): 68 print("Copy Warning: target path is not a directory (skipping): ", ) 61 if verbose: 62 print("Copy Warning: target path is not a directory (skipping): ", ) 69 63 continue 70 64
Note:
See TracChangeset
for help on using the changeset viewer.
