IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 3, 2019, 11:51:21 AM (7 years ago)
Author:
fairlamb
Message:

Better errors, chmod wrapper, fixed config loading and tests

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/ipp-132_automate_jira_conf_backups/utils/python/generic_utils.py

    r40895 r40897  
    1616
    1717    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")
    2019    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")
    2321    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}")
    2623    if not path.exists(destination_path) or not path.isdir(destination_path):
    2724        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}")
    2926
    3027    try:
    3128        if verbose:
    32             print("Copying: {0} to {1}".format(source_file, destination_path))
     29            print(f"Copying: {source_file} to {destination_path}")
    3330        if path.isdir(source_file):
    3431            copy_tree(source_file, destination_path)
     
    3633            shutil.copy2(source_file, destination_path)
    3734    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
    4137    return 0
    4238
     
    4844
    4945    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")
    5247    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")
    5549
    5650    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")
    5952    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")
    6254
    6355    for dpath in destination_paths:
    6456        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)
    6659            continue
    6760        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): ", )
    6963            continue
    7064
Note: See TracChangeset for help on using the changeset viewer.