- 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/subprocess_utils.py
r40895 r40897 2 2 3 3 # Plans are to flesh this out a bit more to make some smarter copying etc 4 from generic_utils import ValidationError 4 5 5 6 … … 10 11 def _args_check(args, function_name): 11 12 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}") 14 14 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}") 17 16 return 0 18 17 … … 20 19 def cp_wrapper(args: [str]): 21 20 if args is None: 22 r eturn 221 raise ValidationError(f"Error: no arguments provided to {cp_wrapper.__name__}") 23 22 command_and_args = ["cp"] + args 24 23 return simple_unix_wrapper(command_and_args) … … 27 26 def tar_wrapper(args: [str]): 28 27 if args is None: 29 r eturn 228 raise ValidationError(f"Error: no arguments provided to {tar_wrapper.__name__}") 30 29 command_and_args = ["tar"] + args 31 30 return simple_unix_wrapper(command_and_args) … … 34 33 def chmod_wrapper(args: [str]): 35 34 if args is None: 36 r eturn 235 raise ValidationError(f"Error: no arguments provided to {chmod_wrapper.__name__}") 37 36 command_and_args = ["chmod"] + args 38 37 return simple_unix_wrapper(command_and_args) … … 44 43 Only a single command should be called. 45 44 """ 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__) 49 46 50 47 try: 51 48 subprocess.check_call(command_and_args) 52 except subprocess.CalledProcessError ase:53 print("CalledProcessError in python subprocess: ")54 print(e)55 r eturn 249 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 56 53 return 0
Note:
See TracChangeset
for help on using the changeset viewer.
