Merge pull request #11604 from bcoca/faf_deprecated_fixes
fixed first_available_found for template
This commit is contained in:
commit
115dce028d
5 changed files with 30 additions and 34 deletions
|
@ -250,8 +250,7 @@ class PluginLoader:
|
|||
if alias_name in self._plugin_path_cache:
|
||||
if not os.path.islink(self._plugin_path_cache[alias_name]):
|
||||
d = Display()
|
||||
d.warning('%s has been deprecated, which means '
|
||||
'it is kept for backwards compatibility '
|
||||
d.deprecated('%s is kept for backwards compatibility '
|
||||
'but usage is discouraged. The module '
|
||||
'documentation details page may explain '
|
||||
'more about this rationale.' %
|
||||
|
|
|
@ -448,3 +448,27 @@ class ActionBase:
|
|||
rc = 0
|
||||
|
||||
return dict(rc=rc, stdout=out, stderr=err)
|
||||
|
||||
def _get_first_available_file(self, faf, of=None, searchdir='files'):
|
||||
|
||||
self._connection._display.deprecated("first_available_file, use with_first_found or lookup('first_found',...) instead")
|
||||
for fn in faf:
|
||||
fn_orig = fn
|
||||
fnt = self._templar.template(fn)
|
||||
if self._task._role is not None:
|
||||
lead = self._task._role._role_path
|
||||
else:
|
||||
lead = fnt
|
||||
fnd = self._loader.path_dwim_relative(lead, searchdir, fnt)
|
||||
|
||||
if not os.path.exists(fnd) and of is not None:
|
||||
if self._task._role is not None:
|
||||
lead = self._task._role._role_path
|
||||
else:
|
||||
lead = of
|
||||
fnd = self._loader.path_dwim_relative(lead, searchdir, of)
|
||||
|
||||
if os.path.exists(fnd):
|
||||
return fnd
|
||||
|
||||
return None
|
||||
|
|
|
@ -74,20 +74,8 @@ class ActionModule(ActionBase):
|
|||
# if we have first_available_file in our vars
|
||||
# look up the files and use the first one we find as src
|
||||
elif faf:
|
||||
#FIXME: issue deprecation warning for first_available_file, use with_first_found or lookup('first_found',...) instead
|
||||
found = False
|
||||
for fn in faf:
|
||||
fn_orig = fn
|
||||
fnt = self._templar.template(fn)
|
||||
fnd = self._loader.path_dwim_relative(self._task._role._role_path, 'files', fnt)
|
||||
of = task_vars.get('_original_file', None)
|
||||
if not os.path.exists(fnd) and of is not None:
|
||||
fnd = self._loader.path_dwim_relative(of, 'files', of)
|
||||
if os.path.exists(fnd):
|
||||
source = fnd
|
||||
found = True
|
||||
break
|
||||
if not found:
|
||||
source = self._get_first_available_file(faf, task_vars.get('_original_file', None))
|
||||
if source is None:
|
||||
return dict(failed=True, msg="could not find src in first_available_file list")
|
||||
else:
|
||||
if self._task._role is not None:
|
||||
|
|
|
@ -64,23 +64,8 @@ class ActionModule(ActionBase):
|
|||
tmp = self._make_tmp_path()
|
||||
|
||||
if faf:
|
||||
#FIXME: issue deprecation warning for first_available_file, use with_first_found or lookup('first_found',...) instead
|
||||
found = False
|
||||
for fn in faf:
|
||||
fn_orig = fn
|
||||
fnt = self._templar.template(fn)
|
||||
fnd = self._loader.path_dwim(self._task._role_._role_path, 'templates', fnt)
|
||||
|
||||
if not os.path.exists(fnd):
|
||||
of = task_vars.get('_original_file', None)
|
||||
if of is not None:
|
||||
fnd = self._loader.path_dwim(self._task._role_._role_path, 'templates', of)
|
||||
|
||||
if os.path.exists(fnd):
|
||||
source = fnd
|
||||
found = True
|
||||
break
|
||||
if not found:
|
||||
source = self._get_first_available_file(faf, task_vars.get('_original_file', None, 'templates'))
|
||||
if source is None:
|
||||
return dict(failed=True, msg="could not find src in first_available_file list")
|
||||
else:
|
||||
if self._task._role is not None:
|
||||
|
|
|
@ -111,7 +111,7 @@ class Display:
|
|||
else:
|
||||
self.display("<%s> %s" % (host, msg), color='blue', screen_only=True)
|
||||
|
||||
def deprecated(self, msg, version, removed=False):
|
||||
def deprecated(self, msg, version=None, removed=False):
|
||||
''' used to print out a deprecation message.'''
|
||||
|
||||
if not removed and not C.DEPRECATION_WARNINGS:
|
||||
|
|
Loading…
Reference in a new issue