2001-09-10 03:14:13 +00:00
|
|
|
#!/usr/bin/python2
|
|
|
|
|
2001-09-11 01:40:42 +00:00
|
|
|
import os
|
2001-09-10 03:14:13 +00:00
|
|
|
import string
|
2001-09-17 01:20:40 +00:00
|
|
|
import commands
|
2001-09-10 03:14:13 +00:00
|
|
|
import StringIO
|
|
|
|
import SimpleHTTPServer
|
|
|
|
import scrollkeeper
|
2001-09-11 01:40:42 +00:00
|
|
|
|
2001-09-10 03:14:13 +00:00
|
|
|
BaseClass = SimpleHTTPServer.SimpleHTTPRequestHandler
|
|
|
|
ScrollKeeper = scrollkeeper.ScrollKeeper()
|
2001-09-11 01:40:42 +00:00
|
|
|
|
2001-09-17 01:20:40 +00:00
|
|
|
htmlbase = "/var/cache/scrollserver/"
|
2001-09-11 01:40:42 +00:00
|
|
|
|
2001-09-17 01:20:40 +00:00
|
|
|
def FileContents(filename):
|
|
|
|
f = open(filename, "r")
|
|
|
|
text = f.read()
|
|
|
|
f.close
|
|
|
|
return text
|
2001-09-11 01:40:42 +00:00
|
|
|
|
2001-09-10 03:14:13 +00:00
|
|
|
class MyRequestHandler(BaseClass):
|
|
|
|
|
|
|
|
def do_GET(self):
|
|
|
|
BaseClass.do_GET(self)
|
|
|
|
|
|
|
|
def send_head(self):
|
|
|
|
|
|
|
|
# extract parameter
|
|
|
|
uri = string.split(self.path,"?")
|
|
|
|
if len(uri) > 1:
|
|
|
|
parameter = uri[1]
|
|
|
|
else:
|
|
|
|
parameter = ""
|
|
|
|
|
|
|
|
# extract filename
|
|
|
|
uri = string.split(uri[0],"/")
|
|
|
|
if len(uri) > 1:
|
|
|
|
directory = uri[0]
|
|
|
|
filename = uri[1]
|
|
|
|
else:
|
|
|
|
directory = ""
|
2001-09-17 01:20:40 +00:00
|
|
|
filename = uri[0]
|
2001-09-10 03:14:13 +00:00
|
|
|
|
|
|
|
if self.path == "" or self.path == "/" or self.path == "/index.html":
|
2001-09-17 01:20:40 +00:00
|
|
|
return self.send_ContentsList()
|
2001-09-10 03:14:13 +00:00
|
|
|
elif filename == "docid":
|
|
|
|
return self.send_DocumentByID(parameter)
|
|
|
|
else:
|
|
|
|
print "Unrecognized request: " + self.path + " (" + filename + "," + parameter + ")"
|
|
|
|
document = ScrollKeeper.ContentList()
|
|
|
|
return BaseClass.send_head(self)
|
|
|
|
|
2001-09-17 01:20:40 +00:00
|
|
|
def send_ContentsList(self):
|
|
|
|
if not os.path.isfile("contents-list.html"):
|
|
|
|
cmd = "scrollkeeper-get-content-list C"
|
|
|
|
contents_list = commands.getoutput(cmd)
|
|
|
|
cmd = "xsltproc stylesheets/contents-list/contents-list.xsl " + contents_list + " > contents-list.html"
|
|
|
|
os.system(cmd)
|
|
|
|
return self.send_File("contents-list.html")
|
|
|
|
|
2001-09-10 03:14:13 +00:00
|
|
|
def send_DocumentByID(self, docid):
|
2001-09-17 01:20:40 +00:00
|
|
|
document = ScrollKeeper.DocumentByID(docid)
|
|
|
|
|
|
|
|
if document.Format == "text/html":
|
|
|
|
text = '<html><head><meta http-equiv="refresh" content="0; url=' + document.URL + '"></head></html>'
|
|
|
|
print text
|
|
|
|
return self.send_Text(text)
|
|
|
|
|
|
|
|
|
|
|
|
xmlfile = document.SourceFile
|
|
|
|
htmlpath = htmlbase + docid
|
|
|
|
htmlfile = htmlpath + "/index.html"
|
|
|
|
if not os.path.isfile(htmlfile):
|
|
|
|
cmd = "mkdir " + htmlpath
|
|
|
|
os.system(cmd)
|
|
|
|
cmd = "xsltproc --docbook --timing stylesheets/docbook/docbook.xsl " + xmlfile + " > " + htmlfile
|
|
|
|
os.system(cmd)
|
|
|
|
return self.send_File(htmlfile)
|
|
|
|
|
|
|
|
def send_File(self, filename):
|
2001-09-10 03:14:13 +00:00
|
|
|
self.send_response(200)
|
|
|
|
self.send_header("Content-type", "text/html")
|
|
|
|
self.end_headers()
|
2001-09-17 01:20:40 +00:00
|
|
|
text = FileContents(filename)
|
2001-09-10 03:14:13 +00:00
|
|
|
return StringIO.StringIO(text)
|
|
|
|
|
2001-09-17 01:20:40 +00:00
|
|
|
def send_Text(self, text):
|
2001-09-10 03:14:13 +00:00
|
|
|
self.send_response(200)
|
|
|
|
self.send_header("Content-type", "text/html")
|
|
|
|
self.end_headers()
|
|
|
|
return StringIO.StringIO(text)
|
2001-09-17 01:20:40 +00:00
|
|
|
|
2001-09-10 03:14:13 +00:00
|
|
|
|
|
|
|
def ScrollServer():
|
2001-09-11 01:40:42 +00:00
|
|
|
os.system("rm -rf /var/cache/scrollserver/*")
|
2001-09-17 01:20:40 +00:00
|
|
|
os.system("rm *.html")
|
2001-09-10 03:14:13 +00:00
|
|
|
SimpleHTTPServer.test(MyRequestHandler)
|
|
|
|
|
2001-09-11 01:40:42 +00:00
|
|
|
ScrollServer()
|
|
|
|
|