-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmakeTutorialHtml.jy
167 lines (136 loc) · 5.01 KB
/
makeTutorialHtml.jy
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# 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.autoplot import AutoplotUtil
from javax.swing import BoxLayout,JPanel,JLabel,JButton,JOptionPane
print '****'
print 'Running AWESOME local copy'
print '====='
print params
print '====='
d= getParam('dir', 'file:/home/jbf/tmp/pngwalk3', 'the pngwalk home' )
outdir= getParam('outdir','/home/jbf/tmp/testtut/', 'the output directory' )
qconly= getParam('qconly','F', 'only qc records', ['T','F'] )
if ( outdir=='' ):
outdir= d
copyImages= False
else:
copyImages= True
mkdir(outdir)
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 /')
if ( not d.endswith('/') ): d= d+'/'
def getCaption( qcFile ):
'return the last review comment in the xml file'
print 'qcFile: ', qcFile
try:
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 )
print 'caption: ', caption
return caption
except:
return 'No Caption'
print 'ls '+d + '/' + ff + '*.png'
ll= listDirectory( d + '/' + ff + '*.png' )
if len(ll)==0:
print 'ls '+d + '/' + ff + '*.jpg'
ll= listDirectory( d + '/' + ff + '*.jpg' )
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
i=0
nll= 0
for l in ll:
cap= getCaption( d + '/' + l + '.ok' )
if ( cap=='No Caption' ):
cap= getCaption( d + '/' + l + '.problem' )
if ( cap=='No Caption' ):
if ( qconly=='T' ):
continue
else:
cap= ''
nll= nll+1
monitor.setTaskSize(nll)
monitor.started()
cssurl= URL("https://github.com/autoplot/scripts/makeTutorialHtml.css");
from org.autoplot.datasource import DataSetURI
cssfile= DataSetURI.getFile(cssurl,monitor.getSubtaskMonitor(0,10,'download css'));
from org.das2.util import FileUtil
FileUtil.fileCopy( cssfile, File( outdir + '/style.css' ) )
for l in ll:
monitor.setTaskProgress(i)
monitor.setProgressMessage(l)
cap= getCaption( d + '/' + l + '.ok' )
if ( cap=='No Caption' ):
cap= getCaption( d + '/' + l + '.problem' )
if ( cap=='No Caption' ):
if ( qconly=='T' ):
continue
else:
cap= ''
img= l # remove the '.ok'
if ! File( d + img ).equals( File( outdir + '/' + img ) ):
from org.das2.util import FileUtil
FileUtil.fileCopy( File( d + img ), File( outdir + '/' + img ) )
html= open( outdir + ff + '_'+ '%04d' % i + '.html', 'w' )
if ( i>0 ):
prevs= '<a href="'+ff + '_'+ '%04d' % (i-1) + '.html' + '">previous</a> '
else:
prevs= 'previous '
if ( i<(nll-1) ):
nexts= '<a href="' + ff + '_'+ '%04d' % (i+1) + '.html' + '">next</a>'
else:
nexts= 'next '
poss= '%d of %d' % ( i+1, nll )
htmltemp= '''
<head>
<title>%(dat)s</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div id='header'>
<strong>%(dat)s</strong>%(summary)s <br>%(prevs)s %(nexts)s %(poss)s
</div>
<div id='content'>
<figure id='fig'>
<a href=%(img)s">
<img id='contentImg' src="%(img)s"></a>
<figcaption id="fcap">%(cap)s</figcaption>
</figure>
</div>
</body>
</html>
'''
sss= htmltemp % { 'dat':thedate, 'summary':summary, 'prevs':prevs, 'nexts':nexts, 'poss':poss, 'img': img, 'cap':cap }
html.write( sss )
i= i + 1
html.close()
monitor.finished()
url= outdir+'/' + ff + '_0000' + '.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)