Project

General

Profile

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 135 aaronmk
test -n "$n" || export n=2
11 53 aaronmk
12 131 aaronmk
. ../util/env_password in_password
13
14
15 106 aaronmk
# Update generated mappings
16
../../mappings/extract_plot_map
17
../../mappings/join_all_vegbank
18 53 aaronmk
19 135 aaronmk
function trace()
20 118 aaronmk
{
21 135 aaronmk
    (
22
        echo -n "$PS4"
23
        for arg in "$@"; do printf "%q " "$arg"; done
24
        echo "${_in+<$_in}" "${_out+>$_out}"
25
    ) >&2
26 118 aaronmk
}
27
28 135 aaronmk
function fromCsv()
29 132 aaronmk
{
30 135 aaronmk
    (_in="$in"; trace)
31
    "$1" <"$in" || exit
32 132 aaronmk
}
33
34 135 aaronmk
function fromDb()
35 118 aaronmk
{
36 135 aaronmk
    trace . "$in"
37
    (. "$in"; "$1") || exit
38
}
39
40
function toXml()
41
{
42 127 aaronmk
    out="$stem.$out_fmt.xml"
43 118 aaronmk
    (set -x; ../map "../../mappings/$src-$out_fmt.$table.csv" >"output/$out"\
44
    && diff "accepted_output/$out" "output/$out")
45
}
46
47 135 aaronmk
function toDb()
48 118 aaronmk
{
49
    (set -x; ../map2vegbank "../../mappings/$src-VegBank.$table.csv")
50
}
51
52
for in in input/*.{csv,sh}; do
53
    ext="${in##*.}" # after last "."
54
    stem="$(basename -- "${in%.*}")" # remove extension and dir
55 106 aaronmk
    src="${stem%.*}" # before last "."
56 118 aaronmk
    table="${stem##*.}" # after last "."
57 106 aaronmk
58
    # Test exporting to XML
59 118 aaronmk
    for out_fmt in VegX VegBank; do
60 135 aaronmk
        if test "$ext" == "csv"; then fromCsv toXml
61
        elif test "$ext" == "sh"; then fromDb toXml
62 118 aaronmk
        fi
63 106 aaronmk
    done
64
65
    # Test exporting to VegBank db
66 135 aaronmk
    if test "$ext" == "csv"; then fromCsv toDb
67
    elif test "$ext" == "sh"; then fromDb toDb
68 118 aaronmk
    fi
69 106 aaronmk
done