def setPath(self, new_path): """ Executable path set property. Will try to generate the json data of the executable. """ if not new_path: return fc = FileCache(self.SETTINGS_KEY, new_path, self.CACHE_VERSION) if fc.path == self.path: # If we are setting the path again, we need to make sure the executable itself hasn't changed if not fc.dirty: return self.json_data = None self.path = None use_cache = os.environ.get("PEACOCK_DISABLE_EXE_CACHE", "0") != "1" if use_cache: obj = fc.read() if obj: self.fromPickle(obj) self.path = fc.path return json_data = JsonData(fc.path) if json_data.app_path: self.json_data = json_data self.path = fc.path self._createPathMap() fc.add(self.toPickle())
def testBasic(self): key = "test_FileCache" obj = {"foo": "bar"} FileCache.clearAll(key) fc = FileCache(key, "/no_exist", 1) self.checkFileCache(fc) self.assertEqual(fc.no_exist, True) ret = fc.add(obj) self.assertEqual(ret, False) self.assertEqual(fc.dirty, True) exe_path = Testing.find_moose_test_exe() fc = FileCache(key, exe_path, 1) self.checkFileCache(fc) val = fc.read() self.assertEqual(val, None) ret = fc.add(obj) self.assertEqual(ret, True) self.assertEqual(fc.dirty, False) ret = fc.add(obj) self.assertEqual(ret, False) self.assertEqual(fc.dirty, False) val = fc.read() self.assertEqual(val, obj) self.assertEqual(fc.dirty, False) fc = FileCache(key, exe_path, 1) self.assertEqual(fc.dirty, False) # different data version fc = FileCache(key, exe_path, 2) self.assertEqual(fc.dirty, True) FileCache.clearAll(key)