Skip to content

Commit 7b7187f

Browse files
committed
Remove requirement to log in via eXide
- in post-install.xql, apply chmod & setuid so that the xquery files can be run as dba without needing to establish a session in eXide or monex - add timing and logging to the calibre step - switch sample to a volume with document number-based cross references, as page-number based cross references take much longer to generate - increment version to 0.5
1 parent bfc5cff commit 7b7187f

5 files changed

+69
-39
lines changed

build.properties.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<name>release</name>
55
<url>http://history.state.gov/ns/apps/release</url>
66
<title>Release</title>
7-
<version>0.4</version>
7+
<version>0.5.0</version>
88
</app>
99
<trigger>
1010
<provider-url>

ebook-batch.xq

+39-11
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ declare function local:output-directory() {
1919
};
2020

2121
declare function local:generate-mobis() {
22+
let $log := console:log('starting conversion of mobi-bound epubs to mobi by calling calibre ebook-convert script')
23+
let $start-time := util:system-time()
2224
let $script := '# enter the source directory
2325
2426
cd mobi-bound;
@@ -36,11 +38,40 @@ mv *.mobi ../mobi/;'
3638
<option>
3739
<workingDir>{local:output-directory()}</workingDir>
3840
</option>
39-
let $execute := process:execute(("sh", "./convert-mobis.sh"), $options)
40-
let $output := $execute/stdout/line
41-
let $newline := '&#10;'
41+
let $execute := try { process:execute(("sh", "./convert-mobis.sh"), $options) } catch * { <error>Error {$err:code} raised when running convert-mobis.sh: {$err:description}</error> }
42+
let $log := console:log('finished calibre ebook-convert script')
43+
let $end-time := util:system-time()
44+
let $duration := $end-time - $start-time
45+
let $minutes := minutes-from-duration($duration)
46+
let $seconds := seconds-from-duration($duration)
4247
return
43-
<pre>{string-join($output, $newline)}</pre>
48+
if ($execute instance of element(execution)) then
49+
if ($execute/@exitCode eq "0") then
50+
(
51+
<p class="bg-success">{
52+
concat('Completed conversion of mobi-bound epub(s) in ', if ($minutes gt 0) then concat($minutes, ' minutes, ') else (), $seconds, ' seconds.')
53+
}</p>,
54+
<pre>{
55+
let $output := $execute/stdout/line
56+
let $newline := '&#10;'
57+
return
58+
string-join($output, $newline)
59+
}</pre>
60+
)
61+
else
62+
(
63+
<p class="bg-danger">{
64+
concat('Conversion of mobi-bound epub(s) to mobi failed after ', if ($minutes gt 0) then concat($minutes, ' minutes, ') else (), $seconds, ' seconds.')
65+
}</p>,
66+
<pre>{
67+
let $output := $execute/stdout/line
68+
let $newline := '&#10;'
69+
return
70+
string-join($output, $newline)
71+
}</pre>
72+
)
73+
else (: if ($execute instance of element(error)) :)
74+
<p class="bg-danger">{$execute/string()}</p>
4475
};
4576

