ATLAS Offline Software
grepfile.py
Go to the documentation of this file.
1 #!/bin/env python2.5
2 #
3 # ----------------------------------------------------------------
4 # Script : subproc.py
5 # Project: AtlRunQuery
6 # Purpose: Grep lines in file and paste into shtml
7 # Authors: Andreas Hoecker (CERN), Joerg Stelzer (DESY)
8 # Created: Nov 13, 2009
9 # ----------------------------------------------------------------
10 #
11 import os
12 import sys
13 import datetime
14 import time
15 
16 def durationstr(sec):
17  dt = time.gmtime(sec)[2:6]
18  if dt[0]>1:
19  return "%id %ih %im %is" % ((dt[0]-1,) + dt[1:])
20  else:
21  return "%ih %im %is" % dt[1:]
22 
23 if __name__ == '__main__':
24 
25  # note, it is assumed that the file exist and that exactly 2 argumentds are given
26  d, searchstr, age, reffile = sys.argv
27 
28  # search for dataset pattern
29  os.system('grep %s %s > data/%s.tmp.txt' % (searchstr, reffile, searchstr))
30 
31  # read file and insert
32  fr = open( 'data/%s.tmp.txt' % searchstr, "r" )
33  ic = 0
34  filenames = []
35  paths = []
36  for line in fr:
37  ic += 1
38  filename, sep, info = str(line).partition(' ')
39  # remove path - caution, different for RAW files
40  if '.RAW' in filename:
41  path = filename[:filename.index(searchstr)]
42  if not path in paths: paths.append(path)
43  if len(paths) == 1:
44  filenames.append( [path, filename[filename.index(searchstr):]] )
45  else:
46  filenames.append( [path, filename] )
47  else:
48  path = filename[:filename.index(searchstr)+len(searchstr)+1]
49  if not path in paths: paths.append(path)
50  if len(paths) == 1:
51  filenames.append( [path, filename[filename.index(searchstr)+len(searchstr)+1:]] )
52  else:
53  filenames.append( [path, filename] )
54  fr.close()
55 
56  content = ''
57  if ic>0:
58  refpath = paths[0]
59  for path, filename in filenames:
60  if path == refpath:
61  content += '<tr><td style="padding-top:5px;padding-bottom:5px;">%s<br>\n' % filename
62  else:
63  content += '<tr><td style="padding-top:5px;padding-bottom:5px;"><font color="#CC0000"><i>The path for the following file differs from the above default. Full path + filename is thus given:</i></font><br>\n'
64  content += '%s<br>\n' % filename
65  content += '<font color="#999999"><font size="1px">%s</font></font><br></td></tr>\n' % info
66 
67  # page header
68  s = '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html xmlns:"my"><head><head><title>ATLCAL results for dataset: %s' % searchstr
69  s += '</title><LINK href="atlas-runquery.css" rel="stylesheet" type="text/css"></head><body>\n\n'
70  s += '<table style="font-family:sans-serif;padding:4px;font-size:80%;width:100%">'
71 
72  # body
73  s += '<tr><td style="font-size:110%%"><b>ATLCAL disk pool &minus; files belonging to dataset: <font color="#CC0000">%s</font><br><hr color="gray" size=1></td></tr>\n' % searchstr
74  try:
75  s += '<tr><td>Age of dataset: <b>%s</b></td></tr>' % durationstr(float(age))
76  except ValueError:
77  s += '<tr><td>Age of dataset: <b>%s</b></td></tr>' % 'unknown'
78  pass
79  if ic == 0: s += '<tr><td><b>No files found on ATLCAL.</b><br>&nbsp;<br>Note that the accounting of newly replicated datasets may take up to 24h (which adds to the production and replication delay). </td></tr>'
80  else: s += '<tr><td>Number of files found: <b>%i</b></td></tr>' % ic
81 
82  if ic>0:
83  if len(paths)==1:
84  s += '<tr><td>Common path for all files:<br> <font color="#AA0000">%s</font><br><hr color="gray" size=1></td></tr>' % refpath
85  else:
86  s += '<tr><td>Common path for the following files if not indicated otherwise:<br> <font color="#AA0000">%s</font><br><hr color="gray" size=1></td></tr>' % refpath
87 
88  # add the content
89  s += content
90 
91  # end of page
92  s += '<tr><td><hr color="red" size=1><font color="#777777"><font size="-1"><i><font size="-2">Created by AtlRunQuery on: %s</font></i></font></td></tr>' % str(datetime.datetime.now())
93  s += '</table></body></html>'
94 
95  os.system("echo '%s' > data/%s.html" % (s, searchstr))
grepfile.durationstr
def durationstr(sec)
Definition: grepfile.py:16
Trk::open
@ open
Definition: BinningType.h:40
StateLessPT_NewConfig.partition
partition
Definition: StateLessPT_NewConfig.py:49
str
Definition: BTagTrackIpAccessor.cxx:11
readCCLHist.float
float
Definition: readCCLHist.py:83