mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-10-04 15:34:01 -07:00
adding display to plugins and start moving debug to display
This commit is contained in:
parent
5d51f3abda
commit
851ed45bbf
20 changed files with 152 additions and 109 deletions
10
lib/ansible/plugins/cache/__init__.py
vendored
10
lib/ansible/plugins/cache/__init__.py
vendored
|
@ -22,12 +22,20 @@ from collections import MutableMapping
|
|||
from ansible import constants as C
|
||||
from ansible.plugins import cache_loader
|
||||
|
||||
try:
|
||||
from __main__ import display
|
||||
except ImportError:
|
||||
from ansible.utils.display import Display
|
||||
display = Display()
|
||||
|
||||
class FactCache(MutableMapping):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
self._plugin = cache_loader.get(C.CACHE_PLUGIN)
|
||||
self._display = display
|
||||
|
||||
if self._plugin is None:
|
||||
# FIXME: this should be an exception
|
||||
self._display.warning("Failed to load fact cache plugins")
|
||||
return
|
||||
|
||||
def __getitem__(self, key):
|
||||
|
|
8
lib/ansible/plugins/cache/base.py
vendored
8
lib/ansible/plugins/cache/base.py
vendored
|
@ -22,9 +22,17 @@ from abc import ABCMeta, abstractmethod
|
|||
|
||||
from six import with_metaclass
|
||||
|
||||
try:
|
||||
from __main__ import display
|
||||
except ImportError:
|
||||
from ansible.utils.display import Display
|
||||
display = Display()
|
||||
|
||||
|
||||
class BaseCacheModule(with_metaclass(ABCMeta, object)):
|
||||
|
||||
display = display
|
||||
|
||||
@abstractmethod
|
||||
def get(self, key):
|
||||
pass
|
||||
|
|
18
lib/ansible/plugins/cache/jsonfile.py
vendored
18
lib/ansible/plugins/cache/jsonfile.py
vendored
|
@ -46,8 +46,7 @@ class CacheModule(BaseCacheModule):
|
|||
try:
|
||||
os.makedirs(self._cache_dir)
|
||||
except (OSError,IOError), e:
|
||||
# FIXME: this is in display now, but cache plugins don't have that
|
||||
#utils.warning("error while trying to create cache dir %s : %s" % (self._cache_dir, str(e)))
|
||||
self._display.warning("error while trying to create cache dir %s : %s" % (self._cache_dir, str(e)))
|
||||
return None
|
||||
|
||||
def get(self, key):
|
||||
|
@ -62,8 +61,7 @@ class CacheModule(BaseCacheModule):
|
|||
try:
|
||||
f = codecs.open(cachefile, 'r', encoding='utf-8')
|
||||
except (OSError,IOError), e:
|
||||
# FIXME: this is in display now, but cache plugins don't have that
|
||||
#utils.warning("error while trying to read %s : %s" % (cachefile, str(e)))
|
||||
self._display.warning("error while trying to read %s : %s" % (cachefile, str(e)))
|
||||
pass
|
||||
else:
|
||||
try:
|
||||
|
@ -71,8 +69,7 @@ class CacheModule(BaseCacheModule):
|
|||
self._cache[key] = value
|
||||
return value
|
||||
except ValueError:
|
||||
# FIXME: this is in display now, but cache plugins don't have that
|
||||
#utils.warning("error while trying to write to %s : %s" % (cachefile, str(e)))
|
||||
self._display.warning("error while trying to write to %s : %s" % (cachefile, str(e)))
|
||||
raise KeyError
|
||||
finally:
|
||||
f.close()
|
||||
|
@ -85,8 +82,7 @@ class CacheModule(BaseCacheModule):
|
|||
try:
|
||||
f = codecs.open(cachefile, 'w', encoding='utf-8')
|
||||
except (OSError,IOError), e:
|
||||
# FIXME: this is in display now, but cache plugins don't have that
|
||||
#utils.warning("error while trying to write to %s : %s" % (cachefile, str(e)))
|
||||
self._display.warning("error while trying to write to %s : %s" % (cachefile, str(e)))
|
||||
pass
|
||||
else:
|
||||
f.write(jsonify(value))
|
||||
|
@ -102,8 +98,7 @@ class CacheModule(BaseCacheModule):
|
|||
if e.errno == errno.ENOENT:
|
||||
return False
|
||||
else:
|
||||
# FIXME: this is in display now, but cache plugins don't have that
|
||||
#utils.warning("error while trying to stat %s : %s" % (cachefile, str(e)))
|
||||
self._display.warning("error while trying to stat %s : %s" % (cachefile, str(e)))
|
||||
pass
|
||||
|
||||
if time.time() - st.st_mtime <= self._timeout:
|
||||
|
@ -135,8 +130,7 @@ class CacheModule(BaseCacheModule):
|
|||
if e.errno == errno.ENOENT:
|
||||
return False
|
||||
else:
|
||||
# FIXME: this is in display now, but cache plugins don't have that
|
||||
#utils.warning("error while trying to stat %s : %s" % (cachefile, str(e)))
|
||||
self._display.warning("error while trying to stat %s : %s" % (cachefile, str(e)))
|
||||
pass
|
||||
|
||||
def delete(self, key):
|
||||
|
|
3
lib/ansible/plugins/cache/redis.py
vendored
3
lib/ansible/plugins/cache/redis.py
vendored
|
@ -28,8 +28,7 @@ from ansible.plugins.cache.base import BaseCacheModule
|
|||
try:
|
||||
from redis import StrictRedis
|
||||
except ImportError:
|
||||
print("The 'redis' python module is required, 'pip install redis'")
|
||||
sys.exit(1)
|
||||
raise AnsibleError("The 'redis' python module is required for the redis fact cache, 'pip install redis'")
|
||||
|
||||
class CacheModule(BaseCacheModule):
|
||||
"""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue