Project

General

Profile

1 11823 aaronmk
#!/bin/bash -e
2 1541 aaronmk
# Imports all inputs at once
3 11823 aaronmk
set -o errexit -o pipefail # errexit since may be called from shell
4 1541 aaronmk
5 11422 aaronmk
if test "$1" = .; then set --; fi # was .-included without args, so $@ is wrong
6
7 13978 aaronmk
hidden_srcs()
8
{
9
    local hidden_srcs=1 inputs=() # with_all adds the hidden srcs to @inputs
10
    . "$selfDir/with_all" import by_col=1 "$@"
11
}
12
13 11416 aaronmk
main()
14 1952 aaronmk
{
15
    local self="${BASH_SOURCE[0]}"
16
    local selfDir="$(dirname -- "$self")"
17 11430 aaronmk
    pushd "$selfDir/.."
18 1952 aaronmk
19 1953 aaronmk
    if test "${BASH_LINENO[1]}" = 0; then # was run without initial "."
20 11371 aaronmk
        echo "usage: [version=...] [inputs=(inputs/src/ ...)]; . $self \
21
[vars...] (note initial \".\")"|fold -s >&2
22 1952 aaronmk
        return 2
23
    fi
24 7103 aaronmk
    : ${version=$(make -s version)}
25 10579 aaronmk
    local by_col=${by_col-1} full_import=1
26
    export version by_col full_import
27 1952 aaronmk
28 10847 aaronmk
    # remove any leftover TNRS lockfile. usually, the PID in it would not exist,
29
    # but sometimes it now refers to an active process which blocks tnrs.make.
30 11419 aaronmk
    "rm" -f inputs/.TNRS/tnrs/tnrs.make.lock
31 10847 aaronmk
32 11421 aaronmk
    make schemas/$version/reinstall
33 6946 aaronmk
34 11415 aaronmk
    local hidden_srcs=1; . "$selfDir/with_all" Source/import by_col=1 "$@"
35 6897 aaronmk
        # note that this isn't affected by $import_source
36 6593 aaronmk
    wait # wait for asynchronous commands
37 11374 aaronmk
    unset hidden_srcs
38 6593 aaronmk
39 7095 aaronmk
    local import_source= # Source tables have already been imported
40
    export import_source # must come after local
41 6897 aaronmk
42 13978 aaronmk
    hidden_srcs "$@" # separate function to avoid overwriting @inputs
43 6594 aaronmk
    wait # wait for asynchronous commands
44 5503 aaronmk
45 11286 aaronmk
    . "$selfDir/with_all" import_scrub "$@" # uses $by_col
46 6210 aaronmk
47 7418 aaronmk
    local jobs="$(jobs -p)"
48
    echo "import_scrub PIDs: $jobs" >&2
49
50 10586 aaronmk
    bin/after_import $jobs &
51 7276 aaronmk
    echo "after_import PID: $!" >&2
52 7228 aaronmk
53
    . bin/disown_all
54 11430 aaronmk
55
    popd
56 1952 aaronmk
}
57 11416 aaronmk
main "$@"