1 |
183
|
aaronmk
|
#!/bin/bash
|
2 |
106
|
aaronmk
|
# Tests map on all input/*.csv
|
3 |
|
|
# Usage: env [n=<num-rows>] self
|
4 |
53
|
aaronmk
|
|
5 |
|
|
selfDir="$(dirname -- "$0")"
|
6 |
|
|
cd "$selfDir"
|
7 |
|
|
|
8 |
183
|
aaronmk
|
shopt -s nullglob
|
9 |
|
|
|
10 |
175
|
aaronmk
|
tests_n=2
|
11 |
181
|
aaronmk
|
testMode=
|
12 |
|
|
test -n "$n" || export n="$tests_n" testMode=1
|
13 |
175
|
aaronmk
|
|
14 |
252
|
aaronmk
|
test "$(hostname)" = nimoy && isNimoy=t || isNimoy=
|
15 |
274
|
aaronmk
|
test -n "$isNimoy" && . ../bin/env_password mysql_password "your MySQL"
|
16 |
252
|
aaronmk
|
|
17 |
272
|
aaronmk
|
bien_password="$(cat ../config/bien_password)"
|
18 |
131
|
aaronmk
|
|
19 |
268
|
aaronmk
|
make --directory=../mappings
|
20 |
185
|
aaronmk
|
mkdir -p output
|
21 |
|
|
|
22 |
135
|
aaronmk
|
function trace()
|
23 |
118
|
aaronmk
|
{
|
24 |
135
|
aaronmk
|
(
|
25 |
181
|
aaronmk
|
env echo -n "$PS4" # bug in sh's built-in echo prints the -n
|
26 |
135
|
aaronmk
|
for arg in "$@"; do printf "%q " "$arg"; done
|
27 |
|
|
echo "${_in+<$_in}" "${_out+>$_out}"
|
28 |
|
|
) >&2
|
29 |
118
|
aaronmk
|
}
|
30 |
|
|
|
31 |
319
|
aaronmk
|
function fromFile()
|
32 |
|
|
{
|
33 |
|
|
(_in="$in"; trace)
|
34 |
|
|
("$@" <"$in") || exit # run in a sandbox; abort tester if error
|
35 |
|
|
}
|
36 |
|
|
|
37 |
161
|
aaronmk
|
function map()
|
38 |
132
|
aaronmk
|
{
|
39 |
169
|
aaronmk
|
test -e "$in" || return 1
|
40 |
|
|
local ext="${in##*.}" # after last "."
|
41 |
319
|
aaronmk
|
(for map in "../mappings/$src-$out_fmt."$table".csv"; do
|
42 |
169
|
aaronmk
|
table="${map%.*}" # remove extension
|
43 |
|
|
table="${table##*.}" # after last "."
|
44 |
252
|
aaronmk
|
{
|
45 |
161
|
aaronmk
|
if test "$ext" == "sh"; then
|
46 |
|
|
trace . "$in"
|
47 |
252
|
aaronmk
|
(
|
48 |
|
|
. "$in"
|
49 |
257
|
aaronmk
|
|
50 |
|
|
# defaults
|
51 |
|
|
test -n "$host" || host=localhost
|
52 |
|
|
if test -z "$user"; then
|
53 |
|
|
if test -n "$isNimoy" -a "$engine" = MySQL; then
|
54 |
|
|
user="$USER" password="$mysql_password"
|
55 |
|
|
else
|
56 |
|
|
user=bien password="$bien_password"
|
57 |
|
|
fi
|
58 |
252
|
aaronmk
|
fi
|
59 |
257
|
aaronmk
|
|
60 |
|
|
for var in engine host user password database; do
|
61 |
|
|
export in_$var="${!var}"
|
62 |
|
|
done
|
63 |
319
|
aaronmk
|
"$@"
|
64 |
252
|
aaronmk
|
)
|
65 |
319
|
aaronmk
|
else fromFile "$@"
|
66 |
161
|
aaronmk
|
fi
|
67 |
319
|
aaronmk
|
} || exit
|
68 |
|
|
done) || exit # run in a sandbox; abort tester if error
|
69 |
132
|
aaronmk
|
}
|
70 |
|
|
|
71 |
135
|
aaronmk
|
function toXml()
|
72 |
|
|
{
|
73 |
169
|
aaronmk
|
local stem="$orig_src.$table.$out_fmt"
|
74 |
|
|
local out="output/$stem${method+.$method}.xml"
|
75 |
|
|
local accepted="accepted_output/$stem.xml"
|
76 |
267
|
aaronmk
|
(set -x; ../map "$map" >"$out") || exit # abort tester
|
77 |
181
|
aaronmk
|
(set -x; ${testMode:+diff "$accepted" "$out"})
|
78 |
175
|
aaronmk
|
true # ignore last command's exit status
|
79 |
118
|
aaronmk
|
}
|
80 |
|
|
|
81 |
274
|
aaronmk
|
vegbienDest=../bin/vegbien_dest
|
82 |
222
|
aaronmk
|
|
83 |
135
|
aaronmk
|
function toDb()
|
84 |
118
|
aaronmk
|
{
|
85 |
222
|
aaronmk
|
trace . "$vegbienDest"
|
86 |
319
|
aaronmk
|
(. "$vegbienDest"; set -x; ../map ${map:+"$map"}) || exit # abort tester
|
87 |
118
|
aaronmk
|
}
|
88 |
|
|
|
89 |
161
|
aaronmk
|
for in in input/*; do
|
90 |
118
|
aaronmk
|
stem="$(basename -- "${in%.*}")" # remove extension and dir
|
91 |
169
|
aaronmk
|
ext="${in##*.}" # after last "."
|
92 |
|
|
src="${stem%.*}" # before last ".", if any
|
93 |
|
|
orig_src="$src"
|
94 |
|
|
if test "$ext" == "sh"; then table="*" # use all tables with a mapping
|
95 |
|
|
else table="${stem##*.}" # after last "."
|
96 |
|
|
fi
|
97 |
106
|
aaronmk
|
|
98 |
319
|
aaronmk
|
for out_fmt in VegX VegBIEN; do map toXml; done # source to XMLs
|
99 |
|
|
|
100 |
222
|
aaronmk
|
out_fmt=VegBIEN
|
101 |
319
|
aaronmk
|
# VegX to VegBIEN XML
|
102 |
169
|
aaronmk
|
(
|
103 |
|
|
src=VegX method=via_$src
|
104 |
|
|
for in in "output/$orig_src."$table".$src.xml"; do
|
105 |
|
|
table="${in#*.}" # after first "."
|
106 |
|
|
table="${table%%.*}" # before second "."
|
107 |
|
|
map toXml
|
108 |
|
|
done
|
109 |
319
|
aaronmk
|
) || exit
|
110 |
|
|
|
111 |
222
|
aaronmk
|
map toDb # source to VegBIEN db
|
112 |
319
|
aaronmk
|
# VegBIEN XML to VegBIEN db
|
113 |
|
|
for in in "output/$orig_src."$table".VegBIEN"*".xml"; do fromFile toDb; done
|
114 |
106
|
aaronmk
|
done
|