mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
brought v2 find plugins up 2 date with v1, also added exception handling for whne there is a permissions issue
This commit is contained in:
parent
92e400eb6d
commit
7a81167b06
1 changed files with 11 additions and 10 deletions
|
@ -26,6 +26,7 @@ import sys
|
|||
import glob
|
||||
import imp
|
||||
from ansible import constants as C
|
||||
from ansible.utils import warnings
|
||||
from ansible import errors
|
||||
|
||||
MODULE_CACHE = {}
|
||||
|
@ -160,15 +161,12 @@ class PluginLoader:
|
|||
self._extra_dirs.append(directory)
|
||||
self._paths = None
|
||||
|
||||
def find_plugin(self, name, suffixes=None, transport=''):
|
||||
def find_plugin(self, name, suffixes=None):
|
||||
''' Find a plugin named name '''
|
||||
|
||||
if not suffixes:
|
||||
if self.class_name:
|
||||
suffixes = ['.py']
|
||||
else:
|
||||
if transport == 'winrm':
|
||||
suffixes = ['.ps1', '']
|
||||
else:
|
||||
suffixes = ['.py', '']
|
||||
|
||||
|
@ -180,10 +178,13 @@ class PluginLoader:
|
|||
found = None
|
||||
for path in [p for p in self._get_paths() if p not in self._searched_paths]:
|
||||
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:
|
||||
if potential_file.endswith(suffix):
|
||||
full_path = os.path.join(path, potential_file)
|
||||
if full_path.endswith(suffix):
|
||||
full_name = os.path.basename(full_path)
|
||||
break
|
||||
else: # Yes, this is a for-else: http://bit.ly/1ElPkyg
|
||||
|
|
Loading…
Reference in a new issue