1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

added missing cachefile and changed str(e) to to_bytes(e)

This commit is contained in:
Brian Coca 2015-10-13 11:14:06 -04:00
parent 3a0bf55ae3
commit f5227d494b

View file

@ -29,6 +29,8 @@ from ansible import constants as C
from ansible.errors import * from ansible.errors import *
from ansible.parsing.utils.jsonify import jsonify from ansible.parsing.utils.jsonify import jsonify
from ansible.plugins.cache.base import BaseCacheModule from ansible.plugins.cache.base import BaseCacheModule
from ansible.utils.unicode import to_bytes
class CacheModule(BaseCacheModule): class CacheModule(BaseCacheModule):
""" """
@ -46,7 +48,7 @@ class CacheModule(BaseCacheModule):
try: try:
os.makedirs(self._cache_dir) os.makedirs(self._cache_dir)
except (OSError,IOError) as e: except (OSError,IOError) as e:
self._display.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, to_bytes(e)))
return None return None
def get(self, key): def get(self, key):
@ -61,7 +63,7 @@ class CacheModule(BaseCacheModule):
try: try:
f = codecs.open(cachefile, 'r', encoding='utf-8') f = codecs.open(cachefile, 'r', encoding='utf-8')
except (OSError,IOError) as e: except (OSError,IOError) as e:
self._display.warning("error while trying to read %s : %s" % (cachefile, str(e))) self._display.warning("error while trying to read %s : %s" % (cachefile, to_bytes(e)))
pass pass
else: else:
try: try:
@ -69,7 +71,7 @@ class CacheModule(BaseCacheModule):
self._cache[key] = value self._cache[key] = value
return value return value
except ValueError as e: except ValueError as e:
self._display.warning("error while trying to read %s : %s. Most likely a corrupt file, so erasing and failing." % (cachefile, str(e))) self._display.warning("error while trying to read %s : %s. Most likely a corrupt file, so erasing and failing." % (cachefile, to_bytes(e)))
self.delete(key) self.delete(key)
raise AnsibleError("The JSON cache file %s was corrupt, or did not otherwise contain valid JSON data. It has been removed, so you can re-run your command now." % cachefile) raise AnsibleError("The JSON cache file %s was corrupt, or did not otherwise contain valid JSON data. It has been removed, so you can re-run your command now." % cachefile)
finally: finally:
@ -83,7 +85,7 @@ class CacheModule(BaseCacheModule):
try: try:
f = codecs.open(cachefile, 'w', encoding='utf-8') f = codecs.open(cachefile, 'w', encoding='utf-8')
except (OSError,IOError) as e: except (OSError,IOError) as e:
self._display.warning("error while trying to write to %s : %s" % (cachefile, str(e))) self._display.warning("error while trying to write to %s : %s" % (cachefile, to_bytes(e)))
pass pass
else: else:
f.write(jsonify(value)) f.write(jsonify(value))
@ -99,7 +101,7 @@ class CacheModule(BaseCacheModule):
if e.errno == errno.ENOENT: if e.errno == errno.ENOENT:
return False return False
else: else:
self._display.warning("error while trying to stat %s : %s" % (cachefile, str(e))) self._display.warning("error while trying to stat %s : %s" % (cachefile, to_bytes(e)))
pass pass
if time.time() - st.st_mtime <= self._timeout: if time.time() - st.st_mtime <= self._timeout:
@ -131,7 +133,7 @@ class CacheModule(BaseCacheModule):
if e.errno == errno.ENOENT: if e.errno == errno.ENOENT:
return False return False
else: else:
self._display.warning("error while trying to stat %s : %s" % (cachefile, str(e))) self._display.warning("error while trying to stat %s : %s" % (cachefile, to_bytes(e)))
pass pass
def delete(self, key): def delete(self, key):