Project

General

Profile

1
#!/bin/bash -e
2
# Imports all inputs at once
3

    
4
. "$(dirname "${BASH_SOURCE[0]}")"/../lib/runscripts/util.run "$@"
5

    
6
hidden_srcs()
7
{
8
    local hidden_srcs=1 inputs=() # with_all adds the hidden srcs to @inputs
9
    . "$selfDir/with_all" import "$@"
10
}
11

    
12
delete_logs()
13
{
14
	if test "$delete_logs"; then
15
		(set -x; find . -name "${n:+n=$n.}$version.log.sql" -delete)
16
	fi
17
}
18

    
19
main()
20
{
21
    local self="${BASH_SOURCE[0]}"
22
    local selfDir="$(dirname -- "$self")"
23
    pushd "$selfDir/.."
24
    
25
    if ! test "$SHLVL" -ge 2; then # was run without subshell
26
        # needs subshell so errexits don't close the terminal window
27
        echo 'usage: must be run in a subshell, obtained by running `$0`' >&2
28
        return 0 # not nonzero because this will close the terminal window
29
    fi
30
    if test "${BASH_LINENO[1]}" = 0; then # was run without initial "."
31
        echo "usage: (*in subshell*) [version=...] [inputs=(inputs/src/ ...)]; \
32
. $self [vars...] (note initial \".\")"|fold -s >&2
33
        return 0 # not nonzero because this will close the subshell
34
    fi
35
    : ${version=$(make -s version)}
36
    local by_col=${by_col-1} full_import=1
37
    export version by_col full_import
38
    
39
    if test ! "${log-1}"; then local delete_logs=1; fi #log==''
40
    trap delete_logs SIGINT SIGTERM #not EXIT b/c doesn't run until *shell* exit
41
    
42
    local log=1 # always use log files for background processes
43
    
44
    # remove any leftover TNRS lockfile. usually, the PID in it would not exist,
45
    # but sometimes it now refers to an active process which blocks tnrs.make.
46
    "rm" -f inputs/.TNRS/tnrs/tnrs.make.lock
47
    
48
    make schemas/$version/reinstall
49
    
50
    local hidden_srcs=1; . "$selfDir/with_all" Source/import "$@"
51
        # note that this isn't affected by $import_source
52
    wait # wait for asynchronous commands
53
    unset hidden_srcs
54
    
55
    local import_source= # Source tables have already been imported
56
    export import_source # must come after local
57
    
58
    hidden_srcs "$@" # separate function to avoid overwriting @inputs
59
    wait # wait for asynchronous commands
60
    
61
    . "$selfDir/with_all" import_scrub "$@" # uses $by_col
62
    
63
    local jobs="$(jobs -p)"
64
    echo "import_scrub PIDs: $jobs" >&2
65
    
66
    bin/after_import $jobs &
67
    echo "after_import PID: $!" >&2
68
    
69
    popd
70
    delete_logs # manually run b/c `trap EXIT` doesn't run until *shell* exit
71
}
72

    
73
on_exit
(31-31/87)