From f5227d494b98ebcc07d5f1f58de223d66ddc3737 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Tue, 13 Oct 2015 11:14:06 -0400 Subject: [PATCH] added missing cachefile and changed str(e) to to_bytes(e) --- lib/ansible/plugins/cache/jsonfile.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/ansible/plugins/cache/jsonfile.py b/lib/ansible/plugins/cache/jsonfile.py index 848e905de3..bf60fcf7f7 100644 --- a/lib/ansible/plugins/cache/jsonfile.py +++ b/lib/ansible/plugins/cache/jsonfile.py @@ -29,6 +29,8 @@ from ansible import constants as C from ansible.errors import * from ansible.parsing.utils.jsonify import jsonify from ansible.plugins.cache.base import BaseCacheModule +from ansible.utils.unicode import to_bytes + class CacheModule(BaseCacheModule): """ @@ -46,7 +48,7 @@ class CacheModule(BaseCacheModule): try: os.makedirs(self._cache_dir) 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 def get(self, key): @@ -61,7 +63,7 @@ class CacheModule(BaseCacheModule): try: f = codecs.open(cachefile, 'r', encoding='utf-8') 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 else: try: @@ -69,7 +71,7 @@ class CacheModule(BaseCacheModule): self._cache[key] = value return value 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) 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: @@ -83,7 +85,7 @@ class CacheModule(BaseCacheModule): try: f = codecs.open(cachefile, 'w', encoding='utf-8') 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 else: f.write(jsonify(value)) @@ -99,7 +101,7 @@ class CacheModule(BaseCacheModule): if e.errno == errno.ENOENT: return False 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 if time.time() - st.st_mtime <= self._timeout: @@ -131,7 +133,7 @@ class CacheModule(BaseCacheModule): if e.errno == errno.ENOENT: return False 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 def delete(self, key):