Project

General

Profile

1
#!/bin/bash -e
2
# Imports all inputs at once
3
set -o errexit -o pipefail # errexit since may be called from shell
4

    
5
if test "$1" = .; then set --; fi # was .-included without args, so $@ is wrong
6

    
7
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
main()
14
{
15
    local self="${BASH_SOURCE[0]}"
16
    local selfDir="$(dirname -- "$self")"
17
    pushd "$selfDir/.."
18
    
19
    if test "${BASH_LINENO[1]}" = 0; then # was run without initial "."
20
        echo "usage: [version=...] [inputs=(inputs/src/ ...)]; . $self \
21
[vars...] (note initial \".\")"|fold -s >&2
22
        return 2
23
    fi
24
    : ${version=$(make -s version)}
25
    local by_col=${by_col-1} full_import=1
26
    export version by_col full_import
27
    
28
    local log=1 # always use log files for background processes
29
    
30
    # remove any leftover TNRS lockfile. usually, the PID in it would not exist,
31
    # but sometimes it now refers to an active process which blocks tnrs.make.
32
    "rm" -f inputs/.TNRS/tnrs/tnrs.make.lock
33
    
34
    make schemas/$version/reinstall
35
    
36
    local hidden_srcs=1; . "$selfDir/with_all" Source/import "$@"
37
        # note that this isn't affected by $import_source
38
    wait # wait for asynchronous commands
39
    unset hidden_srcs
40
    
41
    local import_source= # Source tables have already been imported
42
    export import_source # must come after local
43
    
44
    hidden_srcs "$@" # separate function to avoid overwriting @inputs
45
    wait # wait for asynchronous commands
46
    
47
    . "$selfDir/with_all" import_scrub "$@" # uses $by_col
48
    
49
    local jobs="$(jobs -p)"
50
    echo "import_scrub PIDs: $jobs" >&2
51
    
52
    bin/after_import $jobs &
53
    echo "after_import PID: $!" >&2
54
    
55
    . bin/disown_all
56
    
57
    popd
58
}
59
main "$@"
(31-31/86)