[Debtags-commits] [svn] r2227 - cgi-bin

Erich Schubert erich at alioth.debian.org
Wed Jan 3 19:36:33 CET 2007


Author: erich
Date: Wed Jan  3 19:36:33 2007
New Revision: 2227

Added:
   cgi-bin/cloud
      - copied, changed from r2226, cgi-bin/erich
Modified:
   cgi-bin/rdf
Log:
rename cloud cgi to cloud, add caching to rdf cgi

Copied: cgi-bin/cloud (from r2226, cgi-bin/erich)
==============================================================================
--- cgi-bin/erich	(original)
+++ cgi-bin/cloud	Wed Jan  3 19:36:33 2007
@@ -19,7 +19,7 @@
 query = set(terms) # for comparison
 key = "\0".join(terms)
 
-db = bsddb.hashopen("../json-data/json-erich-cache.db","c")
+db = bsddb.hashopen("../cache/cloud-json.db","c")
 
 result = None
 

Modified: cgi-bin/rdf
==============================================================================
--- cgi-bin/rdf	(original)
+++ cgi-bin/rdf	Wed Jan  3 19:36:33 2007
@@ -3,7 +3,7 @@
 import cgitb; cgitb.enable()
 import os, sys
 import gzip, cStringIO
-#import time
+import time
 import Debtags
 from Debtagsd import Debtagsd
 
@@ -11,37 +11,51 @@
 from cElementTree import Element, SubElement
 
 tagurl = "http://debtags.alioth.debian.org/vocabulary/%s"
-#cache_expiry = 10*60 # 10 minutes.
+cache_expiry = 10*60 # 10 minutes.
+cachefile = "../cache/rdf"
 
 param = os.environ.get("PATH_INFO","").strip('/')
 
-# Prepare RDF
-namespaces = {
-	"xmlns:rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
-	"xmlns": "http://usefulinc.com/ns/doap#"
-}
-
-root = Element("rdf:RDF", namespaces)
-
-# query Debtags database
-srv = Debtagsd()
-srv.query("PKGS ")
-for pkg, ts, desc in srv.resultpkgs():
-	project = SubElement(root,"Project")
-
-	SubElement(project,"name").text = pkg
-	SubElement(project,"description", { "xml:lang":"en" }).text = desc
-
-	for t in ts:
-		SubElement(project, "Category", { "rdf:resource": tagurl % t })
-
-# prepare buffer for both compression and caching
-buf = cStringIO.StringIO()
-stream = gzip.GzipFile(mode = 'wb',  fileobj = buf, compresslevel = 9)
-
-stream.write(cElementTree.tostring(root))
-stream.close()
-result = buf.getvalue()
+result = None
+
+cachestat = os.stat(cachefile)
+if cachestat.st_mtime + cache_expiry < time.time():
+	f = file(cachefile,"r")
+	result = f.readlines()
+	f.close()
+
+if not result:
+	# Prepare RDF
+	namespaces = {
+		"xmlns:rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
+		"xmlns": "http://usefulinc.com/ns/doap#"
+	}
+
+	root = Element("rdf:RDF", namespaces)
+
+	# query Debtags database
+	srv = Debtagsd()
+	srv.query("PKGS ")
+	for pkg, ts, desc in srv.resultpkgs():
+		project = SubElement(root,"Project")
+
+		SubElement(project,"name").text = pkg
+		SubElement(project,"description", { "xml:lang":"en" }).text = desc
+
+		for t in ts:
+			SubElement(project, "Category", { "rdf:resource": tagurl % t })
+
+	# prepare buffer for both compression and caching
+	buf = cStringIO.StringIO()
+	stream = gzip.GzipFile(mode = 'wb',  fileobj = buf, compresslevel = 9)
+
+	stream.write(cElementTree.tostring(root))
+	stream.close()
+	result = buf.getvalue()
+
+	f = file(cachefile,"w")
+	f.write(result)
+	f.close()
 
 sys.stdout.write("Content-type: application/rdf+xml\n")
 sys.stdout.write("Content-Encoding: gzip\n")



More information about the Debtags-commits mailing list