def codex_fresh(codex, module):
 if (not module.params['cache_valid_time']):
  return False
 timedelta = datetime.timedelta(seconds=module.params['cache_valid_time'])
 for grimoire in codex:
  lastupdate_path = os.path.join(SORCERY_STATE_DIR, (grimoire + '.lastupdate'))
  try:
   mtime = os.stat(lastupdate_path).st_mtime
  except:
   return False
  lastupdate_ts = datetime.datetime.fromtimestamp(mtime)
  if ((lastupdate_ts + timedelta) < datetime.datetime.now()):
   return False
 return True

def codex_fresh ( codex , module ) : if ( not module . params [ 'cache_valid_time' ] ) : return False timedelta = datetime . timedelta ( seconds = module . params [ 'cache_valid_time' ] ) for grimoire in codex : lastupdate_path = os . path . join ( SORCERY_STATE_DIR , ( grimoire + '.lastupdate' ) ) try : mtime = os . stat ( lastupdate_path ) . st_mtime except : return False lastupdate_ts = datetime . datetime . fromtimestamp ( mtime ) if ( ( lastupdate_ts + timedelta ) < datetime . datetime . now ( ) ) : return False return True
check if grimoire collection is fresh enough .