-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocess_sources
More file actions
executable file
·54 lines (41 loc) · 1.46 KB
/
process_sources
File metadata and controls
executable file
·54 lines (41 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/bash
source ./config
SOURCEDIR="sources"
DESTDIR="processed"
# awk program to substitute environment variables
AWKFILTER='{while(match($0,"[$]{[^}]*}")){var=substr($0,RSTART+2,RLENGTH-3);gsub("[$]{"var"}",ENVIRON[var])}}1'
# grep filter to remove millstone junk
# see carto issue #212:
# https://github.com/mapbox/carto/issues/212
MILLSTONEFILTER="\[millstone\]"
# "macros" used in carto templates:
export DBSETTINGS='
"type": "postgis",
"host": "${DB_HOST}",
"dbname": "${DB_NAME}",
"user": "${DB_USER}",
"extent": "${EXTENTS_MERCATOR}"'
mkdir -pv "$DESTDIR"
# Generate Mapnik XML from Carto templates
for SRC in `ls ${SOURCEDIR}/*.mml`; do
echo -n "Processing $SRC... "
DST="${DESTDIR}/`basename $SRC .mml`.xml"
# use an intermediate temp file since carto can't read
# from stdin, and we need to run the awk filter *before*
# the carto parser
TEMPFILE="${SOURCEDIR}/___`basename $SRC`"
cat $SRC | awk "$AWKFILTER" > $TEMPFILE
carto $TEMPFILE | grep -v "$MILLSTONEFILTER" > $DST
rm $TEMPFILE
# read errors from output file
# (carto writes these to stdout and always returns 0)
cat $DST | grep "carto:"
echo `wc -l $DST | cut -d " " -f 1` lines.
done
# Process xml,inc,cfg files
for SRC in `ls ${SOURCEDIR}/*.{xml,cfg}`; do
echo -n "Processing $SRC... "
DST="${DESTDIR}/`basename $SRC`"
cat $SRC | awk "$AWKFILTER" > $DST
echo `wc -l $DST | cut -d " " -f 1` lines.
done