Project

General

Profile

« Previous | Next » 

Revision 8774

moved lib/*.run into runscripts/ subdir so runscripts are grouped together and easier to find rather than being scattered throughout lib/

View differences:

lib/table.run
1
#!/bin/bash -e
2

  
3
if false; then #### run script template:
4
#!/bin/bash -e
5
. "$(dirname "${BASH_SOURCE[0]}")"/path/to/table.run
6

  
7
import ()
8
{
9
	echo_func "$@"
10
	before_import_cmds
11
	"$(dirname "${BASH_SOURCE[0]}")"/path/to/table.run "$FUNCNAME" "$@"
12
	after_import_cmds
13
}
14
fi ####
15

  
16
. "$(dirname "${BASH_SOURCE[0]}")"/import.run
17
. "$(dirname "${BASH_SOURCE[0]}")"/local.run
18

  
19
if self_not_included; then
20

  
21
quote='"'
22

  
23
esc_name () { echo "$quote${1//$quote/$quote$quote}$quote"; }
24

  
25
mk_esc_name () { set_var "$1"_esc "$(esc_name "${!1}")"; }
26

  
27
: "${schema="$(cd "$top_dir"/..; basename "$PWD")"}"
28
mk_esc_name schema
29
: "${table="$( cd "$top_dir"   ; basename "$PWD")"}"
30
mk_esc_name table
31
export schema table
32

  
33
mysql ()
34
{
35
	echo_func "$@"
36
	echo_run "$bin_dir"/mysql_bien --database="$schema" --verbose "$@"
37
}
38

  
39
mysql_ANSI ()
40
{
41
	echo_func "$@"
42
	(echo "SET sql_mode = 'ANSI';"; cat)|mysql "$@"
43
}
44

  
45
psql () # usage: ([file=...] [dir=...]; self)
46
{
47
	echo_func "$@"
48
	local dir="$dir"
49
	if test -n "$file"; then
50
		set -- --file "$file" "$@"
51
		: "${dir:=$(dirname "$file")}"
52
	fi
53
	: "${dir:=$top_dir}"
54
	
55
	(cat <<EOF
56
\cd $dir
57
\set schema "$schema"
58
\set table "$table"
59
\set table_str '''"$table"'''
60
SET search_path TO "$schema", util;
61
EOF
62
	cat)|
63
	echo_run env no_search_path=1 "$bin_dir"/psql_verbose_vegbien "$@"
64
}
65

  
66
input_make ()
67
{
68
	echo_func "$@"
69
	echo_run env make --directory="$top_dir"/.. "${@/#/$table/}"
70
}
71

  
72
map_table ()
73
{
74
	echo_func "$@"
75
	input_make map.csv
76
	psql <<EOF
77
SELECT util.reset_map_table('pg_temp.map');
78
\copy pg_temp.map FROM 'map.csv' CSV HEADER;
79
SELECT util.set_col_names('"$table"', 'pg_temp.map'::regclass);
80
EOF
81
}
82

  
83
mk_derived ()
84
{
85
	echo_func "$@"
86
	"$root_dir"/schemas/VegCore/mk_derived
87
}
88

  
89
remake_VegBIEN_mappings ()
90
{
91
	echo_func "$@"
92
	echo_run rm header.csv map.csv # remake them
93
	yes|input_make test
94
}
95

  
96
postprocess () # overridable
97
{
98
	echo_func "$@"
99
	local file="$top_dir"/postprocess.sql
100
	if test -e "$file"; then psql "$@"; fi
101
}
102

  
103
import ()
104
{
105
	echo_func "$@"
106
	map_table
107
	postprocess
108
	mk_derived
109
}
110

  
111
fi
112 0

  
lib/util.run
1
#!/bin/bash -e
2
# runscripts: a bash-based replacement for make
3
# unlike make, supports full bash functionality including multiline commands
4
# usage: path/to/dir/run cmd args
5

  
6
if false; then #### run script template:
7
#!/bin/bash -e
8
. "$(dirname "${BASH_SOURCE[0]}")"/path/to/util.run or file_including_util.run
9
. "$(dirname "${BASH_SOURCE[0]}")"/other_includes
10

  
11
cmd ()
12
{
13
	echo_func "$@"
14
	"$(dirname "${BASH_SOURCE[0]}")"/path_relative_to_self
15
	"$(dirname "${BASH_SOURCE[1]}")"/path_relative_to_caller
16
	"$top_dir"/path_relative_to_outermost_script
17
}
18
fi ####
19

  
20
: "${verbosity=2}"
21

  
22
. "$(dirname "${BASH_SOURCE[0]}")"/util.sh
23

  
24
if self_not_included; then
25

  
26
# users can override this function to perform other commands (or no commands)
27
# after the script is read
28
on_exit () { run_args_cmd; }
29
trap on_exit EXIT
30

  
31
fi
32 0

  
lib/import.run
1
#!/bin/bash -e
2

  
3
if false; then #### run script template:
4
#!/bin/bash -e
5
. "$(dirname "${BASH_SOURCE[0]}")"/path/to/import.run
6

  
7
import ()
8
{
9
	echo_func "$@"
10
	import_cmds
11
}
12
fi ####
13

  
14
. "$(dirname "${BASH_SOURCE[0]}")"/util.run
15

  
16
if self_not_included; then
17

  
18
import ()
19
{
20
	echo_func "$@"
21
}
22

  
23
all ()
24
{
25
	echo_func "$@"
26
	import
27
}
28

  
29
fi
30 0

  
lib/local.run
1
#!/bin/bash -e
2
# links to locally-available resources
3
. "$(dirname "${BASH_SOURCE[0]}")"/util.run
4

  
5
if self_not_included; then
6

  
7
root_dir="$(dirname "${BASH_SOURCE[0]}")"/..
8
bin_dir="$root_dir"/bin
9

  
10
export PATH="$bin_dir:$PATH"
11

  
12
fi
13 0

  
inputs/GBIF/table.run
1 1
#!/bin/bash -e
2
. "$(dirname "${BASH_SOURCE[0]}")"/../../lib/table.run
2
. "$(dirname "${BASH_SOURCE[0]}")"/../../lib/runscripts/table.run
3 3

  
4 4
if self_not_included; then
5 5

  
......
16 16
{
17 17
	echo_func "$@"
18 18
	MySQL_export
19
	"$(dirname "${BASH_SOURCE[0]}")"/../../lib/table.run "$FUNCNAME" "$@"
19
	"$(dirname "${BASH_SOURCE[0]}")"/../../lib/runscripts/table.run "$FUNCNAME" "$@"
20 20
}
21 21

  
22 22
fi
inputs/GBIF/_MySQL/run
1 1
#!/bin/bash -e
2
. "$(dirname "${BASH_SOURCE[0]}")"/../../../lib/import.run
2
. "$(dirname "${BASH_SOURCE[0]}")"/../../../lib/runscripts/import.run
3 3

  
4 4
if self_not_included; then
5 5

  
inputs/GBIF/run
1 1
#!/bin/bash -e
2
. "$(dirname "${BASH_SOURCE[0]}")"/../../lib/import.run
2
. "$(dirname "${BASH_SOURCE[0]}")"/../../lib/runscripts/import.run
3 3

  
4 4
if self_not_included; then
5 5

  
schemas/VegCore/VegCore.ERD.mwb.run
1 1
#!/bin/bash -e
2 2
# syncs VegCore.ERD.mwb's zip file contents
3
. "$(dirname "${BASH_SOURCE[0]}")"/../../lib/util.run
3
. "$(dirname "${BASH_SOURCE[0]}")"/../../lib/runscripts/util.run
4 4

  
5 5
if self_not_included; then
6 6

  
lib/runscripts/util.run
1
#!/bin/bash -e
2
# runscripts: a bash-based replacement for make
3
# unlike make, supports full bash functionality including multiline commands
4
# usage: path/to/dir/run cmd args
5

  
6
if false; then #### run script template:
7
#!/bin/bash -e
8
. "$(dirname "${BASH_SOURCE[0]}")"/path/to/util.run or file_including_util.run
9
. "$(dirname "${BASH_SOURCE[0]}")"/other_includes
10

  
11
cmd ()
12
{
13
	echo_func "$@"
14
	"$(dirname "${BASH_SOURCE[0]}")"/path_relative_to_self
15
	"$(dirname "${BASH_SOURCE[1]}")"/path_relative_to_caller
16
	"$top_dir"/path_relative_to_outermost_script
17
}
18
fi ####
19

  
20
: "${verbosity=2}"
21

  
22
. "$(dirname "${BASH_SOURCE[0]}")"/../util.sh
23

  
24
if self_not_included; then
25

  
26
# users can override this function to perform other commands (or no commands)
27
# after the script is read
28
on_exit () { run_args_cmd; }
29
trap on_exit EXIT
30

  
31
fi
0 32

  
lib/runscripts/table.run
1
#!/bin/bash -e
2

  
3
if false; then #### run script template:
4
#!/bin/bash -e
5
. "$(dirname "${BASH_SOURCE[0]}")"/path/to/table.run
6

  
7
import ()
8
{
9
	echo_func "$@"
10
	before_import_cmds
11
	"$(dirname "${BASH_SOURCE[0]}")"/path/to/table.run "$FUNCNAME" "$@"
12
	after_import_cmds
13
}
14
fi ####
15

  
16
. "$(dirname "${BASH_SOURCE[0]}")"/import.run
17
. "$(dirname "${BASH_SOURCE[0]}")"/local.run
18

  
19
if self_not_included; then
20

  
21
quote='"'
22

  
23
esc_name () { echo "$quote${1//$quote/$quote$quote}$quote"; }
24

  
25
mk_esc_name () { set_var "$1"_esc "$(esc_name "${!1}")"; }
26

  
27
: "${schema="$(cd "$top_dir"/..; basename "$PWD")"}"
28
mk_esc_name schema
29
: "${table="$( cd "$top_dir"   ; basename "$PWD")"}"
30
mk_esc_name table
31
export schema table
32

  
33
mysql ()
34
{
35
	echo_func "$@"
36
	echo_run "$bin_dir"/mysql_bien --database="$schema" --verbose "$@"
37
}
38

  
39
mysql_ANSI ()
40
{
41
	echo_func "$@"
42
	(echo "SET sql_mode = 'ANSI';"; cat)|mysql "$@"
43
}
44

  
45
psql () # usage: ([file=...] [dir=...]; self)
46
{
47
	echo_func "$@"
48
	local dir="$dir"
49
	if test -n "$file"; then
50
		set -- --file "$file" "$@"
51
		: "${dir:=$(dirname "$file")}"
52
	fi
53
	: "${dir:=$top_dir}"
54
	
55
	(cat <<EOF
56
\cd $dir
57
\set schema "$schema"
58
\set table "$table"
59
\set table_str '''"$table"'''
60
SET search_path TO "$schema", util;
61
EOF
62
	cat)|
63
	echo_run env no_search_path=1 "$bin_dir"/psql_verbose_vegbien "$@"
64
}
65

  
66
input_make ()
67
{
68
	echo_func "$@"
69
	echo_run env make --directory="$top_dir"/.. "${@/#/$table/}"
70
}
71

  
72
map_table ()
73
{
74
	echo_func "$@"
75
	input_make map.csv
76
	psql <<EOF
77
SELECT util.reset_map_table('pg_temp.map');
78
\copy pg_temp.map FROM 'map.csv' CSV HEADER;
79
SELECT util.set_col_names('"$table"', 'pg_temp.map'::regclass);
80
EOF
81
}
82

  
83
mk_derived ()
84
{
85
	echo_func "$@"
86
	"$root_dir"/schemas/VegCore/mk_derived
87
}
88

  
89
remake_VegBIEN_mappings ()
90
{
91
	echo_func "$@"
92
	echo_run rm header.csv map.csv # remake them
93
	yes|input_make test
94
}
95

  
96
postprocess () # overridable
97
{
98
	echo_func "$@"
99
	local file="$top_dir"/postprocess.sql
100
	if test -e "$file"; then psql "$@"; fi
101
}
102

  
103
import ()
104
{
105
	echo_func "$@"
106
	map_table
107
	postprocess
108
	mk_derived
109
}
110

  
111
fi
0 112

  
lib/runscripts/import.run
1
#!/bin/bash -e
2

  
3
if false; then #### run script template:
4
#!/bin/bash -e
5
. "$(dirname "${BASH_SOURCE[0]}")"/path/to/import.run
6

  
7
import ()
8
{
9
	echo_func "$@"
10
	import_cmds
11
}
12
fi ####
13

  
14
. "$(dirname "${BASH_SOURCE[0]}")"/util.run
15

  
16
if self_not_included; then
17

  
18
import ()
19
{
20
	echo_func "$@"
21
}
22

  
23
all ()
24
{
25
	echo_func "$@"
26
	import
27
}
28

  
29
fi
0 30

  
lib/runscripts/local.run
1
#!/bin/bash -e
2
# links to locally-available resources
3
. "$(dirname "${BASH_SOURCE[0]}")"/util.run
4

  
5
if self_not_included; then
6

  
7
root_dir="$(dirname "${BASH_SOURCE[0]}")"/../..
8
bin_dir="$root_dir"/bin
9

  
10
export PATH="$bin_dir:$PATH"
11

  
12
fi
0 13

  
web/links/index.htm.run
1 1
#!/bin/bash -e
2 2
# reformats index.htm for display
3
. "$(dirname "${BASH_SOURCE[0]}")"/../../lib/local.run
3
. "$(dirname "${BASH_SOURCE[0]}")"/../../lib/runscripts/local.run
4 4

  
5 5
if self_not_included; then
6 6

  

Also available in: Unified diff