Project

General

Profile

« Previous | Next » 

Revision 772

input.Makefile: Added import support for CSV and XML inputs (no test support yet)

View differences:

input.Makefile
21 21
tablesSort ?= plots organisms stems
22 22
coreMapTry ?= organisms specimens
23 23

  
24
+maps = $(filter maps/%,$(+_))
25
+in = $(filter-out maps/%,$(+_))
26

  
27 24
root := $(selfDir_uZPPqC)..
28 25
psqlAsBien := $(root)/bin/psql_vegbien
29 26

  
......
66 63
$(coreMapTry:%=$(root)/mappings/$(via)-VegBIEN.%.csv)))
67 64
viaMaps := $(wildcard $(tablesSort:%=maps/$(via).%.csv))
68 65
viaMaps += $(filter-out $(viaMaps),$(wildcard maps/$(via).*.csv))
69
tables := $(viaMaps:maps/$(via).%.csv=%)
70 66
autogenMaps := $(subst $(via).,VegBIEN.,$(viaMaps))
71 67
directMaps := $(autogenMaps) $(filter-out $(autogenMaps),\
72 68
$(wildcard maps/VegBIEN.*.csv))
69
tables := $(directMaps:maps/VegBIEN.%.csv=%)
73 70

  
74 71
maps: $(directMaps) _always ;
75 72

  
......
84 81
#####
85 82

  
86 83
dbFile := $(firstword $(wildcard src/db.*.sql))
84
inputFiles := $(wildcard src/*.csv src/*.xml)
87 85

  
88
ifneq ($(wildcard $(dbFile)),)
86
+maps = $(filter maps/%,$(+_))
87
<in = $(firstword $(wildcard $(patsubst %,src/*.$*.%,csv xml)) \
88
$(filter-out $(+maps),$(+_)))
89
map = $(if $(mapEnv),env $(mapEnv) ,)$(root)/map $(if $(<in),<$(<in)) $(+maps)
90
map2db = env out_database=vegbien $(map)
89 91

  
92
#####
93

  
94
ifneq ($(dbFile)$(inputFiles),)
95

  
90 96
import: _always import-all verify ;
91 97

  
92 98
log = $(@:-all=)$(if $(n),.n=$(n),).log
93
import = -(set -x; "time" env commit=1 $(map2db) $(+_)) \
99
import = -(set -x; "time" env commit=1 $(map2db)) \
94 100
$(if $(n),,>>$(log)) 2>&1$(if $(n),|tee -a $(log))
95 101
# ignore import errors, which are often benign (e.g. invalid date format)
96 102

  
103
ifneq ($(inputFiles),)
104
import-all: $(addprefix import-,$(tables)) _always ;
105
else
97 106
import-all: $(directMaps) _always
98 107
	$(import)
108
endif
99 109

  
100 110
import-%: maps/VegBIEN.%.csv _always
101 111
	$(import)
112
# default:
113
import-%: _always ;
102 114

  
115
else
116
import: _always ;
117
endif
118

  
103 119
logs := $(wildcard *.log)
104 120

  
105 121
rm_logs: _always
106 122
	$(RM) $(logs)
107 123

  
108
else
109
import: _always ;
110
import-%: _always ;
111
rm_logs: _always ;
112
endif
113

  
114 124
#####
115 125

  
116 126
ifneq ($(wildcard verify.ref*),)
......
123 133
%.out: %.sql _always
124 134
	$(out_cmd)
125 135
.PRECIOUS: %.out
126
out_cmd = $(psqlAsBien) --no-align --field-separator='	' --pset=footer=off \
136
out_cmd = $(psqlAsBien) --no-align --field-separator='	' --pset=footer=off\
127 137
--pset=null=NULL <$< >$@
128 138

  
129 139
else
......
140 150
testRef = $(1:.2-step.xml=.xml).ref
141 151

  
142 152
define test
143
env test=1 verbose=1 n=$(test_n) $(1) $(if $(+in),<$(+in)) $(+maps) >$@
153
env test=1 verbose=1 n=$(test_n) $(1) >$@
144 154
@(set -x; $(DIFF) $(call testRef,$@) $@) 2>&1 || { e=$$?;\
145 155
$(if $(hasOwnRef),echo $(emph)"To accept new test output:"$(endEmph);\
146 156
echo "$(MAKE) $@-ok --directory=$(realpath .) --makefile=../input.Makefile";)\
......
233 243
####
234 244

  
235 245
else
236
mapEnv :=
237 246
install: _always ;
238 247
uninstall: _always ;
239 248
endif
240

  
241
#####
242

  
243
# Must come after mapEnv is set
244
map := $(if $(mapEnv),env $(mapEnv) ,)$(root)/map
245
map2db := env out_database=vegbien $(map)

Also available in: Unified diff