Fix undefined variables, basestring usage, and some associated python3 issues

This commit is contained in:
Toshio Kuratomi 2017-07-22 18:15:46 -07:00
commit 225fa5d092
84 changed files with 652 additions and 963 deletions

View file

@ -137,7 +137,8 @@ EXAMPLES = '''
import os.path
import re
from ansible.module_utils.six import iteritems
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.six import iteritems, string_types
# exceptions -------------------------------------------------------------- {{{
@ -206,7 +207,7 @@ class Homebrew(object):
- os.path.sep
'''
if isinstance(path, basestring):
if isinstance(path, string_types):
return not cls.INVALID_PATH_REGEX.search(path)
try:
@ -234,7 +235,7 @@ class Homebrew(object):
return True
return (
isinstance(brew_path, basestring)
isinstance(brew_path, string_types)
and not cls.INVALID_BREW_PATH_REGEX.search(brew_path)
)
@ -246,7 +247,7 @@ class Homebrew(object):
return True
return (
isinstance(package, basestring)
isinstance(package, string_types)
and not cls.INVALID_PACKAGE_REGEX.search(package)
)
@ -267,7 +268,7 @@ class Homebrew(object):
return True
else:
return (
isinstance(state, basestring)
isinstance(state, string_types)
and state.lower() in (
'installed',
'upgraded',
@ -316,7 +317,7 @@ class Homebrew(object):
raise HomebrewException(self.message)
else:
if isinstance(path, basestring):
if isinstance(path, string_types):
self._path = path.split(':')
else:
self._path = path
@ -515,7 +516,7 @@ class Homebrew(object):
'update',
])
if rc == 0:
if out and isinstance(out, basestring):
if out and isinstance(out, string_types):
already_updated = any(
re.search(r'Already up-to-date.', s.strip(), re.IGNORECASE)
for s in out.split('\n')
@ -902,8 +903,6 @@ def main():
else:
module.exit_json(changed=changed, msg=message)
# this is magic, see lib/ansible/module_common.py
from ansible.module_utils.basic import *
if __name__ == '__main__':
main()

View file

@ -97,7 +97,8 @@ EXAMPLES = '''
import os.path
import re
from ansible.module_utils.six import iteritems
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.six import iteritems, string_types
# exceptions -------------------------------------------------------------- {{{
@ -163,7 +164,7 @@ class HomebrewCask(object):
- os.path.sep
'''
if isinstance(path, basestring):
if isinstance(path, (string_types)):
return not cls.INVALID_PATH_REGEX.search(path)
try:
@ -191,7 +192,7 @@ class HomebrewCask(object):
return True
return (
isinstance(brew_path, basestring)
isinstance(brew_path, string_types)
and not cls.INVALID_BREW_PATH_REGEX.search(brew_path)
)
@ -203,7 +204,7 @@ class HomebrewCask(object):
return True
return (
isinstance(cask, basestring)
isinstance(cask, string_types)
and not cls.INVALID_CASK_REGEX.search(cask)
)
@ -219,7 +220,7 @@ class HomebrewCask(object):
return True
else:
return (
isinstance(state, basestring)
isinstance(state, string_types)
and state.lower() in (
'installed',
'absent',
@ -264,7 +265,7 @@ class HomebrewCask(object):
raise HomebrewCaskException(self.message)
else:
if isinstance(path, basestring):
if isinstance(path, string_types):
self._path = path.split(':')
else:
self._path = path
@ -423,7 +424,7 @@ class HomebrewCask(object):
'update',
])
if rc == 0:
if out and isinstance(out, basestring):
if out and isinstance(out, string_types):
already_updated = any(
re.search(r'Already up-to-date.', s.strip(), re.IGNORECASE)
for s in out.split('\n')
@ -603,8 +604,6 @@ def main():
else:
module.exit_json(changed=changed, msg=message)
# this is magic, see lib/ansible/module_common.py
from ansible.module_utils.basic import *
if __name__ == '__main__':
main()

View file

@ -68,11 +68,14 @@ EXAMPLES = '''
state: absent
'''
import shlex
import os
import re
import sys
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.six.moves import shlex_quote
def query_package(module, name):
pkg_info_path = module.get_bin_path('pkg_info', False)
@ -81,7 +84,7 @@ def query_package(module, name):
if pkg_info_path:
pkgng = False
pkg_glob_path = module.get_bin_path('pkg_glob', True)
rc, out, err = module.run_command("%s -e `pkg_glob %s`" % (pkg_info_path, pipes.quote(name)), use_unsafe_shell=True)
rc, out, err = module.run_command("%s -e `pkg_glob %s`" % (pkg_info_path, shlex_quote(name)), use_unsafe_shell=True)
else:
pkgng = True
pkg_info_path = module.get_bin_path('pkg', True)
@ -137,11 +140,13 @@ def remove_packages(module, packages):
if not query_package(module, package):
continue
rc, out, err = module.run_command("%s `%s %s`" % (pkg_delete_path, pkg_glob_path, pipes.quote(package)), use_unsafe_shell=True)
rc, out, err = module.run_command("%s `%s %s`" % (pkg_delete_path, pkg_glob_path, shlex_quote(package)), use_unsafe_shell=True)
if query_package(module, package):
name_without_digits = re.sub('[0-9]', '', package)
rc, out, err = module.run_command("%s `%s %s`" % (pkg_delete_path, pkg_glob_path, pipes.quote(name_without_digits)),use_unsafe_shell=True)
rc, out, err = module.run_command("%s `%s %s`" % (pkg_delete_path, pkg_glob_path,
shlex_quote(name_without_digits)),
use_unsafe_shell=True)
if query_package(module, package):
module.fail_json(msg="failed to remove %s: %s" % (package, out))
@ -211,8 +216,6 @@ def main():
elif p["state"] == "absent":
remove_packages(module, pkgs)
# import module snippets
from ansible.module_utils.basic import *
if __name__ == '__main__':
main()