forked from autoplot/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakeTutorialHtml.jy
More file actions
88 lines (67 loc) · 3.12 KB
/
makeTutorialHtml.jy
File metadata and controls
88 lines (67 loc) · 3.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# Generate HTML demonstrations based on Screenshots Tool and PngWalkTool QC facility.
# The screenshots tool is run, creating a sequence of screenshots. This should be trimmed
# automatically, so that all images are of the same size, and as small as possible.
# The PNGWalk QC tool is turned on, and then "OK/green" images are written to HTML with
# the last comment as the caption to each figure.
from javax.xml.parsers import ParserConfigurationException
from javax.xml.parsers import DocumentBuilderFactory
from javax.xml.xpath import XPath
from javax.xml.xpath import XPathExpressionException
from javax.xml.xpath import XPathFactory
from javax.xml.xpath import XPathConstants
from org.xml.sax import InputSource
from java.io import File
from java.io import FileInputStream
from org.virbo.autoplot import AutoplotUtil
from javax.swing import BoxLayout,JPanel,JLabel,JButton,JOptionPane
d= getParam('dir','/home/jbf/ct/autoplot/tutorials/plotVap/', 'the pngwalk home' )
ff= getParam('name', '', 'prefix for each file, e.g. product')
summary= getParam('summary','', 'One-line summary or title' )
if ( d.startswith('file:') ): d= d[5:]
if ( not d.startswith('/') ): raise Exception('folder must start with /')
def getCaption( qcFile ):
'return the last review comment in the xml file'
myin= FileInputStream( qcFile )
builder = DocumentBuilderFactory.newInstance().newDocumentBuilder()
source = InputSource( myin )
initialDocument = builder.parse(source)
factory= XPathFactory.newInstance()
xpath= factory.newXPath()
caption= xpath.evaluate( '/qualityControlRecord/reviewComment[last()]/text()', initialDocument, XPathConstants.STRING )
return caption
print 'ls '+d + '/' + ff + '*.ok'
ll= listDirectory( d + '/' + ff + '*.ok' )
print 'found %d files.'%len(ll)
thedate= TimeParser.create('$Y$m$d_$H$M').format(TimeUtil.now())
if ( ff=='' ): ff= thedate
if ( len(summary)>0 ):
summary= '<br>' + summary
html= open( d + '/' + ff + '.html', 'w' )
html.write( '''
<head><title>%(dat)s</title></head>
<body style="background-color: #6B6B6B; margin=0;">
<div style="padding:20px; top: 0px; margin-right=0px; background-color:black; color:white;height:30px;">
<strong>%(dat)s</strong>%(summary)s
</div>
<div style="background-color: #6B6B6B;margin-left:100px;">
''' % { 'dat':thedate, 'summary':summary } )
for l in ll:
cap= getCaption( d + '/' + l ) # bug here where line 31 error wasn't highlited.
img= l[0:-3] # remove the '.ok'
html.write( '''<figure style="width:700px; float:left;">
<a href="%(img)s">
<img src="%(img)s" style="width:100%%;margin-left:10px;margin-bottom:10px;"></a>
<figcaption style="color: white; text-align:left;">%(cap)s</figcaption>
</figure>''' % { 'img':img, 'cap':cap } )
html.write( '''</div>
</body>
</html>''' )
html.close()
url= d+'/' + ff + '.html'
print 'wrote '+url + '.'
msg= 'Wrote '+ url +'.'
panel= JPanel()
panel.setLayout( BoxLayout(panel,BoxLayout.Y_AXIS ))
panel.add( JLabel(msg) )
panel.add( JButton( 'Open in Browser', actionPerformed=lambda a: AutoplotUtil.openBrowser(url) ) )
JOptionPane.showMessageDialog( getViewWindow(),panel)