shorten extract-and-generate

This commit is contained in:
Motiejus Jakštys 2021-05-19 22:57:48 +03:00 committed by Motiejus Jakštys
parent b291b52957
commit 020447b687
2 changed files with 17 additions and 19 deletions

View File

@ -60,7 +60,7 @@ slides: $(SLIDES)
# The report, quick version # The report, quick version
########################### ###########################
mj-msc.pdf: mj-msc.tex version.inc.tex vars.inc.tex bib.bib \ mj-msc.pdf: mj-msc.tex version.inc.tex vars.inc.tex extract-and-generate bib.bib \
$(addsuffix .pdf,$(FIGURES)) $(addsuffix .pdf,$(RIVERS)) $(addsuffix .pdf,$(FIGURES)) $(addsuffix .pdf,$(RIVERS))
latexmk -shell-escape -g -pdf $< latexmk -shell-escape -g -pdf $<
@ -133,16 +133,16 @@ salvis-250k_1SELECT = wm_rivers where name='Šalčia' OR name='Visinčia'
salvis-250k_WIDTHDIV = 10 salvis-250k_WIDTHDIV = 10
.faux_test-rivers: tests-rivers.sql wm.sql Makefile .faux_db .faux_test-rivers: tests-rivers.sql wm.sql Makefile .faux_db
./db -v scaledwidth=$(SCALEDWIDTH) -f $< bash db -v scaledwidth=$(SCALEDWIDTH) -f $<
touch $@ touch $@
.faux_test: tests.sql wm.sql .faux_db .faux_test: tests.sql wm.sql .faux_db
./db -f $< bash db -f $<
touch $@ touch $@
.faux_db: db init.sql .faux_db: db init.sql
./db start bash db start
./db -f init.sql -f rivers.sql bash db -f init.sql -f rivers.sql
touch $@ touch $@
################################ ################################
@ -186,7 +186,7 @@ mj-msc-gray.pdf: mj-msc.pdf
.PHONY: clean .PHONY: clean
clean: ## Clean the current working directory clean: ## Clean the current working directory
-./db stop -bash db stop
-rm -r .faux_test .faux_aggregate-rivers .faux_test-rivers .faux_db \ -rm -r .faux_test .faux_aggregate-rivers .faux_test-rivers .faux_db \
version.inc.tex vars.inc.tex version.aux version.fdb_latexmk \ version.inc.tex vars.inc.tex version.aux version.fdb_latexmk \
_minted-mj-msc \ _minted-mj-msc \
@ -197,7 +197,7 @@ clean: ## Clean the current working directory
.PHONY: clean-tables .PHONY: clean-tables
clean-tables: ## Remove tables created during unit or rivers tests clean-tables: ## Remove tables created during unit or rivers tests
./db -c '\dt wm_*' | awk '/_/{print "drop table "$$3";"}' | ./db -f - bash db -c '\dt wm_*' | awk '/_/{print "drop table "$$3";"}' | bash db -f -
-rm .faux_db -rm .faux_db
.PHONY: help .PHONY: help
@ -217,7 +217,7 @@ $(OSM):
.PHONY: refresh-rivers .PHONY: refresh-rivers
refresh-rivers: aggregate-rivers.sql $(OSM) .faux_db ## Refresh rivers.sql from Open Street Maps refresh-rivers: aggregate-rivers.sql $(OSM) .faux_db ## Refresh rivers.sql from Open Street Maps
PGPASSWORD=osm osm2pgsql -c --multi-geometry -H 127.0.0.1 -d osm -U osm $(OSM) PGPASSWORD=osm osm2pgsql -c --multi-geometry -H 127.0.0.1 -d osm -U osm $(OSM)
./db -v where="$(WHERE)" -f $< bash db -v where="$(WHERE)" -f $<
(\ (\
echo '-- Generated at $(shell TZ=UTC date +"%FT%TZ") on $(shell whoami)@$(shell hostname -f)'; \ echo '-- Generated at $(shell TZ=UTC date +"%FT%TZ") on $(shell whoami)@$(shell hostname -f)'; \
echo '-- Select: $(WHERE)'; \ echo '-- Select: $(WHERE)'; \

View File

@ -1,16 +1,14 @@
#!/bin/bash #!/bin/bash
set -euo pipefail set -euo pipefail
dir=$(mktemp -d) s=${1:-mj-msc-full.pdf}
src=${1:-mj-msc-full.pdf} d=$(mktemp -d)
readonly dst=mj-msc.pdf readonly f=mj-msc.pdf
readonly log="$dir/make.log" readonly l="$d/make.log"
echo "Extracting $src to $dir/" && pdfdetach -saveall -o "$dir" "$src" echo "Extracting $s to workdir $d/"; pdfdetach -saveall -o "$d" "$s"
chmod a+x "$dir/db" echo "Logs in $l ..."; make -j "$(nproc)" -C "$d" "$f" &> "$l" || {
echo "Generating $dir/$dst, logs in $log ..." echo "Failed to generate. $l extract:" && tail -20 "$l"
make -j "$(nproc)" -C "$dir" "$dst" &> "$log" || {
echo "Failed to generate. $log extract:" && tail -20 "$dir/make.log"
exit 1 exit 1
} }
echo "Opening $dir/$dst ..." && xdg-open "$dir/$dst" echo "Opening $d/$f ..."; xdg-open "$d/$f"
echo "$dir/$dst was closed. Removing $dir" && rm -fr "$dir" echo "$d/$f was closed. Removing $d"; rm -fr "$d"