19def _new_request(q=''):
20 installpath = os.path.dirname(__file__)
21
22 timeofrequest = time.gmtime()
23
24
25 queryday = time.strftime("%y%m%d",timeofrequest)
26 queryid = time.strftime("%y%m%d%H%M%S",timeofrequest)
27
28
29 queryid +=
"".join([choice(
'abcdefghijklmnopqrstyz')
for x
in xrange(4)])
30
31
32 datapath = 'data/arq_%s/arq_%s' % (queryday,queryid)
33
34
35
36 fulldatapath = '/%s' % datapath
37 os.makedirs(fulldatapath)
38
39
40 queryfile = '%s/query.txt' % fulldatapath
41 fh = open(queryfile,"w")
42 print >> fh, "%s" % q
43 fh.close()
44
45
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" )
50 fh.close()
51
52 com = "cd %s; ./CoolRunQueryWrapper.sh fileindex %s" % (installpath,queryid)
53
54
55 from commands import getoutput
56 log = getoutput(com)
57 logfile = '%s/log.txt' % fulldatapath
58 fh = open(logfile,"w")
59 print >> fh, log
60 fh.close()
61
62
63
64 outputfile = '%s/index.html' % fulldatapath
65 try:
66 fh = open(outputfile,"r")
67 page = fh.read()
68 fh.close()
69 if not page.rstrip().endswith("</html>"):
70 page = _error_page(datapath)
71 except IOError:
72 page =
"<html><body>No web page created! Here the log file:<pre><br><br><br>%s</pre></body></html>" % (log.replace(
"<",
"<").
replace(
">",
">"))
73
74 return (page,fulldatapath)
75
76
77
void xrange(TH1 *h, bool symmetric)
std::string replace(std::string s, const std::string &s2, const std::string &s3)