From 8b80ad8ba18a618f6f6a6009c8369be6a49bc8bb Mon Sep 17 00:00:00 2001 From: Sandro Santilli Date: Thu, 16 Jan 2014 18:51:02 +0100 Subject: [PATCH] Restore XML print from the show_style tool Closes #110 --- NEWS.md | 5 ++++ tools/show_style | 64 ++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 62 insertions(+), 7 deletions(-) diff --git a/NEWS.md b/NEWS.md index 957a752e..92cc691a 100644 --- a/NEWS.md +++ b/NEWS.md @@ -5,6 +5,11 @@ Bug fixes: * Fix support for long (>64k chars) queries in layergroup creation (#111) +Enhancements: + +* Enhance tools/show_style to accept an environment parameter and + print XML style now it is not in redis anymore (#110) + 1.6.1 -- 2014-01-15 ------------------- diff --git a/tools/show_style b/tools/show_style index b073f78a..d52ac9a9 100755 --- a/tools/show_style +++ b/tools/show_style @@ -2,28 +2,78 @@ # TODO: port to node, if you really need it -REDIS_PORT=6379 # default port - +ENV='development'; +BASEDIR=`cd $(dirname $0)/../; pwd` if test -z "$1"; then - echo "Usage: $0 [|~]" >&2 + echo "Usage: $0 [--env ] [|~]" >&2 + echo " environment defaults to 'development'" + exit 1 +fi + +username="" +token="" + +while test -n "$1"; do + if test "$1" = "--env"; then + shift; ENV="$1"; shift + elif test -z "$username"; then + username="$1"; shift + elif test -z "$token"; then + token="$1"; shift + else + echo "Unused option $1" >&2 + shift + fi +done + +echo "Using environment '${ENV}'" + +CONFIG="${BASEDIR}/config/environments/${ENV}.js" +REDIS_PORT=`node -e "console.log(require('${CONFIG}').redis.port)"` +if test $? -ne 0; then exit 1 fi -username="$1" -token="$2" dbname=`redis-cli -p ${REDIS_PORT} -n 5 hget "rails:users:${username}" "database_name"` if test $? -ne 0; then exit 1 fi if test -z "${dbname}"; then - echo "Username ${username} unknown by redis (try CARTODB/script/restore_redis?)" >&2 + echo "Username ${username} unknown by redis on port ${REDIS_PORT} (try CARTODB/script/restore_redis?)" >&2 exit 1 fi echo "Database name for user ${username}: ${dbname}" # only if verbose? if test -n "$token"; then - redis-cli get "map_style|${dbname}|${token}" | sed -e 's/\\n/\n/g' -e 's/\\//g' + rec=`redis-cli get "map_style|${dbname}|${token}"` + if test -z "${rec}"; then + echo "${token}: no such map style known by redis on port ${REDIS_PORT}" >&2 + exit 1 + fi + #echo "${rec}" + escrec=`echo "${rec}" | sed -e 's/\\\\/\\\\\\\\/g'` + #echo "${escrec}" + node <