4677
declare function local:generate-ebooks($vol-ids, $format) {
@@ -146,14 +177,11 @@ let $titles := ('Release', 'Ebook Batch Helper')
146177
let $new-volumes := request:get-parameter('volumes', ())
147178
let $format := request:get-parameter('format', 'all')
148179
let $output-directory := local:output-directory()
149-
let $login := xmldb:login('/db', 'admin', '') (: TODO: hook in proper login form :)
150180
let $body :=
151181
<div>
152182
<h2>{$titles[2]}</h2>
153183
{
154-
if (not(sm:is-dba(sm:id()/sm:id/sm:real/sm:username/string()))) then
155-
<p class="bg-danger">This resource is limited to admin users. Please log in first via <a href="/exist/apps/eXide">eXide</a>.</p>
156-
else if ($new-volumes) then
184+
if (exists($new-volumes)) then
157185
(
158186
local:form($new-volumes, $format)
159187
,
@@ -191,9 +219,9 @@ let $body :=
191219
else
192220
(
193221
local:form((), $format),
194-
<p>Please enter volume IDs, one per line. (Click <a href="?volumes=frus1949v01&amp;format=epub">here</a> to try generating frus1949v01 as an epub.)</p>,
195-
<p>Before generating Mobi-bound EPUBs, make sure you have installed <a href="http://calibre-ebook.com/download">Calibre</a>.</p>,
196-
<p>Generating an ebook can take as much as 5-10 minutes each. Open the Monex <a href="/exist/apps/monex/console.html">Console</a> to follow status updates. If an ebook job is taking too long to generate, you can kill the entire query via the Monex <a href="/apps/monex/index.html">Monitoring</a> tab, under "Running Queries."</p>,
222+
<p>Please enter volume IDs, one per line. (Click <a href="?volumes=frus1969-76v18&amp;format=epub">here</a> to try generating frus1969-76v18 as an epub.)</p>,
223+
<p>Before generating Mobi-bound EPUBs, make sure you have installed <a href="https://calibre-ebook.com/download">Calibre</a>.</p>,
224+
<p>Generating an ebook can take as much as 5-10 minutes each (or even longer for volumes with page-number-based back-of-book indexes). Open the Monex <a href="/exist/apps/monex/console.html">Console</a> to follow status updates. If an ebook job is taking too long to generate, you can kill the entire query via the Monex <a href="/apps/monex/index.html">Monitoring</a> tab, under "Running Queries."</p>,
197225
<p>Ebooks are saved on your hard disk at: <code>{$output-directory}</code>.</p>
198226
)
199227
}

post-install.xql

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1-
xquery version "1.0";
1+
xquery version "3.1";
22

3-
import module namespace xdb="http://exist-db.org/xquery/xmldb";
3+
import module namespace xmldb="http://exist-db.org/xquery/xmldb";
44

55
(: the target collection into which the app is deployed :)
66
declare variable $target external;
77

8-
xdb:create-collection($target, 'epub-cache')
8+
xmldb:create-collection($target, 'epub-cache'),
9+
sm:chown(xs:anyURI($target || "/ebook-batch.xq"), "admin"),
10+
sm:chmod(xs:anyURI($target || "/ebook-batch.xq"), "rwsr-xr-x"),
11+
sm:chown(xs:anyURI($target || "/public-diplomacy-to-fo-disk.xq"), "admin"),
12+
sm:chmod(xs:anyURI($target || "/public-diplomacy-to-fo-disk.xq"), "rwsr-xr-x"),
13+
sm:chown(xs:anyURI($target || "/s3-cache.xq"), "admin"),
14+
sm:chmod(xs:anyURI($target || "/s3-cache.xq"), "rwsr-xr-x")

public-diplomacy-to-fo-disk.xq

+20-23
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,25 @@ let $fo := t2f:public-diplomacy-to-fo($vol-path, $div-id, $output-type, $rendere
1010
let $fo-filename := concat('public-diplomacy', if ($div-id) then concat('_', $div-id) else (), '.fo')
1111
let $file-system-output-dir := '/Users/joe/workspace/hsg-project/repos/release/'
1212
let $fo-dir := concat($file-system-output-dir, 'output/')
13+
let $mkdir := if (file:exists($fo-dir)) then () else file:mkdir($fo-dir)
1314
return
14-
system:as-user('admin', '',
15-
let $mkdir := if (file:exists($fo-dir)) then () else file:mkdir($fo-dir)
15+
try {
16+
let $attempt :=
17+
file:serialize(
18+
$fo,
19+
<x>{concat($fo-dir, $fo-filename)}</x>,
20+
'indent=no'
21+
)
1622
return
17-
try {
18-
let $attempt :=
19-
file:serialize(
20-
$fo,
21-
<x>{concat($fo-dir, $fo-filename)}</x>,
22-
'indent=no'
23-
)
24-
return
25-
<ok/>
26-
}
27-
catch * {
28-
let $log-message :=
29-
concat('TEI-to-FO: Error while generating pdf version of public-diplomacy: ',
30-
$err:code, $err:value, " module: ",
31-
$err:module, "(", $err:line-number, ",", $err:column-number, ")"
32-
)
33-
let $log := util:log('INFO', $log-message)
34-
return
35-
<error>{$log-message}</error>
36-
}
37-
)
23+
<ok/>
24+
}
25+
catch * {
26+
let $log-message :=
27+
concat('TEI-to-FO: Error while generating pdf version of public-diplomacy: ',
28+
$err:code, $err:value, " module: ",
29+
$err:module, "(", $err:line-number, ",", $err:column-number, ")"
30+
)
31+
let $log := util:log('INFO', $log-message)
32+
return
33+
<error>{$log-message}</error>
34+
}

s3-cache.xq

-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ declare function local:validate($vol-ids as xs:string*) {
116116
else $vol-id
117117
};
118118

119-
let $login := xmldb:login('/db', 'admin', '') (: TODO: hook in proper login form :)
120119
let $titles := ('Release', 'S3 Cache Helper')
121120
let $new-volumes := request:get-parameter('volumes', ())
122121
let $body :=

0 commit comments

Comments
 (0)