]> git.openstreetmap.org Git - chef.git/commitdiff
imagery: add osstvw_make_diffs script
authorGrant Slater <git@firefishy.com>
Mon, 30 May 2016 12:51:12 +0000 (13:51 +0100)
committerGrant Slater <git@firefishy.com>
Mon, 30 May 2016 12:51:12 +0000 (13:51 +0100)
cookbooks/imagery/files/default/osstvw_make_diffs [new file with mode: 0644]
cookbooks/imagery/recipes/gb_os_sv.rb

diff --git a/cookbooks/imagery/files/default/osstvw_make_diffs b/cookbooks/imagery/files/default/osstvw_make_diffs
new file mode 100644 (file)
index 0000000..f4da6df
--- /dev/null
@@ -0,0 +1,49 @@
+#!/bin/bash
+set -e
+GDALCOPYPROJ="/usr/share/doc/python-gdal/examples/gdalcopyproj.py"
+
+# Expected directory names: 2010-04, 2010-11, ... 2016-04
+OSSV_EDITIONS=($(ls -d 201*|sort -n))
+OSSV_EDITIONS_LENGTH=${#OSSV_EDITIONS[@]}
+
+OSSV_EDITIONS_TMP=$(mktemp -d --suffix=osstvw_edit)
+function cleanup {
+  rm -rf "${OSSV_EDITIONS_TMP}"
+}
+trap cleanup EXIT
+
+# Create OSSTVW ocean blue to compare new files against
+convert -size 5000x5000 xc:'#e6f6ff' -depth 8 ${OSSV_EDITIONS_TMP}/blue.png
+
+# Outer loop (compare from)
+for (( i=0; i<${OSSV_EDITIONS_LENGTH}; i++ )); do
+  # Inner loop (compare to)
+  for (( o=${i}; o<${OSSV_EDITIONS_LENGTH}; o++ )); do
+    # Skip when outer == inner edition
+    if [ "$i" != "$o" ]; then
+      OSSV_DIFF_NAME="diff-${OSSV_EDITIONS[$i]}-${OSSV_EDITIONS[$o]}"
+      mkdir -p "${OSSV_DIFF_NAME}"
+      # TIF file loop for edition - see end of loop for find
+      while IFS= read -r -d $'\0' FILE; do
+        FILE_1="${OSSV_EDITIONS[$i]}/${FILE}"
+        FILE_2="${OSSV_EDITIONS[$o]}/${FILE}"
+        if [ ! -f "${FILE_1}" ]; then
+          FILE_1="${OSSV_EDITIONS_TMP}/blue.png"
+        fi
+        # Skip existing files
+        if [ ! -f "${OSSV_DIFF_NAME}/${FILE}" ]; then
+          echo Creating diff ${OSSV_EDITIONS[$i]} ${OSSV_EDITIONS[$o]} "${FILE_1}" "${OSSV_DIFF_NAME}/${FILE}"
+          # Background compare + gdalcopyproj
+          ((compare -quiet "${FILE_1}" "${FILE_2}" -compose Src -highlight-color Red -lowlight-color 'rgba(255,255,255,0)' -define tiff:tile-geometry=512x512 "${OSSV_DIFF_NAME}/${FILE}" || true) && python ${GDALCOPYPROJ} "${FILE_2}" "${OSSV_DIFF_NAME}/${FILE}" ) &
+
+          # Check how many background processes and wait if exceed
+          running=($(jobs -rp))
+          while [ ${#running[@]} -ge 16 ] ; do
+            sleep 1   # this is not optimal, but you can't use wait here
+            running=($(jobs -rp))
+          done
+        fi
+      done < <(find "${OSSV_EDITIONS[$o]}" -maxdepth 1 -name '*.tif' -printf '%f\0')
+    fi
+  done
+done
index e4d394d52b10c2f16a46df8941927c8222d0a0cd..c234fa7a119e193c71afd3f4860fc0f764c0f2bd 100644 (file)
@@ -33,6 +33,13 @@ cookbook_file "/srv/imagery/common/osstvw_process" do
   mode "0755"
 end
 
+cookbook_file "/srv/imagery/common/osstvw_make_diffs" do
+  source "osstvw_make_diffs"
+  owner "root"
+  group "root"
+  mode "0755"
+end
+
 imagery_site "os.openstreetmap.org" do
   aliases ["os.openstreetmap.org.uk"]
 end