File size: 9,273 Bytes
41c16fb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
[buildout]
extends = translator.cfg
          components/jxml.cfg
          components/xalan-j-2.7.2.cfg
develop+= pyhwp-tests
          tools/xsltest
          tools/gpl
parts+= test-core
	test-coverage
	test-cli
        test-xsl
        test-xsl-cov
	test-sdist
        test-tools
	test-for-bisect
        xsltest
        code-analysis
        collect-samples
        masstest-failed
        massfind-unknowntag
        massfind-incomplete
        expected-output-update

[pyhwp]
eggs+= nose
       coverage
       gpl
       pyroma

[test-core]
recipe = collective.xmltestreport
eggs = pyhwp-tests
defaults = ['--auto-color', '--auto-progress', '--xml', '--tests-pattern=hwp5_tests']

[test-xsl]
recipe = collective.recipe.template
input = ${buildout:directory}/misc/test-xsl.in
output = ${buildout:directory}/bin/test-xsl
mode = 755

[test-xsl-cov]
recipe = collective.recipe.template
mode=755
output=${buildout:bin-directory}/test-xsl-cov
input =inline:
       #!/bin/sh
       CLASSPATH=${xalan-j-2.7.2:jars} ${jxml:location}/bin/jxml-cov-test $*

[test-coverage]
recipe = collective.recipe.template
input = ${buildout:directory}/misc/test-coverage
output = ${buildout:directory}/bin/test-coverage
mode = 755

[test-cli]
recipe = collective.recipe.template
input = ${buildout:directory}/misc/test-cli.in
output = ${buildout:directory}/bin/test-cli
mode = 755

[test-sdist]
recipe = collective.recipe.template
input = ${buildout:directory}/misc/test-sdist.in
output = ${buildout:directory}/bin/test-sdist
mode = 755

[test-tools]
recipe = collective.xmltestreport
eggs = gpl
defaults = ['--auto-color', '--auto-progress', '--xml']

[test-for-bisect]
recipe = collective.recipe.template
input = ${buildout:directory}/misc/test-for-bisect
output = ${buildout:directory}/bin/test-for-bisect
mode = 755

[xsltest]
recipe = zc.recipe.egg
eggs = xsltest

[code-analysis]
recipe = plone.recipe.codeanalysis
directory = ${buildout:directory}/pyhwp

# Default is 10
flake8-max-complexity = 30

utf8-header = True

[collect-samples]
recipe = collective.recipe.template
mode = 755
output = ${buildout:bin-directory}/${:_buildout_section_name_}
input =
       inline:
       #!/bin/sh

       set -e

       dir="$1"
       find "$dir" -iname '*.hwp' -print0 | parallel --gnu -0 "${save-sample:output}"

[save-sample]
recipe = collective.recipe.template
mode = 755
output = ${buildout:bin-directory}/${:_buildout_section_name_}
input =
       inline:
       #!/bin/sh

       set -e

       src="$1"

       [ -e "$src" ] || (echo "$src not found"; exit 1)

       ${:abspath}

       version=$(${buildout:bin-directory}/hwp5proc version "$src")
       srcpath=$(abspath "$src")
       sha1sum=$(sha1sum -b "$srcpath" | awk '{ print $1 }')

       echo "$version/$sha1sum $srcpath"

       repo="${buildout:directory}/samples.local"

       blob_dir="${buildout:directory}/samples.local/blob"
       [ -d "$blob_dir" ] || mkdir -p "$blob_dir"

       blob_path="$blob_dir/$sha1sum"
       [ -e "$blob_path" ] || cp "$srcpath" "$blob_path"

       dst_path="$repo/$version/$sha1sum.hwp"
       dst_dir=$(dirname "$dst_path")
       [ -d "$dst_dir" ] || mkdir -p "$dst_dir"
       [ -e $dst_path ] || ln -s "$blob_path" "$dst_path"

abspath=
       abspath() {
              if [ $(echo "$1" | head -c 1) = "/" ]; then
                     echo "$1"
              else
                     echo "$PWD/$1"
              fi
       }

[masstest-failed]
recipe = collective.recipe.template
mode = 755
output = ${buildout:bin-directory}/${:_buildout_section_name_}
input =
       inline:
       #!/bin/sh

       set -e

       ${masstest:output} "${masstest-worker:failed-dir}"

[masstest]
recipe = collective.recipe.template
mode = 755
output = ${buildout:bin-directory}/${:_buildout_section_name_}
input =
       inline:
       #!/bin/sh

       set -e

       ${:def-masstest}

       sample_dir="${buildout:directory}/samples.local/"
       [ -z "$1" ] || sample_dir="$1"

       masstest "$sample_dir" | tee ${buildout:parts-directory}/masstest.log

def-masstest=
       masstest() {
              find "$1" -iname '*.hwp' -print0 | parallel --gnu -0 ${masstest-worker:output}
       }

