7 import xml.parsers.expat
as expat
8 from xml.dom
import minidom
14 from collections
import OrderedDict
21 xmlOut =
"&outformat=xml" 26 pwMan = urllib2.HTTPBasicAuthHandler()
32 pwMan.add_password( realm =
"PasswordRequired",
36 opener = urllib2.build_opener(pwMan)
37 urllib2.install_opener(opener)
43 req = urllib2.Request(url)
44 page = urllib2.urlopen(url)
49 def __init__(self, name, base, ext, url, tarPath=None):
50 self.
name = name.decode(
"utf-8")
51 self.
base = base.decode(
"utf-8")
52 self.
ext = ext.decode(
"utf-8")
53 self.
url = url.decode(
"utf-8")
59 descriptions = fileDom.getElementsByTagName(
"description")
60 if len(descriptions) > 0:
61 fileName = descriptions[0].lastChild.nodeValue
64 fileName = fileDom.getElementsByTagName(
"name")[0].lastChild.nodeValue
66 url = fileDom.getAttribute(
"href")
67 baseExt = os.path.splitext(fileName)
68 return FileNBE(fileName, baseExt[0], baseExt[1], url)
71 cacheFile =
open(filePath,
'r') 73 for line
in cacheFile:
74 splitLine = line.strip().
split(
"@")
75 cache[splitLine[0]] = splitLine[1]
79 def __init__(self, topic, thumbWebPath, caption, formats, docURL, docTitle, wrapperWebPath, wrapperPath, fileBaseName):
91 wrapper = codecs.open(self.
wrapperPath,
'w',
'utf-8')
95 wrapper.write(
hrule())
98 wrapper.write(
'<img src=../"' + self.
thumbWebPath +
'" style="border-style: none" Title="'+fig.caption+
'" />')
101 wrapper.write(
paragraph(
"Disclaimer: this .png version of the image is for browsing purposes only. Please find the official versions of this plot through the links above.", fullWidth))
109 bar += (
"[" +
link(
"DocDB" , self.
docURL) +
"] " )
112 bar += (
"[" +
link(format.ext , format.url) +
"] " )
118 <div class="col-sm-4"> 122 </div><!-- /.col-sm-4 --> 129 return "<title>" + str +
"</title>" + endl
131 return "<h1>" + str +
"</h1>" + endl
133 return "<h2>" + str +
"</h2>" + endl
135 return "<h3>" + str +
"</h3>"+ endl
137 return "<h4>" + str +
"</h4>" + endl
139 return '<a href="'+ url +
'">' + text +
"</a>" + endl
142 if width: p +=
'<p style="width:'+width+
'px;">' 145 p+= str +
"</p>" + endl
148 return "<li>" + str +
"</li>" + endl
150 return '<hr width="100%" align="left" noshade color="#000000">' + endl
153 return '<hr align="left" noshade color="#000000">' + endl
157 entry =
'<td valign="bottom" style="border:1px solid black" >' 158 entry +=
link(
'<img src="' + fig.thumbWebPath +
'" width="'+ thumbWidth +
'" style="border-style: none" Title="'+fig.caption+
'" />', fig.wrapperWebPath)
161 entry += fig.formatsBar()
172 <meta charset="utf-8"> 173 <meta http-equiv="X-UA-Compatible" content="IE=edge"> 174 <meta name="viewport" content="width=device-width, initial-scale=1"> 175 <meta name="description" content=""> 176 <meta name="author" content=""> 177 <link rel="icon" href="../../favicon.ico"> 181 <!-- Bootstrap core CSS --> 182 <link href="static/bootstrap/css/bootstrap.min.css" rel="stylesheet"> 184 <!-- Custom styles for this template --> 185 <link href="static/bootstrap/css/theme.css" rel="stylesheet"> 192 return '<body role="document">' 196 <!-- Bootstrap core JavaScript 197 ================================================== --> 198 <!-- Placed at the end of the document so the pages load faster --> 199 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> 200 <script src="static/bootstrap/js/bootstrap.min.js"></script> 206 t =
' <div class="jumbotron">' + endl
207 t+=
" " + content + endl
214 <!-- Fixed navbar --> 215 <div class="navbar navbar-default navbar-fixed-top" role="navigation"> 216 <div class="container"> 217 <div class="navbar-header"> 218 <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse"> 219 <span class="sr-only">Toggle navigation</span> 220 <span class="icon-bar"></span> 221 <span class="icon-bar"></span> 222 <span class="icon-bar"></span> 224 <a class="navbar-brand" href="#">Blessed Plots</a> 226 <div class="navbar-collapse collapse"> 227 <ul class="nav navbar-nav"> 229 t+=
' <li>' +
link(
"Grid View",
"sortgrid.html") +
'</li>' + endl
230 t+=
' <li>' +
link(
"Unsorted GridView",
"grid.html") +
'</li>' + endl
231 t+=
' <li>' +
link(
"Captioned View",
"gallery.html") +
'</li>' + endl
234 <li class="dropdown"> 235 <a href="#" class="dropdown-toggle" data-toggle="dropdown">Categories <span class="caret"></span></a> 236 <ul class="dropdown-menu" role="menu"> 239 for cat
in categories:
240 t +=
' <li><a href="#' + cat.strip().replace(
" ",
"").lower() +
'">' + cat +
'</a></li>' + endl
247 </div><!--/.nav-collapse --> 255 <!-- Fixed navbar --> 256 <div class="navbar navbar-default navbar-fixed-top" role="navigation"> 257 <div class="container"> 258 <div class="navbar-header"> 259 <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse"> 260 <span class="sr-only">Toggle navigation</span> 261 <span class="icon-bar"></span> 262 <span class="icon-bar"></span> 263 <span class="icon-bar"></span> 265 <a class="navbar-brand" href="#">Project name</a> 267 <div class="navbar-collapse collapse"> 270 </div><!--/.nav-collapse --> 277 webPath =
"/nusoft/app/web/htdoc/nova/blessedplots/" 278 officialURL =
"http://nova-docdb.fnal.gov:8080/cgi-bin/Search?topics=370" + xmlOut
279 thumbsDir =
"thumbs/" 280 wrappersDir =
"wrappers/" 281 thumbsPath = webPath + thumbsDir
282 wrappersPath = webPath + wrappersDir
284 tempPath = webPath + tempDir
286 pageTitle =
"NOvA Blessed Plots and Figures Gallery" 287 gridTitle =
"NOvA Blessed Plots and Figures Grid" 290 pw =
open(os.environ[
'NOVADOCPWDFILE'],
'r').readlines()[0].strip() 294 optParser = optparse.OptionParser()
295 optParser.add_option(
"--nothumbs", action=
"store_true",
296 help=
"Do not remake the thumbnails, runs more quickly. This is pretty dangerous, could lead to borked HTML pages. Only meant to debug HTML writing.")
297 optParser.add_option(
"--nocaps", action=
"store_true",
298 help=
"Do not download the captions, runs more quickly. Only meant to debug HTML writing.")
299 optParser.add_option(
"--nocache", action=
"store_true",
300 help=
"Ignore the fact that the cached version is current, run anyway")
303 (options, args) = optParser.parse_args()
309 officialDom = minidom.parse(officialPage)
310 documents = officialDom.getElementsByTagName(
"document")
316 statusPath = webPath +
"status.txt" 318 status = OrderedDict()
319 for doc
in documents:
320 id = doc.getAttribute(
"id")
321 rev = doc.getElementsByTagName(
"docrevision")[0]
322 mod = rev.getAttribute(
"modified")
326 for id
in status.keys():
327 if id
in cacheStatus.keys():
328 if not cacheStatus[id] == status[id]:
333 for id
in cacheStatus.keys():
334 if not id
in status.keys():
337 if not changed
and not options.nocache:
338 print "The page has not changed, exiting" 341 statusFile =
open(statusPath,
'w')
342 for key
in status.keys():
343 statusFile.write(key +
"@" + status[key] + endl)
348 for doc
in documents:
350 docURL = doc.getAttribute(
"href") + xmlOut
351 print "DOC ID : ", doc.getAttribute(
"id")
354 docDom = minidom.parse(docPage)
355 topics = docDom.getElementsByTagName(
"topic")
360 topicNames.append(topic.getElementsByTagName(
"name")[0].lastChild.nodeValue)
363 if not "Official" in topicNames:
369 nameDom = topic.getElementsByTagName(
"name")
371 name = nameDom[0].lastChild.nodeValue
375 if name ==
"Blessed Plots" or name ==
"Official":
379 if not name
in topicMap.keys():
382 topicMap[name].
append(docDom.getElementsByTagName(
"document")[0])
384 print "###########################################################" 386 topics = topicMap.keys()
392 gallery = codecs.open(webPath +
"gallery_new.html",
'w',
"utf-8")
395 if not options.nothumbs:
397 os.system(
"rm -f " + tempPath +
"*")
398 os.system(
"rm -f " + thumbsPath +
"*")
402 gallery.write(
navBar(topics))
404 gallery.write(
"<title>" + pageTitle +
"</title>")
406 gallery.write(
paragraph(
"To find out how to add a plot to this page, read this " +
link(
"guide",
"howto.html") +
"."))
409 gallery.write(
'<a name="toc"> </a>')
410 gallery.write(
heading2(
"Categories"))
411 gallery.write(
"<ul>")
414 gallery.write(
entry(
link(topic + hendl,
"gallery.html#" + topic.strip().replace(
" ",
"").lower())))
415 gallery.write(
"</ul>")
417 gallery.write(
hrule())
419 savedFigsByTopic = OrderedDict()
423 savedFigsByTopic[topic] = []
425 gallery.write(
'<a name="' + topic.strip().replace(
" ",
"").lower() +
'"> </a>')
427 gallery.write(
hrule())
430 gallery.write(
'<table border=0 class="fixed" cellpadding="20"> <col width="' + thumbSize +
'px" /> <col width="740px" />' + endl)
432 for docDom
in topicMap[topic]:
434 docId = docDom.getAttribute(
"id")
435 docURL = docDom.getAttribute(
"href")
436 docTitle = docDom.getElementsByTagName(
"title")[0].lastChild.nodeValue
437 files = docDom.getElementsByTagName(
"file")
444 for fileDom
in files:
446 if fileNBE.name ==
'Document Archive':
447 arcUrl = fileDom.getAttribute(
"href")
448 tempName = tempPath +
'docArchive.tar.gz' 450 tar = tarfile.open(tempName,
'r') 451 for name
in tar.getnames():
452 base, ext = os.path.splitext(name)
454 if "._" in base:
continue 459 url =
'http://nova-docdb.fnal.gov:8080/cgi-bin/RetrieveFile?docid='+docId+
'&filename='+name
460 nbes.append(
FileNBE(name, base, ext, url, tempName))
465 if fileNBE.ext ==
".txt":
466 foundOnceAlready =
False 467 print "Found CAPTION : ", fileNBE.name, fileNBE.base, docId
469 shortName =
"doc" + docId +
"_" + fileNBE.base
470 thumbName = shortName +
".png" 471 thumbPath = thumbsPath + thumbName
472 thumbWebPath = thumbsDir + thumbName
473 wrapperName = shortName +
".html" 474 wrapperPath = wrappersPath + wrapperName
475 wrapperWebPath = wrappersDir + wrapperName
477 if not os.path.isfile(thumbPath)
and not options.nothumbs:
478 print "MAKING THUMBNAIL " 479 for otherFileNBE
in nbes:
481 if otherFileNBE.base == fileNBE.base
and not otherFileNBE.ext ==
".txt":
483 imgUrl = otherFileNBE.url
484 tempName = tempPath + otherFileNBE.name
485 if otherFileNBE.tarPath:
486 tar = tarfile.open(otherFileNBE.tarPath,
'r') 487 tar.extract(otherFileNBE.name, tempPath) 490 os.system(
"convert -trim -resize " + fullWidth +
" " + tempName +
" " + thumbPath)
493 print "THUMBNAIL ALREADY EXISTS" 494 foundOnceAlready = (
True and not options.nothumbs)
497 gallery.write(
"<tr>")
498 gallery.write(
'<td>' +
link(
'<img src="' + thumbWebPath +
'" width="'+ thumbSize +
'" style="border-style: none"/ >', wrapperWebPath) +
'</td>' )
499 gallery.write(
'<td valign="top">')
502 gallery.write(
heading4(fileNBE.base))
503 gallery.write(
link(
"[DocDB]", docURL) +
" " )
505 for otherFileNBE
in nbes:
506 if otherFileNBE.base == fileNBE.base
and not otherFileNBE.ext ==
".txt":
507 gallery.write(
"[" +
link(otherFileNBE.ext , otherFileNBE.url) +
"] " )
508 formats.append(otherFileNBE)
510 gallery.write(
"</p>")
511 if not options.nocaps:
513 capFile = tarfile.open(fileNBE.tarPath,
'r')\ 514 .extractfile(fileNBE.name) 517 caption = cgi.escape(
str(capFile.read()).
decode(encoding=
"utf-8", errors=
'ignore')).replace(
"\n",
"<br> \n").replace(
"\t",
" ")
519 caption =
"No caption option enabled. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum." 521 gallery.write(caption)
522 gallery.write(
"</p>")
523 gallery.write(
' </td>' )
524 gallery.write(
"</tr>")
527 fig =
SavedFigure(topic, thumbWebPath, caption, formats, docURL, docTitle, wrapperWebPath, wrapperPath, fileNBE.base)
530 savedFigsByTopic[topic].
append(fig)
531 if not foundOnceAlready:
532 savedFigs.append(fig)
535 gallery.write(
"</table>" + endl)
536 gallery.write(
"</section>")
537 gallery.write(
link(
"Return to Table of Categories",
"gallery.html#toc"))
539 gallery.write(
paragraph(
"Page generated at " + datetime.datetime.now().strftime(
"%Y/%m/%d at %H:%M")))
543 grid = codecs.open(webPath +
"grid_new.html",
'w',
"utf-8")
545 grid.write(
"<title>" + pageTitle +
"</title>"+endl)
549 grid.write(
navBar(topics))
552 grid.write(
paragraph(
"To find out how to add a plot to this page, read this " +
link(
"guide",
"howto.html") +
".") + endl)
558 grid.write(
'<table style="border:1px solid black;border-collapse:collapse;" class="fixed" cellpadding="5"> ' + endl)
559 for i
in range(0, gridNumCols):
560 grid.write(
' <col width="' + thumbSize +
'px" /> ' + endl)
562 grid.write(
"<tr>"+endl)
564 for fig
in savedFigs:
565 grid.write(
gridEntry(fig, gridThumbWidth))
567 if currentCell == gridNumCols:
568 grid.write(
"</tr>"+endl)
569 grid.write(
"<tr>"+endl)
573 grid.write(
"</tr>"+endl)
574 grid.write(
"</table>"+endl)
576 grid.write(
paragraph(
"Page generated at " + datetime.datetime.now().strftime(
"%Y/%m/%d at %H:%M")))
580 sGrid = codecs.open(webPath +
"sortgrid_new.html",
'w',
"utf-8")
583 sGrid.write(
"<title>" + pageTitle +
"</title>"+endl)
586 sGrid.write(
navBar(topics))
588 sGrid.write(
paragraph(
"To find out how to add a plot to this page, read this " +
link(
"guide",
"howto.html") +
"."))
595 sGrid.write(
entry(
link(topic + hendl,
"sortgrid.html#" + topic.strip().replace(
" ",
"").lower())))
600 sGrid.write(
'<a name="' + topic.strip().replace(
" ",
"").lower() +
'"> </a>')
605 sGrid.write(
'<table style="border:1px solid black;border-collapse:collapse;" class="fixed" cellpadding="5"> ' + endl)
606 for i
in range(0, gridNumCols):
607 sGrid.write(
' <col width="' + thumbSize +
'px" /> ' + endl)
609 sGrid.write(
"<tr>"+endl)
611 for fig
in savedFigsByTopic[topic]:
612 sGrid.write(
gridEntry(fig, gridThumbWidth))
614 if currentCell == gridNumCols:
615 sGrid.write(
"</tr>"+endl)
616 sGrid.write(
"<tr>"+endl)
620 sGrid.write(
"</tr>"+endl)
621 sGrid.write(
"</table>"+endl)
625 sGrid.write(
paragraph(
"Page generated at " + datetime.datetime.now().strftime(
"%Y/%m/%d at %H:%M")))
630 os.system(
"mv -f " + webPath +
"gallery_new.html " + webPath +
"gallery.html")
631 os.system(
"mv -f " + webPath +
"grid_new.html " + webPath +
"grid.html")
632 os.system(
"mv -f " + webPath +
"sortgrid_new.html " + webPath +
"sortgrid.html")
void split(double tt, double *fr)
def navBar(categories=None)
def __init__(self, name, base, ext, url, tarPath=None)
def paragraph(str, width=None)
def gridEntry(fig, thumbWidth)
procfile open("FD_BRL_v0.txt")
void decode(std::any const &, InputTag &)
def loadStatusCache(filePath)