mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
* Replace distutils.spawn.find_executable.
* Replace distutils.util.strtobool.
(cherry picked from commit 77b7b4f75b
)
Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
parent
89560ea2e7
commit
77bf1fedf5
6 changed files with 36 additions and 27 deletions
6
changelogs/fragments/3934-distutils.yml
Normal file
6
changelogs/fragments/3934-distutils.yml
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
bugfixes:
|
||||||
|
- "say callback plugin - replace deprecated ``distutils.spawn.find_executable`` with Ansible's ``get_bin_path`` to find the ``say`` resp. ``espeak`` executables (https://github.com/ansible-collections/community.general/pull/3934)."
|
||||||
|
- "jail connection plugin - replace deprecated ``distutils.spawn.find_executable`` with Ansible's ``get_bin_path`` to find the executable (https://github.com/ansible-collections/community.general/pull/3934)."
|
||||||
|
- "lxd connection plugin - replace deprecated ``distutils.spawn.find_executable`` with Ansible's ``get_bin_path`` to find the ``lxc`` executable (https://github.com/ansible-collections/community.general/pull/3934)."
|
||||||
|
- "zone connection plugin - replace deprecated ``distutils.spawn.find_executable`` with Ansible's ``get_bin_path`` to find the executable (https://github.com/ansible-collections/community.general/pull/3934)."
|
||||||
|
- "passwordstore lookup plugin - replace deprecated ``distutils.util.strtobool`` with Ansible's ``convert_bool.boolean`` to interpret values for the ``create``, ``returnall``, ``overwrite``, 'backup``, and ``nosymbols`` options (https://github.com/ansible-collections/community.general/pull/3934)."
|
|
@ -21,11 +21,11 @@ DOCUMENTATION = '''
|
||||||
- In 2.8, this callback has been renamed from C(osx_say) into M(community.general.say).
|
- In 2.8, this callback has been renamed from C(osx_say) into M(community.general.say).
|
||||||
'''
|
'''
|
||||||
|
|
||||||
import distutils.spawn
|
|
||||||
import platform
|
import platform
|
||||||
import subprocess
|
import subprocess
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
from ansible.module_utils.common.process import get_bin_path
|
||||||
from ansible.plugins.callback import CallbackBase
|
from ansible.plugins.callback import CallbackBase
|
||||||
|
|
||||||
|
|
||||||
|
@ -47,14 +47,9 @@ class CallbackModule(CallbackBase):
|
||||||
self.HAPPY_VOICE = None
|
self.HAPPY_VOICE = None
|
||||||
self.LASER_VOICE = None
|
self.LASER_VOICE = None
|
||||||
|
|
||||||
self.synthesizer = distutils.spawn.find_executable('say')
|
try:
|
||||||
if not self.synthesizer:
|
self.synthesizer = get_bin_path('say')
|
||||||
self.synthesizer = distutils.spawn.find_executable('espeak')
|
if platform.system() != 'Darwin':
|
||||||
if self.synthesizer:
|
|
||||||
self.FAILED_VOICE = 'klatt'
|
|
||||||
self.HAPPY_VOICE = 'f5'
|
|
||||||
self.LASER_VOICE = 'whisper'
|
|
||||||
elif platform.system() != 'Darwin':
|
|
||||||
# 'say' binary available, it might be GNUstep tool which doesn't support 'voice' parameter
|
# 'say' binary available, it might be GNUstep tool which doesn't support 'voice' parameter
|
||||||
self._display.warning("'say' executable found but system is '%s': ignoring voice parameter" % platform.system())
|
self._display.warning("'say' executable found but system is '%s': ignoring voice parameter" % platform.system())
|
||||||
else:
|
else:
|
||||||
|
@ -62,6 +57,14 @@ class CallbackModule(CallbackBase):
|
||||||
self.REGULAR_VOICE = 'Trinoids'
|
self.REGULAR_VOICE = 'Trinoids'
|
||||||
self.HAPPY_VOICE = 'Cellos'
|
self.HAPPY_VOICE = 'Cellos'
|
||||||
self.LASER_VOICE = 'Princess'
|
self.LASER_VOICE = 'Princess'
|
||||||
|
except ValueError:
|
||||||
|
try:
|
||||||
|
self.synthesizer = get_bin_path('espeak')
|
||||||
|
self.FAILED_VOICE = 'klatt'
|
||||||
|
self.HAPPY_VOICE = 'f5'
|
||||||
|
self.LASER_VOICE = 'whisper'
|
||||||
|
except ValueError:
|
||||||
|
self.synthesizer = None
|
||||||
|
|
||||||
# plugin disable itself if say is not present
|
# plugin disable itself if say is not present
|
||||||
# ansible will not call any callback if disabled is set to True
|
# ansible will not call any callback if disabled is set to True
|
||||||
|
|
|
@ -31,7 +31,6 @@ DOCUMENTATION = '''
|
||||||
- name: ansible_jail_user
|
- name: ansible_jail_user
|
||||||
'''
|
'''
|
||||||
|
|
||||||
import distutils.spawn
|
|
||||||
import os
|
import os
|
||||||
import os.path
|
import os.path
|
||||||
import subprocess
|
import subprocess
|
||||||
|
@ -39,6 +38,7 @@ import traceback
|
||||||
|
|
||||||
from ansible.errors import AnsibleError
|
from ansible.errors import AnsibleError
|
||||||
from ansible.module_utils.six.moves import shlex_quote
|
from ansible.module_utils.six.moves import shlex_quote
|
||||||
|
from ansible.module_utils.common.process import get_bin_path
|
||||||
from ansible.module_utils.common.text.converters import to_bytes, to_native, to_text
|
from ansible.module_utils.common.text.converters import to_bytes, to_native, to_text
|
||||||
from ansible.plugins.connection import ConnectionBase, BUFSIZE
|
from ansible.plugins.connection import ConnectionBase, BUFSIZE
|
||||||
from ansible.utils.display import Display
|
from ansible.utils.display import Display
|
||||||
|
@ -75,10 +75,10 @@ class Connection(ConnectionBase):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _search_executable(executable):
|
def _search_executable(executable):
|
||||||
cmd = distutils.spawn.find_executable(executable)
|
try:
|
||||||
if not cmd:
|
return get_bin_path(executable)
|
||||||
|
except ValueError:
|
||||||
raise AnsibleError("%s command not found in PATH" % executable)
|
raise AnsibleError("%s command not found in PATH" % executable)
|
||||||
return cmd
|
|
||||||
|
|
||||||
def list_jails(self):
|
def list_jails(self):
|
||||||
p = subprocess.Popen([self.jls_cmd, '-q', 'name'],
|
p = subprocess.Popen([self.jls_cmd, '-q', 'name'],
|
||||||
|
|
|
@ -43,10 +43,10 @@ DOCUMENTATION = '''
|
||||||
'''
|
'''
|
||||||
|
|
||||||
import os
|
import os
|
||||||
from distutils.spawn import find_executable
|
|
||||||
from subprocess import Popen, PIPE
|
from subprocess import Popen, PIPE
|
||||||
|
|
||||||
from ansible.errors import AnsibleError, AnsibleConnectionFailure, AnsibleFileNotFound
|
from ansible.errors import AnsibleError, AnsibleConnectionFailure, AnsibleFileNotFound
|
||||||
|
from ansible.module_utils.common.process import get_bin_path
|
||||||
from ansible.module_utils.common.text.converters import to_bytes, to_text
|
from ansible.module_utils.common.text.converters import to_bytes, to_text
|
||||||
from ansible.plugins.connection import ConnectionBase
|
from ansible.plugins.connection import ConnectionBase
|
||||||
|
|
||||||
|
@ -62,9 +62,9 @@ class Connection(ConnectionBase):
|
||||||
super(Connection, self).__init__(play_context, new_stdin, *args, **kwargs)
|
super(Connection, self).__init__(play_context, new_stdin, *args, **kwargs)
|
||||||
|
|
||||||
self._host = self._play_context.remote_addr
|
self._host = self._play_context.remote_addr
|
||||||
self._lxc_cmd = find_executable("lxc")
|
try:
|
||||||
|
self._lxc_cmd = get_bin_path("lxc")
|
||||||
if not self._lxc_cmd:
|
except ValueError:
|
||||||
raise AnsibleError("lxc command not found in PATH")
|
raise AnsibleError("lxc command not found in PATH")
|
||||||
|
|
||||||
if self._play_context.remote_user is not None and self._play_context.remote_user != 'root':
|
if self._play_context.remote_user is not None and self._play_context.remote_user != 'root':
|
||||||
|
|
|
@ -26,7 +26,6 @@ DOCUMENTATION = '''
|
||||||
- name: ansible_zone_host
|
- name: ansible_zone_host
|
||||||
'''
|
'''
|
||||||
|
|
||||||
import distutils.spawn
|
|
||||||
import os
|
import os
|
||||||
import os.path
|
import os.path
|
||||||
import subprocess
|
import subprocess
|
||||||
|
@ -34,6 +33,7 @@ import traceback
|
||||||
|
|
||||||
from ansible.errors import AnsibleError
|
from ansible.errors import AnsibleError
|
||||||
from ansible.module_utils.six.moves import shlex_quote
|
from ansible.module_utils.six.moves import shlex_quote
|
||||||
|
from ansible.module_utils.common.process import get_bin_path
|
||||||
from ansible.module_utils.common.text.converters import to_bytes
|
from ansible.module_utils.common.text.converters import to_bytes
|
||||||
from ansible.plugins.connection import ConnectionBase, BUFSIZE
|
from ansible.plugins.connection import ConnectionBase, BUFSIZE
|
||||||
from ansible.utils.display import Display
|
from ansible.utils.display import Display
|
||||||
|
@ -64,10 +64,10 @@ class Connection(ConnectionBase):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _search_executable(executable):
|
def _search_executable(executable):
|
||||||
cmd = distutils.spawn.find_executable(executable)
|
try:
|
||||||
if not cmd:
|
return get_bin_path(executable)
|
||||||
|
except ValueError:
|
||||||
raise AnsibleError("%s command not found in PATH" % executable)
|
raise AnsibleError("%s command not found in PATH" % executable)
|
||||||
return cmd
|
|
||||||
|
|
||||||
def list_zones(self):
|
def list_zones(self):
|
||||||
process = subprocess.Popen([self.zoneadm_cmd, 'list', '-ip'],
|
process = subprocess.Popen([self.zoneadm_cmd, 'list', '-ip'],
|
||||||
|
|
|
@ -141,9 +141,9 @@ import time
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
|
|
||||||
from distutils import util
|
|
||||||
from ansible.errors import AnsibleError, AnsibleAssertionError
|
from ansible.errors import AnsibleError, AnsibleAssertionError
|
||||||
from ansible.module_utils.common.text.converters import to_bytes, to_native, to_text
|
from ansible.module_utils.common.text.converters import to_bytes, to_native, to_text
|
||||||
|
from ansible.module_utils.parsing.convert_bool import boolean
|
||||||
from ansible.utils.display import Display
|
from ansible.utils.display import Display
|
||||||
from ansible.utils.encrypt import random_password
|
from ansible.utils.encrypt import random_password
|
||||||
from ansible.plugins.lookup import LookupBase
|
from ansible.plugins.lookup import LookupBase
|
||||||
|
@ -211,7 +211,7 @@ class LookupModule(LookupBase):
|
||||||
try:
|
try:
|
||||||
for key in ['create', 'returnall', 'overwrite', 'backup', 'nosymbols']:
|
for key in ['create', 'returnall', 'overwrite', 'backup', 'nosymbols']:
|
||||||
if not isinstance(self.paramvals[key], bool):
|
if not isinstance(self.paramvals[key], bool):
|
||||||
self.paramvals[key] = util.strtobool(self.paramvals[key])
|
self.paramvals[key] = boolean(self.paramvals[key])
|
||||||
except (ValueError, AssertionError) as e:
|
except (ValueError, AssertionError) as e:
|
||||||
raise AnsibleError(e)
|
raise AnsibleError(e)
|
||||||
if self.paramvals['missing'] not in ['error', 'warn', 'create', 'empty']:
|
if self.paramvals['missing'] not in ['error', 'warn', 'create', 'empty']:
|
||||||
|
|
Loading…
Reference in a new issue