[masstest-worker]
recipe = collective.recipe.template
mode = 755
output = ${buildout:bin-directory}/${:_buildout_section_name_}
input =
       inline:
       #!/bin/sh

       set -e

       [ -e "$1" ] || (echo "$1: not found"; exit 1)
       testee="$1"

       failed_dir="${:failed-dir}"
       [ -d "$failed_dir" ] || mkdir -p "$failed_dir"

       errors_dir="${:errors-dir}"
       [ -d "$errors_dir" ] || mkdir -p "$errors_dir"

       testee_filename=$(basename "$testee")
       testee_error_hwp5proc="$errors_dir/$testee_filename.hwp5proc.err"
       testee_error_xmllint="$errors_dir/$testee_filename.xmllint.err"

       test_xml() {
              ${buildout:bin-directory}/hwp5proc xml "$testee" 2> "$testee_error_hwp5proc" | xmllint --format - > /dev/null 2> "$testee_error_xmllint"
       }

       handle_success() {
              echo ""
              filename=$(basename "$testee")
              failed_path="$failed_dir/$filename"
              [ ! -e "$failed_path" ] || rm -f "$failed_path"
              rm -f "$testee_error_hwp5proc"
              rm -f "$testee_error_xmllint"
       }

       handle_failed() {
              echo " FAILED"
              [ -e "$failed_path" ] || ln -s "$testee" "$failed_dir"
       }

       echo -n "$testee"
       test_xml && handle_success || handle_failed

failed-dir=${buildout:parts-directory}/masstest/failed
errors-dir=${buildout:parts-directory}/masstest/errors


[massfind-unknowntag]
recipe = collective.recipe.template
output = ${buildout:bin-directory}/${:_buildout_section_name_}
mode = 755
input =
       inline:
       #!/bin/sh

       set -e

       samples='${buildout:directory}/samples.local'
       find "$samples/" -iname '*.hwp' | parallel --gnu ${buildout:bin-directory}/hwp5proc find --model=UnknownTagModel | tee ${buildout:parts-directory}/massfind-unknowntag


[massfind-incomplete]
recipe = collective.recipe.template
output = ${buildout:bin-directory}/${:_buildout_section_name_}
mode = 755
input =
       inline:
       #!/bin/sh

       set -e

       samples='${buildout:directory}/samples.local'
       find "$samples/" -iname '*.hwp' | parallel --gnu ${buildout:bin-directory}/hwp5proc find --incomplete | tee ${buildout:parts-directory}/massfind-incomplete


[expected-output-update]
recipe = collective.recipe.template
output = ${buildout:bin-directory}/${:_buildout_section_name_}
mode = 755
input =
       inline:
       #!/bin/sh

       set -e

       samples='${buildout:directory}/samples'
       find "$samples/" -iname '*.hwp' | parallel --gnu ${expected-output-update-worker:output}

[expected-output-update-worker]
recipe = collective.recipe.template
output = ${buildout:bin-directory}/${:_buildout_section_name_}
mode = 755
input =
       inline:
       #!/bin/sh

       set -e

       filename=$1
       docinfo="$filename.docinfo.json"
       section0="$filename.bodytext.section0.json"
       xmlformat="$filename.formatted.xml"
       odt_output="$filename.odt"
       odt_filename=`basename "$odt_output"`

       hwp5proc_xml() {
              ${buildout:bin-directory}/hwp5proc xml "$1" 2> "$xmlformat.err"
       }

       hwp5odt() {
              local orgdir="$PWD"
              local filename=`basename "$1"`
              local odt_file=`echo $filename | sed -e "s/.hwp$/.odt/g"`
              cd `dirname "$1"`
              ${buildout:bin-directory}/hwp5odt "$filename"
              rm -rf "$odt_file.d"
              mkdir "$odt_file.d"
              unzip "$odt_file" -d "$odt_file.d"
              rm -f "$odt_file"
              cd "$orgdir"
       }

       hwp5html() {
              local html_dir=`echo $1 | sed -e "s/.hwp$/.html.d/g"`
              rm -rf "$html_dir"
              ${buildout:bin-directory}/hwp5html "$1" --output "$html_dir"
              xmllint --c14n --nonet --encode utf-8 "$html_dir/index.xhtml" | xmllint --format --encode utf-8 - > "$html_dir/index.formatted.xhtml"
       }

       xml_c14n() {
              xmllint --c14n --encode utf-8 - 2> "$xmlformat.c14n.err"
       }
       xml_format() {
              xmllint --format --encode utf-8 - 2> "$xmlformat.format.err"
       }

       if ${buildout:bin-directory}/hwp5proc header "$filename" | grep password | grep 0 > /dev/null; then
              dummy=''
       else
              echo "$filename: SKIPPING"
              rm -f "$docinfo.err"
              rm -f "$section0.err"
              rm -f "$xmlformat.err"
              rm -f "$xmlformat.c14n.err"
              rm -f "$xmlformat.format.err"
              exit 0
       fi

       ${buildout:bin-directory}/hwp5proc models "$filename" docinfo > "$docinfo" 2> "$docinfo.err" && echo "$filename: docinfo" && rm -f "$docinfo.err"

       ${buildout:bin-directory}/hwp5proc models "$filename" bodytext/0 > "$section0" 2> "$section0.err" && echo "$filename: bodytext/0" && rm -f "$section0.err"

       hwp5proc_xml "$filename" | xml_c14n | xml_format > "$xmlformat" && echo "$filename: xml" && rm -f "$xmlformat.err" "$xmlformat.c14n.err" "$xmlformat.format.err"
       hwp5odt "$filename"
       hwp5html "$filename"