1 |
53
|
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 |
118
|
aaronmk
|
shopt -s nullglob
|
9 |
|
|
|
10 |
53
|
aaronmk
|
test -n "$n" || n=2
|
11 |
131
|
aaronmk
|
let n++ # account for header row
|
12 |
53
|
aaronmk
|
|
13 |
131
|
aaronmk
|
. ../util/env_password in_password
|
14 |
|
|
|
15 |
|
|
|
16 |
106
|
aaronmk
|
# Update generated mappings
|
17 |
|
|
../../mappings/extract_plot_map
|
18 |
|
|
../../mappings/join_all_vegbank
|
19 |
53
|
aaronmk
|
|
20 |
118
|
aaronmk
|
function importCsv()
|
21 |
|
|
{
|
22 |
|
|
(set -x; head -"$n" "$in")
|
23 |
|
|
}
|
24 |
|
|
|
25 |
132
|
aaronmk
|
function importDb()
|
26 |
|
|
{
|
27 |
|
|
echo "$PS4. \"$in\"" >&2
|
28 |
|
|
. "$in"
|
29 |
|
|
}
|
30 |
|
|
|
31 |
118
|
aaronmk
|
function exportXml()
|
32 |
|
|
{
|
33 |
127
|
aaronmk
|
out="$stem.$out_fmt.xml"
|
34 |
118
|
aaronmk
|
(set -x; ../map "../../mappings/$src-$out_fmt.$table.csv" >"output/$out"\
|
35 |
|
|
&& diff "accepted_output/$out" "output/$out")
|
36 |
|
|
}
|
37 |
|
|
|
38 |
|
|
function exportDb()
|
39 |
|
|
{
|
40 |
|
|
(set -x; ../map2vegbank "../../mappings/$src-VegBank.$table.csv")
|
41 |
|
|
}
|
42 |
|
|
|
43 |
|
|
for in in input/*.{csv,sh}; do
|
44 |
|
|
ext="${in##*.}" # after last "."
|
45 |
|
|
stem="$(basename -- "${in%.*}")" # remove extension and dir
|
46 |
106
|
aaronmk
|
src="${stem%.*}" # before last "."
|
47 |
118
|
aaronmk
|
table="${stem##*.}" # after last "."
|
48 |
106
|
aaronmk
|
|
49 |
|
|
# Test exporting to XML
|
50 |
118
|
aaronmk
|
for out_fmt in VegX VegBank; do
|
51 |
127
|
aaronmk
|
if test "$ext" == "csv"; then importCsv|exportXml
|
52 |
132
|
aaronmk
|
elif test "$ext" == "sh"; then (importDb; exportXml)
|
53 |
118
|
aaronmk
|
fi
|
54 |
106
|
aaronmk
|
done
|
55 |
|
|
|
56 |
|
|
# Test exporting to VegBank db
|
57 |
127
|
aaronmk
|
if test "$ext" == "csv"; then importCsv|exportDb
|
58 |
132
|
aaronmk
|
elif test "$ext" == "sh"; then (importDb; exportDb)
|
59 |
118
|
aaronmk
|
fi
|
60 |
106
|
aaronmk
|
done
|