def _fromCache( self, path ): path = os.path.abspath(path) assert self.cache if isinstance(self.cache, SignatureCache): return self.cache.get(path, SignatureCache.mtime(path))[1] else: return self.cache.get(path)
def processSugar( sugarText, path, cache=True ): timestamp = has_changed = data = None is_same = False if cache: timestamp = SignatureCache.mtime(path) is_same, data = CACHE.get(path,timestamp) if (not is_same) or (not cache): modulename = os.path.splitext(os.path.basename(path))[0] parent_path = os.path.dirname(path) dirpath = tempfile.mkdtemp() p = dirpath + os.path.sep + modulename + ".sjs" f = file(p, "w") ; f.write(sugarText) command = "%s -cljs %s %s" % (COMMANDS["sugar"], "-L%s -L%s/lib/sjs" % (parent_path, parent_path), p) cmd = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) data = cmd.stdout.read() error = cmd.stderr.read() cmd.wait() ; f.close() os.unlink(p) if os.path.exists(dirpath): os.rmdir(dirpath) if not data: raise Exception(error) if cache: CACHE.set(path,timestamp,data) return data, "text/plain"
def _toCache( self, path, data ): if self.cache: if isinstance(self.cache, SignatureCache): return self.cache.set(path, SignatureCache.mtime(path), data) else: return self.cache.set(path, data) return data
def _inCache( self, path ): if self.cache: if isinstance(self.cache, SignatureCache): return self.cache.has(path, SignatureCache.mtime(path)) else: return self.cache.has(path) else: return False
def _toCache( self, path, data ): path = os.path.abspath(path) if self.cache: if isinstance(self.cache, SignatureCache): return self.cache.set(path, SignatureCache.mtime(path), data) else: return self.cache.set(path, data) return data
def _inCache( self, path ): path = os.path.abspath(path) if self.cache: if isinstance(self.cache, SignatureCache): return self.cache.has(path, SignatureCache.mtime(path)) else: return self.cache.has(path) else: return False
def cacheGet( text, path, cache ): if cache: if path: cache = SIG_CACHE timestamp = SignatureCache.mtime(path) is_same, data = cache.get(path,timestamp) return cache, is_same, data, timestamp else: text = engine.ensure_unicode(text) sig = hashlib.sha256(bytes(u" ".join(command) + text)).hexdigest() cache = MEMORY_CACHE is_same = cache.has(sig) data = cache.get(sig) return cache, is_same, data, sig else: return cache, False, None, None