ATLAS Offline Software
Loading...
Searching...
No Matches
query Namespace Reference

Functions

 index (q='')
 _new_request (q='')
 _error_page (datapath)
 _cache_request (q)
 _touch (fullpath)

Detailed Description

Publisher example 

Function Documentation

◆ _cache_request()

query._cache_request ( q)
protected

Definition at line 93 of file query.py.

93def _cache_request(q):
94 installpath = os.path.dirname(__file__)
95 fulldatapath = '%s/data/%s/%s' % (installpath,q[:10],q)
96 try:
97 # open cache
98 fh = open('%s/index.html' % fulldatapath,"r")
99 page = fh.read()
100 fh.close()
101 return (page,fulldatapath)
102 except IOError:
103 return ("Could not find cache %s" % q, None)
104

◆ _error_page()

query._error_page ( datapath)
protected

Definition at line 78 of file query.py.

78def _error_page(datapath):
79
80 s = """<html>
81 <head><title>Error</title></head>
82 <body>
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> ?
86 </body>
87 </html>
88 """ % (datapath.split('/')[-1], datapath)
89 return s
90
91
92

◆ _new_request()

query._new_request ( q = '')
protected

Definition at line 19 of file query.py.

19def _new_request(q=''):
20 installpath = os.path.dirname(__file__)
21
22 timeofrequest = time.gmtime()
23
24 # data stream uses current time
25 queryday = time.strftime("%y%m%d",timeofrequest)
26 queryid = time.strftime("%y%m%d%H%M%S",timeofrequest)
27
28 # add random string to avoid conflict from coincident query
29 queryid += "".join([choice('abcdefghijklmnopqrstyz') for x in xrange(4)])
30
31 # the query datapath
32 datapath = 'data/arq_%s/arq_%s' % (queryday,queryid)
33
34 # where to store the result
35 #fulldatapath = '%s/%s' % (installpath,datapath)
36 fulldatapath = '/%s' % datapath
37 os.makedirs(fulldatapath)
38
39 # the query that should be run
40 queryfile = '%s/query.txt' % fulldatapath
41 fh = open(queryfile,"w")
42 print >> fh, "%s" % q
43 fh.close()
44
45 # global log file
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 # run the query
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 # forward file
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("<","&lt;").replace(">","&gt;"))
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)
Definition hcg.cxx:310

◆ _touch()

query._touch ( fullpath)
protected

Definition at line 105 of file query.py.

105def _touch(fullpath):
106 if fullpath==None: return
107 installpath = os.path.dirname(__file__)
108 try:
109 # open cache
110 fh = open('%s/access.log' % fullpath,"a")
111 timeofaccess = time.gmtime()
112 querytime = time.strftime("%y%m%d",timeofaccess)
113 print >> fh, querytime
114 fh.close()
115 except IOError:
116 pass

◆ index()

query.index ( q = '')

Definition at line 8 of file query.py.

8def index(q=''):
9
10 if q.startswith('arq_'):
11 (page, fullpath) = _cache_request(q)
12 else:
13 (page, fullpath) = _new_request(q)
14
15 _touch(fullpath)
16
17 return page
18
Definition index.py:1