Add a base-level get_basedir method for lookup plugins and fix relative lookups

Fixes #11746
This commit is contained in:
James Cammarata 2015-07-27 10:41:28 -04:00
parent 3a4dd523d3
commit ee835ff7ad
5 changed files with 14 additions and 15 deletions

View file

@ -32,6 +32,12 @@ class LookupBase:
self._loader = loader
self._display = display
def get_basedir(self, variables):
if 'role_path' in variables:
return variables['role_path']
else:
return self._loader.get_basedir()
def _flatten(self, terms):
ret = []
for term in terms:

View file

@ -45,12 +45,9 @@ class LookupModule(LookupBase):
if isinstance(terms, basestring):
terms = [ terms ]
ret = []
basedir = self.get_basedir(variables)
if 'role_path' in variables:
basedir = variables['role_path']
else:
basedir = self._loader.get_basedir()
ret = []
for term in terms:
params = term.split()

View file

@ -32,10 +32,7 @@ class LookupModule(LookupBase):
ret = []
if 'role_path' in variables:
basedir = variables['role_path']
else:
basedir = self._loader.get_basedir()
basedir = self.get_basedir(variables)
for term in terms:
self._display.debug("File lookup term: %s" % term)

View file

@ -26,9 +26,11 @@ class LookupModule(LookupBase):
def run(self, terms, variables=None, **kwargs):
basedir = self.get_basedir(variables)
ret = []
for term in terms:
dwimmed = self._loader.path_dwim(term)
dwimmed = self._loader.path_dwim_relative(basedir, 'files', term)
globbed = glob.glob(dwimmed)
ret.extend(g for g in globbed if os.path.isfile(g))
return ret

View file

@ -30,15 +30,12 @@ class LookupModule(LookupBase):
if not isinstance(terms, list):
terms = [ terms ]
basedir = self.get_basedir(variables)
ret = []
templar = Templar(loader=self._loader, variables=variables)
if 'role_path' in variables:
basedir = variables['role_path']
else:
basedir = self._loader.get_basedir()
for term in terms:
self._display.debug("File lookup term: %s" % term)