4 """ Publisher example """
5 import sys, re, time, datetime, os
6 from random
import choice
10 if q.startswith(
'arq_'):
20 installpath = os.path.dirname(__file__)
22 timeofrequest = time.gmtime()
25 queryday = time.strftime(
"%y%m%d",timeofrequest)
26 queryid = time.strftime(
"%y%m%d%H%M%S",timeofrequest)
32 datapath =
'data/arq_%s/arq_%s' % (queryday,queryid)
36 fulldatapath =
'/%s' % datapath
37 os.makedirs(fulldatapath)
40 queryfile =
'%s/query.txt' % fulldatapath
41 fh =
open(queryfile,
"w")
46 logpath = fulldatapath
47 logfile =
'%s/log.txt' % logpath
48 fh =
open(logfile,
"a")
49 print >> fh,
"%s / [id %s] - received query: %s" % (timeofrequest, queryid, q
if q
else "none" )
52 com =
"cd %s; ./CoolRunQueryWrapper.sh fileindex %s" % (installpath,queryid)
55 from commands
import getoutput
57 logfile =
'%s/log.txt' % fulldatapath
58 fh =
open(logfile,
"w")
64 outputfile =
'%s/index.html' % fulldatapath
66 fh =
open(outputfile,
"r")
69 if not page.rstrip().endswith(
"</html>"):
72 page =
"<html><body>No web page created! Here the log file:<pre><br><br><br>%s</pre></body></html>" % (log.replace(
"<",
"<").
replace(
">",
">"))
74 return (page,fulldatapath)
81 <head><title>Error</title></head>
83 Found incomplete web page! Would you like to see the
84 <a target="_blank" href="query.py?q=%s">web page fragment</a> or the
85 <a target="_blank" href="%s/log.txt">log file</a> ?
88 """ % (datapath.split(
'/')[-1], datapath)
94 installpath = os.path.dirname(__file__)
95 fulldatapath =
'%s/data/%s/%s' % (installpath,q[:10],q)
98 fh =
open(
'%s/index.html' % fulldatapath,
"r")
101 return (page,fulldatapath)
103 return (
"Could not find cache %s" % q,
None)
106 if fullpath==
None:
return
107 installpath = os.path.dirname(__file__)
110 fh =
open(
'%s/access.log' % fullpath,
"a")
111 timeofaccess = time.gmtime()
112 querytime = time.strftime(
"%y%m%d",timeofaccess)
113 print >> fh, querytime