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 136 aaronmk
    (
44
        set -x
45
        ../map "../../mappings/$src-$out_fmt.$table.csv" >"output/$out" || exit
46
        diff "accepted_output/$out" "output/$out" || true
47
    )
48 118 aaronmk
}
49
50 135 aaronmk
function toDb()
51 118 aaronmk
{
52
    (set -x; ../map2vegbank "../../mappings/$src-VegBank.$table.csv")
53
}
54
55
for in in input/*.{csv,sh}; do
56
    ext="${in##*.}" # after last "."
57
    stem="$(basename -- "${in%.*}")" # remove extension and dir
58 106 aaronmk
    src="${stem%.*}" # before last "."
59 118 aaronmk
    table="${stem##*.}" # after last "."
60 106 aaronmk
61
    # Test exporting to XML
62 118 aaronmk
    for out_fmt in VegX VegBank; do
63 135 aaronmk
        if test "$ext" == "csv"; then fromCsv toXml
64
        elif test "$ext" == "sh"; then fromDb toXml
65 118 aaronmk
        fi
66 106 aaronmk
    done
67
68
    # Test exporting to VegBank db
69 135 aaronmk
    if test "$ext" == "csv"; then fromCsv toDb
70
    elif test "$ext" == "sh"; then fromDb toDb
71 118 aaronmk
    fi
72 106 aaronmk
done