changes for package loading of modules

This commit is contained in:
Michael DeHaan
2014-09-26 11:25:56 -04:00
parent f35ed8a6c0
commit e5116d2f9b
261 changed files with 21 additions and 70591 deletions

View File

@@ -90,22 +90,6 @@ p = load_config_file()
active_user = pwd.getpwuid(os.geteuid())[0]
# Needed so the RPM can call setup.py and have modules land in the
# correct location. See #1277 for discussion
if getattr(sys, "real_prefix", None):
# in a virtualenv
DIST_MODULE_PATH = os.path.join(sys.prefix, 'share/ansible/')
else:
DIST_MODULE_PATH = '/usr/share/ansible/'
# Look for modules relative to this file path
# This is so that we can find the modules when running from a local checkout
# installed as editable with `pip install -e ...` or `python setup.py develop`
local_module_path = os.path.abspath(
os.path.join(os.path.dirname(__file__), '..', '..', 'library')
)
DIST_MODULE_PATH = os.pathsep.join([DIST_MODULE_PATH, local_module_path])
# check all of these extensions when looking for yaml files for things like
# group variables -- really anything we can load
YAML_FILENAME_EXTENSIONS = [ "", ".yml", ".yaml", ".json" ]
@@ -115,7 +99,7 @@ DEFAULTS='defaults'
# configurable things
DEFAULT_HOST_LIST = shell_expand_path(get_config(p, DEFAULTS, 'hostfile', 'ANSIBLE_HOSTS', '/etc/ansible/hosts'))
DEFAULT_MODULE_PATH = get_config(p, DEFAULTS, 'library', 'ANSIBLE_LIBRARY', DIST_MODULE_PATH)
DEFAULT_MODULE_PATH = get_config(p, DEFAULTS, 'library', 'ANSIBLE_LIBRARY', None)
DEFAULT_ROLES_PATH = shell_expand_path(get_config(p, DEFAULTS, 'roles_path', 'ANSIBLE_ROLES_PATH', '/etc/ansible/roles'))
DEFAULT_REMOTE_TMP = get_config(p, DEFAULTS, 'remote_tmp', 'ANSIBLE_REMOTE_TEMP', '$HOME/.ansible/tmp')
DEFAULT_MODULE_NAME = get_config(p, DEFAULTS, 'module_name', None, 'command')

View File

@@ -1215,7 +1215,7 @@ class Runner(object):
module_suffixes = getattr(conn, 'default_suffixes', None)
module_path = utils.plugins.module_finder.find_plugin(module_name, module_suffixes)
if module_path is None:
raise errors.AnsibleFileNotFound("module %s not found in %s" % (module_name, utils.plugins.module_finder.print_paths()))
raise errors.AnsibleFileNotFound("module %s not found in configured module paths" % (module_name))
# insert shared code and arguments into the module

View File

@@ -75,6 +75,15 @@ class PluginLoader(object):
ret.append(i)
return os.pathsep.join(ret)
def _all_directories(self, dir):
results = []
results.append(dir)
for root, subdirs, files in os.walk(dir):
if '__init__.py' in files:
for x in subdirs:
results.append(os.path.join(root,x))
return results
def _get_package_paths(self):
''' Gets the path of a Python package '''
@@ -85,7 +94,7 @@ class PluginLoader(object):
m = __import__(self.package)
parts = self.package.split('.')[1:]
self.package_path = os.path.join(os.path.dirname(m.__file__), *parts)
paths.append(self.package_path)
paths.extend(self._all_directories(self.package_path))
return paths
else:
return [ self.package_path ]
@@ -107,7 +116,8 @@ class PluginLoader(object):
# allow directories to be two levels deep
files2 = glob.glob("%s/*/*" % fullpath)
files = files.extend(files2)
if files2 is not None:
files.extend(files2)
for file in files:
if os.path.isdir(file) and file not in ret:
@@ -128,6 +138,8 @@ class PluginLoader(object):
# look for any plugins installed in the package subtree
ret.extend(self._get_package_paths())
package_dirs = self._get_package_paths()
self._paths = ret
@@ -153,7 +165,7 @@ class PluginLoader(object):
if self.class_name:
suffixes = ['.py']
else:
suffixes = ['', '.ps1']
suffixes = ['', '.ps1', '.py']
for suffix in suffixes:
full_name = '%s%s' % (name, suffix)