brought v2 find plugins up 2 date with v1, also added exception handling for whne there is a permissions issue

pull/10612/head
Brian Coca 10 years ago
parent 92e400eb6d
commit 7a81167b06

@ -26,6 +26,7 @@ import sys
import glob import glob
import imp import imp
from ansible import constants as C from ansible import constants as C
from ansible.utils import warnings
from ansible import errors from ansible import errors
MODULE_CACHE = {} MODULE_CACHE = {}
@ -160,17 +161,14 @@ class PluginLoader:
self._extra_dirs.append(directory) self._extra_dirs.append(directory)
self._paths = None self._paths = None
def find_plugin(self, name, suffixes=None, transport=''): def find_plugin(self, name, suffixes=None):
''' Find a plugin named name ''' ''' Find a plugin named name '''
if not suffixes: if not suffixes:
if self.class_name: if self.class_name:
suffixes = ['.py'] suffixes = ['.py']
else: else:
if transport == 'winrm': suffixes = ['.py', '']
suffixes = ['.ps1', '']
else:
suffixes = ['.py', '']
potential_names = frozenset('%s%s' % (name, s) for s in suffixes) potential_names = frozenset('%s%s' % (name, s) for s in suffixes)
for full_name in potential_names: for full_name in potential_names:
@ -180,10 +178,13 @@ class PluginLoader:
found = None found = None
for path in [p for p in self._get_paths() if p not in self._searched_paths]: for path in [p for p in self._get_paths() if p not in self._searched_paths]:
if os.path.isdir(path): if os.path.isdir(path):
for potential_file in os.listdir(path): try:
full_paths = (os.path.join(path, f) for f in os.listdir(path))
except OSError,e:
warnings("Error accessing plugin paths: %s" % str(e))
for full_path in (f for f in full_paths if os.path.isfile(f)):
for suffix in suffixes: for suffix in suffixes:
if potential_file.endswith(suffix): if full_path.endswith(suffix):
full_path = os.path.join(path, potential_file)
full_name = os.path.basename(full_path) full_name = os.path.basename(full_path)
break break
else: # Yes, this is a for-else: http://bit.ly/1ElPkyg else: # Yes, this is a for-else: http://bit.ly/1ElPkyg

Loading…
Cancel
Save