def unlocked(path): folderConfig = os.path.join(path, FOLDERCFG) lock = getParam('LOCK', folderConfig) if not lock: return True import cache if cache.exists(path): return True md5 = checkPassword(path, lock) if len(md5) == 0: return False if md5 == 'ERROR': utils.DialogOK(GETTEXT(30080)) return False periods = [0, 1, 5, 15] setting = int(ADDON.getSetting('CACHE')) period = periods[setting] cache.add(path, period) return True
def unlocked(path, lock=None): if not lock: folderConfig = os.path.join(path, FOLDERCFG) lock = parameters.getParam('LOCK', folderConfig) if not lock: return True if cache.exists(path): return True return False
def test_cache_clear_all(self): """ Test cache clearing by downloading a page (and thus creating the cached version), then asking for everything to be cleared, and checking if files reported exist """ # download a test page first - make sure it is cached climate.get_climate_data("Melbourne") paths = cache.clear_all() # see if it self-reports successful for the test page self.assertEquals(cache.exists("Melbourne"), False) # check if files physically exists for path in paths: self.assertFalse(os.path.exists(path))
def test_cache_clear(self): """ Test cache clearing by downloading a page (and thus creating the cached version), then asking for it to be cleared, and checking if the file still exists """ # download a test page first - make sure it is cached climate.get_climate_data("Melbourne") # clear, and see if it reports successful paths = cache.clear("Melbourne") self.assertEqual(cache.exists("Melbourne"), False) # check if file physically exists for path in paths: self.assertFalse(os.path.exists(path))
def test_cache_timeout(self): """ Make sure files older than 7 days are treated as not valid for cache purposes. Fake this with changing a file's modified time with os.utime() """ page = "Melbourne" climate.get_climate_data(page) self.assertEqual(cache.exists(page), True) # cache.get_file_name should really be treated as private # most of the time, but for the purposes of the test # it's OK to use it I guess file_name = cache.get_file_name(page) # set new filetime to (max cache age + 1 day) ago new_file_datetime = datetime.now() - timedelta(cache.CACHE_PERIOD_DAYS + 1, 0) new_file_timestamp = time.mktime(new_file_datetime.timetuple()) # use the new timestamp as both access time and modify time os.utime(file_name, (new_file_timestamp, new_file_timestamp)) # assert it's now reported as not cacheable self.assertEqual(cache.exists(page), False)
def index(): if cache.exists(): worklists = cache.get_data() else: worklists = generate_worklist(50) cache.write_data(worklists) write_file_worklist(worklists) context = { "worklist_address": config("WORKLIST_ADDRESS"), "worklist_port": config("WORKLIST_PORT"), "calling_ae_title": config("CALLING_AE_TITLE"), "called_ae_title": config("CALLED_AE_TITLE"), "worklists": worklists, } return render_template("index.html", **context)
def test_cache_create(self): """ Really basic test: get a page, then check if it is reported as having cache available. """ climate.get_climate_data("Melbourne") self.assertEqual(cache.exists("Melbourne"), True)
def exists_in_cache(url, cache_hostname): return cache.exists(url, cache_hostname)