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/subprocess_utils.py

    r40895 r40897  
    22
    33# Plans are to flesh this out a bit more to make some smarter copying etc
     4from generic_utils import ValidationError
    45
    56
     
    1011def _args_check(args, function_name):
    1112    if args is None:
    12         print("Error: no arguments provided in ", function_name)
    13         return 2
     13        raise ValidationError(f"Error: no arguments provided in {function_name}")
    1414    if type(args) != list or len(args) == 0:
    15         print("Error: at least 1 arg must be given for ", function_name)
    16         return 2
     15        raise ValidationError(f"Error: no arguments provided in {function_name}")
    1716    return 0
    1817
     
    2019def cp_wrapper(args: [str]):
    2120    if args is None:
    22         return 2
     21        raise ValidationError(f"Error: no arguments provided to {cp_wrapper.__name__}")
    2322    command_and_args = ["cp"] + args
    2423    return simple_unix_wrapper(command_and_args)
     
    2726def tar_wrapper(args: [str]):
    2827    if args is None:
    29         return 2
     28        raise ValidationError(f"Error: no arguments provided to {tar_wrapper.__name__}")
    3029    command_and_args = ["tar"] + args
    3130    return simple_unix_wrapper(command_and_args)
     
    3433def chmod_wrapper(args: [str]):
    3534    if args is None:
    36         return 2
     35        raise ValidationError(f"Error: no arguments provided to {chmod_wrapper.__name__}")
    3736    command_and_args = ["chmod"] + args
    3837    return simple_unix_wrapper(command_and_args)
     
    4443Only a single command should be called.
    4544    """
    46     arg_check = _args_check(command_and_args, simple_unix_wrapper.__name__)
    47     if arg_check != 0:
    48         return arg_check
     45    _args_check(command_and_args, simple_unix_wrapper.__name__)
    4946
    5047    try:
    5148        subprocess.check_call(command_and_args)
    52     except subprocess.CalledProcessError as e:
    53         print("CalledProcessError in python subprocess: ")
    54         print(e)
    55         return 2
     49    except (subprocess.CalledProcessError) as cpe:
     50        raise SubprocessError(f"{type(cpe)} in python simple_unix_wrapper") from cpe
     51    except (ValidationError) as ve:
     52        raise ValidationError(f"{type(ve)} in python simple_unix_wrapper") from ve
    5653    return 0
Note: See TracChangeset for help on using the changeset viewer.