@ -52,7 +59,7 @@ class CacheModule(BaseCacheModule):
try:
try:
os.makedirs(self._cache_dir)
os.makedirs(self._cache_dir)
except(OSError,IOError)ase:
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
returnNone
defget(self,key):
defget(self,key):
@ -71,11 +78,12 @@ class CacheModule(BaseCacheModule):
self._cache[key]=value
self._cache[key]=value
returnvalue
returnvalue
exceptValueErrorase:
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)
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:
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
raiseKeyError
defset(self,key,value):
defset(self,key,value):
@ -86,7 +94,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)ase:
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
pass
else:
else:
f.write(jsonify(value))
f.write(jsonify(value))
@ -102,7 +110,7 @@ class CacheModule(BaseCacheModule):
ife.errno==errno.ENOENT:
ife.errno==errno.ENOENT:
returnFalse
returnFalse
else:
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
pass
iftime.time()-st.st_mtime<=self._timeout:
iftime.time()-st.st_mtime<=self._timeout:
@ -128,13 +136,13 @@ class CacheModule(BaseCacheModule):
ifself.has_expired(key):
ifself.has_expired(key):
returnFalse
returnFalse
try:
try:
st =os.stat(cachefile)
os.stat(cachefile)
returnTrue
returnTrue
except(OSError,IOError)ase:
except(OSError,IOError)ase:
ife.errno==errno.ENOENT:
ife.errno==errno.ENOENT:
returnFalse
returnFalse
else:
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)))