Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

GC documents now only fetch upon request

Mike McGann2014eee05101
diff --git a/Gruntfile.js b/Gruntfile.js
index 1d3461399..6bb4e2933 100644
--- a/Gruntfile.js
+++ b/Gruntfile.js
@@ -256,6 +256,10 @@ module.exports = function(grunt) {
command: "find build -type d -empty -delete"
},
+ fetch: {
+ command: "PATH=python/bin:${PATH} FETCH_GC=1 bin/wv-options-build"
+ },
+
rpmbuild: {
command: 'rpmbuild --define "_topdir $PWD/build/rpmbuild" ' +
'-ba build/rpmbuild/SPECS/worldview.spec'
@@ -591,6 +595,8 @@ module.exports = function(grunt) {
"copy:dist_config_versioned"
]);
+ grunt.registerTask("fetch", ["exec:fetch"])
+
grunt.registerTask("site", [
"load_branding",
"remove:build_site",
diff --git a/bin/wv-options-build b/bin/wv-options-build
index f4ec741fb..06fb372b0 100755
--- a/bin/wv-options-build
+++ b/bin/wv-options-build
@@ -17,6 +17,7 @@ BIN_DIR="$BASE/bin"
SRC_DIR="$BASE/options"
BUILD_DIR="$BASE/build/options-build"
DEST_DIR="$BASE/build/options"
+OPT_DIR="$BASE/options"
[ "$FORCE" ] || set -e
@@ -27,6 +28,13 @@ die() {
[ -d "$SRC_DIR" ] || die "Options directory does not exist"
+if [ "$FETCH_GC" ] ; then
+ rm -rf "$OPT_DIR/gc/*"
+ rm -rf "$OPT_DIR/colormaps/gc/*"
+ "$BIN_DIR/wv-options-fetch" "$BUILD_DIR/config.json" "$OPT_DIR/gc"
+ exit 0
+fi
+
rm -rf "$BUILD_DIR" "$DEST_DIR"
mkdir -p "$BUILD_DIR" "$DEST_DIR"
@@ -40,8 +48,7 @@ if [ -e "$BUILD_DIR/features.json" ] ; then
fi
if [ -e "$BUILD_DIR/config.json" ] ; then
- "$BIN_DIR/wv-options-fetch" "$BUILD_DIR/config.json" "$BUILD_DIR/fetch"
- "$BIN_DIR/wv-options-wmts" "$BUILD_DIR/config.json" "$BUILD_DIR/fetch" \
+ "$BIN_DIR/wv-options-wmts" "$BUILD_DIR/config.json" "$OPT_DIR/gc" \
"$BUILD_DIR/config/wv.json/_wmts" "$BUILD_DIR/colormaps"
fi
if [ -e "$BUILD_DIR/colormaps" ] ; then
diff --git a/bin/wv-options-fetch b/bin/wv-options-fetch
index dfd4a3073..e80d21a6f 100755
--- a/bin/wv-options-fetch
+++ b/bin/wv-options-fetch
@@ -11,10 +11,12 @@
#
from optparse import OptionParser
+from datetime import datetime
import os
import sys
import json
import urllib2 as urllib
+import xmltodict
prog = os.path.basename(__file__)
base_dir = os.path.join(os.path.dirname(__file__), "..")
@@ -33,8 +35,14 @@ if len(args) != 2:
config_file = args[0]
output_dir = args[1]
+colormaps = {}
+colormaps_dir = os.path.join("options", "colormaps", "gc")
+remote_count = 0
+error_count = 0
+warning_count = 0
-os.makedirs(output_dir)
+if not os.path.exists(output_dir):
+ os.makedirs(output_dir)
with open(config_file) as fp:
config = json.load(fp)
@@ -47,13 +55,47 @@ def process_remote(entry):
output_file = os.path.join(output_dir, entry["to"])
with open(output_file, "w") as fp:
fp.write(contents)
+ gc = xmltodict.parse(contents)
-remote_count = 0
-error_count = 0
-warning_count = 0
+ for layer in gc["Capabilities"]["Contents"]["Layer"]:
+ ident = layer["ows:Identifier"]
+ if "ows:Metadata" in layer:
+ if ident in config.get("skipPalettes", []):
+ sys.stderr.write("%s: WARN: Skipping palette for %s\n" %
+ prog, ident)
+ global warning_count
+ warning_count += 1
+ else:
+ colormap_link = layer["ows:Metadata"]["@xlink:href"]
+ colormap_file = os.path.basename(colormap_link)
+ colormap_id = os.path.splitext(colormap_file)[0]
+ colormaps[colormap_id] = colormap_link
+
+def process_colormaps():
+ print "%s: Fetching %d colormaps" % (prog, len(colormaps))
+ sys.stdout.flush()
+ if not os.path.exists(colormaps_dir):
+ os.makedirs(colormaps_dir)
+ for link in colormaps.values():
+ try:
+ response = urllib.urlopen(link)
+ contents = response.read()
+ output_file = os.path.join(colormaps_dir, os.path.basename(link))
+ with open(output_file, "w") as fp:
+ fp.write(contents)
+ except Exception as e:
+ sys.stderr.write("%s: WARN: Unable to fetch %s: %s" %
+ (prog, link, str(e)))
+ global warning_count
+ warning_count += 1
tolerant = config.get("tolerant", False)
if "wv-options-fetch" in config:
+ with open(os.path.join(output_dir, "info.json"), "w") as fp:
+ info = {
+ "fetched": datetime.today().isoformat()
+ }
+ json.dump(info, fp)
for entry in config["wv-options-fetch"]:
try:
remote_count += 1
@@ -65,6 +107,8 @@ if "wv-options-fetch" in config:
else:
error_count += 1
sys.stderr.write("%s: ERROR: %s\n" % (prog, str(e)))
+ if colormaps:
+ process_colormaps()
print "%s: %d error(s), %d remote(s)" % (prog, error_count, remote_count)
diff --git a/bin/wv-options-wmts b/bin/wv-options-wmts
index f48cc2622..d9655542c 100755
--- a/bin/wv-options-wmts
+++ b/bin/wv-options-wmts
@@ -122,7 +122,6 @@ def process_layer(gc_layer, wv_layers, colormaps):
colormap_link = gc_layer["ows:Metadata"]["@xlink:href"]
colormap_file = os.path.basename(colormap_link)
colormap_id = os.path.splitext(colormap_file)[0]
- colormaps[colormap_id] = colormap_link
wv_layer["palette"] = {
"id": colormap_id
}
@@ -197,23 +196,6 @@ def process_entry(entry, colormaps):
error_count, warning_count, layer_count, entry["source"])
return [error_count, warning_count, layer_count]
-def fetch_colormaps(colormaps):
- print "%s: Fetching %d colormaps" % (prog, len(colormaps))
- sys.stdout.flush()
- warnings = 0
- for link in colormaps.values():
- try:
- response = urllib.urlopen(link)
- contents = response.read()
- output_file = os.path.join(colormaps_dir, os.path.basename(link))
- with open(output_file, "w") as fp:
- fp.write(contents)
- except Exception as e:
- warnings += 1
- sys.stderr.write("%s: WARN: Unable to fetch %s: %s" %
- (prog, link, str(e)))
-
- return warnings
# Main
colormaps = {}
@@ -223,8 +205,6 @@ for entry in entries:
total_warning_count += warning_count
total_layer_count += layer_count
-total_warning_count += fetch_colormaps(colormaps)
-
print "%s: %d error(s), %d warning(s), %d layers" % (prog, total_error_count,
total_warning_count, total_layer_count)