run pre commit

This commit is contained in:
Joe Eacott 2021-02-03 16:48:04 -07:00 committed by Megan Wilhite
parent c898cb44d6
commit c2552a1b05

View file

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
Execution of arbitrary commands
===============================
@ -232,20 +231,16 @@ To use it, one may pass it like this. Example:
"""
# Import python libs
from __future__ import absolute_import, print_function, unicode_literals
import copy
import logging
import os
# Import salt libs
import salt.utils.args
import salt.utils.functools
import salt.utils.json
import salt.utils.platform
from salt.exceptions import CommandExecutionError, SaltRenderError
from salt.ext import six
log = logging.getLogger(__name__)
@ -318,11 +313,11 @@ def _failout(state, msg):
def _is_true(val):
if val and six.text_type(val).lower() in ("true", "yes", "1"):
if val and str(val).lower() in ("true", "yes", "1"):
return True
elif six.text_type(val).lower() in ("false", "no", "0"):
elif str(val).lower() in ("false", "no", "0"):
return False
raise ValueError("Failed parsing boolean value: {0}".format(val))
raise ValueError("Failed parsing boolean value: {}".format(val))
def wait(
@ -801,11 +796,11 @@ def run(
if __opts__["test"] and not test_name:
ret["result"] = None
ret["comment"] = 'Command "{0}" would have been executed'.format(name)
ret["comment"] = 'Command "{}" would have been executed'.format(name)
return _reinterpreted_state(ret) if stateful else ret
if cwd and not os.path.isdir(cwd):
ret["comment"] = ('Desired working directory "{0}" ' "is not available").format(
ret["comment"] = ('Desired working directory "{}" ' "is not available").format(
cwd
)
return ret
@ -817,12 +812,12 @@ def run(
cmd=name, timeout=timeout, python_shell=True, **cmd_kwargs
)
except Exception as err: # pylint: disable=broad-except
ret["comment"] = six.text_type(err)
ret["comment"] = str(err)
return ret
ret["changes"] = cmd_all
ret["result"] = not bool(cmd_all["retcode"])
ret["comment"] = 'Command "{0}" run'.format(name)
ret["comment"] = 'Command "{}" run'.format(name)
# Ignore timeout errors if asked (for nohups) and treat cmd as a success
if ignore_timeout:
@ -1096,11 +1091,11 @@ def script(
if __opts__["test"] and not test_name:
ret["result"] = None
ret["comment"] = "Command '{0}' would have been " "executed".format(name)
ret["comment"] = "Command '{}' would have been " "executed".format(name)
return _reinterpreted_state(ret) if stateful else ret
if cwd and not os.path.isdir(cwd):
ret["comment"] = ('Desired working directory "{0}" ' "is not available").format(
ret["comment"] = ('Desired working directory "{}" ' "is not available").format(
cwd
)
return ret
@ -1108,8 +1103,8 @@ def script(
# Wow, we passed the test, run this sucker!
try:
cmd_all = __salt__["cmd.script"](source, python_shell=True, **cmd_kwargs)
except (CommandExecutionError, SaltRenderError, IOError) as err:
ret["comment"] = six.text_type(err)
except (CommandExecutionError, SaltRenderError, OSError) as err:
ret["comment"] = str(err)
return ret
ret["changes"] = cmd_all
@ -1118,11 +1113,11 @@ def script(
else:
ret["result"] = not bool(cmd_all["retcode"])
if ret.get("changes", {}).get("cache_error"):
ret["comment"] = "Unable to cache script {0} from saltenv " "'{1}'".format(
ret["comment"] = "Unable to cache script {} from saltenv " "'{}'".format(
source, __env__
)
else:
ret["comment"] = "Command '{0}' run".format(name)
ret["comment"] = "Command '{}' run".format(name)
if stateful:
ret = _reinterpreted_state(ret)
if __opts__["test"] and cmd_all["retcode"] == 0 and ret["changes"]:
@ -1188,7 +1183,7 @@ def call(
# result must be JSON serializable else we get an error
ret["changes"] = {"retval": result}
ret["result"] = True if result is None else bool(result)
if isinstance(result, six.string_types):
if isinstance(result, str):
ret["comment"] = result
return ret