mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Commit pyupgrade code changes
Signed-off-by: Pedro Algarvio <palgarvio@vmware.com>
This commit is contained in:
parent
b35e7d46dc
commit
c1ce23e71b
6 changed files with 22 additions and 40 deletions
|
@ -1113,7 +1113,10 @@ repos:
|
||||||
args: [--py3-plus, --keep-mock]
|
args: [--py3-plus, --keep-mock]
|
||||||
exclude: >
|
exclude: >
|
||||||
(?x)^(
|
(?x)^(
|
||||||
salt/client/ssh/ssh_py_shim.py|
|
salt/client/ssh/ssh_py_shim.py
|
||||||
|
|
|
||||||
|
salt/client/ssh/wrapper/pillar.py
|
||||||
|
|
|
||||||
salt/ext/.*\.py
|
salt/ext/.*\.py
|
||||||
)$
|
)$
|
||||||
|
|
||||||
|
|
|
@ -10,12 +10,6 @@ import salt.utils.decorators as decorators
|
||||||
import salt.utils.files
|
import salt.utils.files
|
||||||
import salt.utils.stringutils
|
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__)
|
log = logging.getLogger(__name__)
|
||||||
default_conf = "/etc/logadm.conf"
|
default_conf = "/etc/logadm.conf"
|
||||||
option_toggles = {
|
option_toggles = {
|
||||||
|
@ -300,7 +294,7 @@ def rotate(name, pattern=None, conf_file=default_conf, **kwargs):
|
||||||
_arg2opt(arg),
|
_arg2opt(arg),
|
||||||
)
|
)
|
||||||
elif arg in option_flags.values():
|
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":
|
elif arg != "log_file":
|
||||||
log.warning("Unknown argument %s, don't know how to map this!", arg)
|
log.warning("Unknown argument %s, don't know how to map this!", arg)
|
||||||
if "log_file" in kwargs:
|
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 mylog /my/really/long/log/file/name
|
||||||
# % logadm -C2 -w /my/really/long/log/file/name
|
# % logadm -C2 -w /my/really/long/log/file/name
|
||||||
if "entryname" not in kwargs:
|
if "entryname" not in kwargs:
|
||||||
command = "{} -w {}".format(command, _quote_args(kwargs["log_file"]))
|
command = "{} -w {}".format(command, shlex.quote(kwargs["log_file"]))
|
||||||
else:
|
else:
|
||||||
command = "{} {}".format(command, _quote_args(kwargs["log_file"]))
|
command = "{} {}".format(command, shlex.quote(kwargs["log_file"]))
|
||||||
|
|
||||||
log.debug("logadm.rotate - command: %s", command)
|
log.debug("logadm.rotate - command: %s", command)
|
||||||
result = __salt__["cmd.run_all"](command, python_shell=False)
|
result = __salt__["cmd.run_all"](command, python_shell=False)
|
||||||
|
|
|
@ -4,6 +4,7 @@ Module for running vmadm command on SmartOS
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
import shlex
|
||||||
|
|
||||||
import salt.utils.args
|
import salt.utils.args
|
||||||
import salt.utils.files
|
import salt.utils.files
|
||||||
|
@ -13,12 +14,6 @@ import salt.utils.platform
|
||||||
import salt.utils.stringutils
|
import salt.utils.stringutils
|
||||||
from salt.utils.odict import OrderedDict
|
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__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
# Function aliases
|
# Function aliases
|
||||||
|
@ -688,7 +683,7 @@ def reprovision(vm, image, key="uuid"):
|
||||||
# vmadm reprovision <uuid> [-f <filename>]
|
# vmadm reprovision <uuid> [-f <filename>]
|
||||||
cmd = "echo {image} | vmadm reprovision {uuid}".format(
|
cmd = "echo {image} | vmadm reprovision {uuid}".format(
|
||||||
uuid=salt.utils.stringutils.to_unicode(vm),
|
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)
|
res = __salt__["cmd.run_all"](cmd, python_shell=True)
|
||||||
retcode = res["retcode"]
|
retcode = res["retcode"]
|
||||||
|
|
|
@ -9,6 +9,7 @@ available and installed roles/features. Can install and remove roles/features.
|
||||||
|
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
import shlex
|
||||||
|
|
||||||
import salt.utils.json
|
import salt.utils.json
|
||||||
import salt.utils.platform
|
import salt.utils.platform
|
||||||
|
@ -16,12 +17,6 @@ import salt.utils.powershell
|
||||||
import salt.utils.versions
|
import salt.utils.versions
|
||||||
from salt.exceptions import CommandExecutionError
|
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__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
__virtualname__ = "win_servermanager"
|
__virtualname__ = "win_servermanager"
|
||||||
|
@ -230,7 +225,7 @@ def install(feature, recurse=False, restart=False, source=None, exclude=None):
|
||||||
|
|
||||||
cmd = "{} -Name {} {} {} {} -WarningAction SilentlyContinue".format(
|
cmd = "{} -Name {} {} {} {} -WarningAction SilentlyContinue".format(
|
||||||
command,
|
command,
|
||||||
_cmd_quote(feature),
|
shlex.quote(feature),
|
||||||
management_tools,
|
management_tools,
|
||||||
"-IncludeAllSubFeature" if recurse else "",
|
"-IncludeAllSubFeature" if recurse else "",
|
||||||
"" if source is None else "-Source {}".format(source),
|
"" 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(
|
cmd = "{} -Name {} {} {} {} -WarningAction SilentlyContinue".format(
|
||||||
command,
|
command,
|
||||||
_cmd_quote(feature),
|
shlex.quote(feature),
|
||||||
management_tools,
|
management_tools,
|
||||||
_remove_payload,
|
_remove_payload,
|
||||||
"-Restart" if restart else "",
|
"-Restart" if restart else "",
|
||||||
|
|
|
@ -23,6 +23,7 @@ Module for managing Windows Users.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
import shlex
|
||||||
import time
|
import time
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
|
@ -32,12 +33,6 @@ import salt.utils.platform
|
||||||
import salt.utils.winapi
|
import salt.utils.winapi
|
||||||
from salt.exceptions import CommandExecutionError
|
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__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -463,8 +458,8 @@ def addgroup(name, group):
|
||||||
|
|
||||||
salt '*' user.addgroup jsnuffy 'Power Users'
|
salt '*' user.addgroup jsnuffy 'Power Users'
|
||||||
"""
|
"""
|
||||||
name = _cmd_quote(name)
|
name = shlex.quote(name)
|
||||||
group = _cmd_quote(group).lstrip("'").rstrip("'")
|
group = shlex.quote(group).lstrip("'").rstrip("'")
|
||||||
|
|
||||||
user = info(name)
|
user = info(name)
|
||||||
if not user:
|
if not user:
|
||||||
|
@ -496,8 +491,8 @@ def removegroup(name, group):
|
||||||
|
|
||||||
salt '*' user.removegroup jsnuffy 'Power Users'
|
salt '*' user.removegroup jsnuffy 'Power Users'
|
||||||
"""
|
"""
|
||||||
name = _cmd_quote(name)
|
name = shlex.quote(name)
|
||||||
group = _cmd_quote(group).lstrip("'").rstrip("'")
|
group = shlex.quote(group).lstrip("'").rstrip("'")
|
||||||
|
|
||||||
user = info(name)
|
user = info(name)
|
||||||
|
|
||||||
|
@ -632,11 +627,11 @@ def chgroups(name, groups, append=True):
|
||||||
if ugrps == set(groups):
|
if ugrps == set(groups):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
name = _cmd_quote(name)
|
name = shlex.quote(name)
|
||||||
|
|
||||||
if not append:
|
if not append:
|
||||||
for group in ugrps:
|
for group in ugrps:
|
||||||
group = _cmd_quote(group).lstrip("'").rstrip("'")
|
group = shlex.quote(group).lstrip("'").rstrip("'")
|
||||||
if group not in groups:
|
if group not in groups:
|
||||||
cmd = 'net localgroup "{}" {} /delete'.format(group, name)
|
cmd = 'net localgroup "{}" {} /delete'.format(group, name)
|
||||||
__salt__["cmd.run_all"](cmd, python_shell=True)
|
__salt__["cmd.run_all"](cmd, python_shell=True)
|
||||||
|
@ -644,7 +639,7 @@ def chgroups(name, groups, append=True):
|
||||||
for group in groups:
|
for group in groups:
|
||||||
if group in ugrps:
|
if group in ugrps:
|
||||||
continue
|
continue
|
||||||
group = _cmd_quote(group).lstrip("'").rstrip("'")
|
group = shlex.quote(group).lstrip("'").rstrip("'")
|
||||||
cmd = 'net localgroup "{}" {} /add'.format(group, name)
|
cmd = 'net localgroup "{}" {} /add'.format(group, name)
|
||||||
out = __salt__["cmd.run_all"](cmd, python_shell=True)
|
out = __salt__["cmd.run_all"](cmd, python_shell=True)
|
||||||
if out["retcode"] != 0:
|
if out["retcode"] != 0:
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import collections
|
import collections.abc
|
||||||
import textwrap
|
import textwrap
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
@ -23,7 +23,7 @@ def assert_unicode(value):
|
||||||
for k, v in value.items():
|
for k, v in value.items():
|
||||||
assert_unicode(k)
|
assert_unicode(k)
|
||||||
assert_unicode(v)
|
assert_unicode(v)
|
||||||
elif isinstance(value, collections.Iterable):
|
elif isinstance(value, collections.abc.Iterable):
|
||||||
for item in value:
|
for item in value:
|
||||||
assert_unicode(item)
|
assert_unicode(item)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue