@ -52,7 +59,7 @@ class CacheModule(BaseCacheModule):
try:
os.makedirs(self._cache_dir)
except(OSError,IOError)ase:
self._display.warning("error while trying to create cache dir %s : %s"%(self._cache_dir,to_bytes(e)))
display.warning("error while trying to create cache dir %s : %s"%(self._cache_dir,to_bytes(e)))
returnNone
defget(self,key):
@ -71,11 +78,12 @@ class CacheModule(BaseCacheModule):
self._cache[key]=value
returnvalue
exceptValueErrorase:
self._display.warning("error while trying to read %s : %s. Most likely a corrupt file, so erasing and failing."%(cachefile,to_bytes(e)))
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)
raiseAnsibleError("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)
raiseAnsibleError("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)
except(OSError,IOError)ase:
self._display.warning("error while trying to read %s : %s"%(cachefile,to_bytes(e)))
display.warning("error while trying to read %s : %s"%(cachefile,to_bytes(e)))
raiseKeyError
defset(self,key,value):
@ -86,7 +94,7 @@ class CacheModule(BaseCacheModule):
try:
f=codecs.open(cachefile,'w',encoding='utf-8')
except(OSError,IOError)ase:
self._display.warning("error while trying to write to %s : %s"%(cachefile,to_bytes(e)))
display.warning("error while trying to write to %s : %s"%(cachefile,to_bytes(e)))
pass
else:
f.write(jsonify(value))
@ -102,7 +110,7 @@ class CacheModule(BaseCacheModule):
ife.errno==errno.ENOENT:
returnFalse
else:
self._display.warning("error while trying to stat %s : %s"%(cachefile,to_bytes(e)))
display.warning("error while trying to stat %s : %s"%(cachefile,to_bytes(e)))
pass
iftime.time()-st.st_mtime<=self._timeout:
@ -128,13 +136,13 @@ class CacheModule(BaseCacheModule):
ifself.has_expired(key):
returnFalse
try:
st =os.stat(cachefile)
os.stat(cachefile)
returnTrue
except(OSError,IOError)ase:
ife.errno==errno.ENOENT:
returnFalse
else:
self._display.warning("error while trying to stat %s : %s"%(cachefile,to_bytes(e)))
display.warning("error while trying to stat %s : %s"%(cachefile,to_bytes(e)))