Ejemplo n.º 1
0
	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)
Ejemplo n.º 2
0
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"
Ejemplo n.º 3
0
	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
Ejemplo n.º 4
0
	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)
Ejemplo n.º 5
0
	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
Ejemplo n.º 6
0
	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
Ejemplo n.º 7
0
	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
Ejemplo n.º 8
0
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