Commit pyupgrade code changes

Signed-off-by: Pedro Algarvio <palgarvio@vmware.com>
This commit is contained in:
Pedro Algarvio 2022-07-20 13:58:57 +01:00 committed by Megan Wilhite
parent b35e7d46dc
commit c1ce23e71b
6 changed files with 22 additions and 40 deletions

View file

@ -1113,7 +1113,10 @@ repos:
args: [--py3-plus, --keep-mock]
exclude: >
(?x)^(
salt/client/ssh/ssh_py_shim.py|
salt/client/ssh/ssh_py_shim.py
|
salt/client/ssh/wrapper/pillar.py
|
salt/ext/.*\.py
)$

View file

@ -10,12 +10,6 @@ import salt.utils.decorators as decorators
import salt.utils.files
import salt.utils.stringutils
try:
from shlex import quote as _quote_args # pylint: disable=E0611
except ImportError:
from pipes import quote as _quote_args
log = logging.getLogger(__name__)
default_conf = "/etc/logadm.conf"
option_toggles = {
@ -300,7 +294,7 @@ def rotate(name, pattern=None, conf_file=default_conf, **kwargs):
_arg2opt(arg),
)
elif arg in option_flags.values():
command = "{} {} {}".format(command, _arg2opt(arg), _quote_args(str(val)))
command = "{} {} {}".format(command, _arg2opt(arg), shlex.quote(str(val)))
elif arg != "log_file":
log.warning("Unknown argument %s, don't know how to map this!", arg)
if "log_file" in kwargs:
@ -313,9 +307,9 @@ def rotate(name, pattern=None, conf_file=default_conf, **kwargs):
# % logadm -C2 -w mylog /my/really/long/log/file/name
# % logadm -C2 -w /my/really/long/log/file/name
if "entryname" not in kwargs:
command = "{} -w {}".format(command, _quote_args(kwargs["log_file"]))
command = "{} -w {}".format(command, shlex.quote(kwargs["log_file"]))
else:
command = "{} {}".format(command, _quote_args(kwargs["log_file"]))
command = "{} {}".format(command, shlex.quote(kwargs["log_file"]))
log.debug("logadm.rotate - command: %s", command)
result = __salt__["cmd.run_all"](command, python_shell=False)

View file

@ -4,6 +4,7 @@ Module for running vmadm command on SmartOS
import logging
import os
import shlex
import salt.utils.args
import salt.utils.files
@ -13,12 +14,6 @@ import salt.utils.platform
import salt.utils.stringutils
from salt.utils.odict import OrderedDict
try:
from shlex import quote as _quote_args # pylint: disable=E0611
except ImportError:
from pipes import quote as _quote_args
log = logging.getLogger(__name__)
# Function aliases
@ -688,7 +683,7 @@ def reprovision(vm, image, key="uuid"):
# vmadm reprovision <uuid> [-f <filename>]
cmd = "echo {image} | vmadm reprovision {uuid}".format(
uuid=salt.utils.stringutils.to_unicode(vm),
image=_quote_args(salt.utils.json.dumps({"image_uuid": image})),
image=shlex.quote(salt.utils.json.dumps({"image_uuid": image})),
)
res = __salt__["cmd.run_all"](cmd, python_shell=True)
retcode = res["retcode"]

View file

@ -9,6 +9,7 @@ available and installed roles/features. Can install and remove roles/features.
import logging
import shlex
import salt.utils.json
import salt.utils.platform
@ -16,12 +17,6 @@ import salt.utils.powershell
import salt.utils.versions
from salt.exceptions import CommandExecutionError
try:
from shlex import quote as _cmd_quote # pylint: disable=E0611
except ImportError:
from pipes import quote as _cmd_quote
log = logging.getLogger(__name__)
__virtualname__ = "win_servermanager"
@ -230,7 +225,7 @@ def install(feature, recurse=False, restart=False, source=None, exclude=None):
cmd = "{} -Name {} {} {} {} -WarningAction SilentlyContinue".format(
command,
_cmd_quote(feature),
shlex.quote(feature),
management_tools,
"-IncludeAllSubFeature" if recurse else "",
"" if source is None else "-Source {}".format(source),
@ -374,7 +369,7 @@ def remove(feature, remove_payload=False, restart=False):
cmd = "{} -Name {} {} {} {} -WarningAction SilentlyContinue".format(
command,
_cmd_quote(feature),
shlex.quote(feature),
management_tools,
_remove_payload,
"-Restart" if restart else "",

View file

@ -23,6 +23,7 @@ Module for managing Windows Users.
"""
import logging
import shlex
import time
from datetime import datetime
@ -32,12 +33,6 @@ import salt.utils.platform
import salt.utils.winapi
from salt.exceptions import CommandExecutionError
try:
from shlex import quote as _cmd_quote # pylint: disable=E0611
except Exception: # pylint: disable=broad-except
from pipes import quote as _cmd_quote
log = logging.getLogger(__name__)
try:
@ -463,8 +458,8 @@ def addgroup(name, group):
salt '*' user.addgroup jsnuffy 'Power Users'
"""
name = _cmd_quote(name)
group = _cmd_quote(group).lstrip("'").rstrip("'")
name = shlex.quote(name)
group = shlex.quote(group).lstrip("'").rstrip("'")
user = info(name)
if not user:
@ -496,8 +491,8 @@ def removegroup(name, group):
salt '*' user.removegroup jsnuffy 'Power Users'
"""
name = _cmd_quote(name)
group = _cmd_quote(group).lstrip("'").rstrip("'")
name = shlex.quote(name)
group = shlex.quote(group).lstrip("'").rstrip("'")
user = info(name)
@ -632,11 +627,11 @@ def chgroups(name, groups, append=True):
if ugrps == set(groups):
return True
name = _cmd_quote(name)
name = shlex.quote(name)
if not append:
for group in ugrps:
group = _cmd_quote(group).lstrip("'").rstrip("'")
group = shlex.quote(group).lstrip("'").rstrip("'")
if group not in groups:
cmd = 'net localgroup "{}" {} /delete'.format(group, name)
__salt__["cmd.run_all"](cmd, python_shell=True)
@ -644,7 +639,7 @@ def chgroups(name, groups, append=True):
for group in groups:
if group in ugrps:
continue
group = _cmd_quote(group).lstrip("'").rstrip("'")
group = shlex.quote(group).lstrip("'").rstrip("'")
cmd = 'net localgroup "{}" {} /add'.format(group, name)
out = __salt__["cmd.run_all"](cmd, python_shell=True)
if out["retcode"] != 0:

View file

@ -1,4 +1,4 @@
import collections
import collections.abc
import textwrap
import pytest
@ -23,7 +23,7 @@ def assert_unicode(value):
for k, v in value.items():
assert_unicode(k)
assert_unicode(v)
elif isinstance(value, collections.Iterable):
elif isinstance(value, collections.abc.Iterable):
for item in value:
assert_unicode(item)