Strabon
changeset 99:e0285c06da6a
added debug option to endpoint script
author | Babis Nikolaou <charnik@di.uoa.gr> |
---|---|
date | Thu Apr 05 20:28:55 2012 +0300 (2012-04-05) |
parents | b22762ef9795 |
children | 298c806608c2 |
files | scripts/endpoint |
line diff
1.1 --- a/scripts/endpoint Thu Apr 05 13:55:28 2012 +0300 1.2 +++ b/scripts/endpoint Thu Apr 05 20:28:55 2012 +0300 1.3 @@ -7,13 +7,16 @@ 1.4 # 1.5 1.6 function help() { 1.7 - echo "Usage: `basename ${0}` COMMAND ENDPOINT ARGS" 1.8 + echo "Usage: `basename ${0}` [OPTIONS] COMMAND ENDPOINT ARGS" 1.9 echo 1.10 echo "Execute SPARQL and SPARQL Update queries as well as store RDF triples on a Strabon endpoint." 1.11 echo 1.12 echo " COMMAND : one of query, update, store, or help" 1.13 echo " ENDPOINT : the URL of the Strabon Endpoint (e.g., http://localhost:8080/StrabonEndpoint)" 1.14 echo " ARGS : arguments according to selected command" 1.15 + echo 1.16 + echo "OPTIONS can be any of the following" 1.17 + echo " -d : don't run, just print what shall be executed" 1.18 } 1.19 1.20 function help_query() { 1.21 @@ -39,7 +42,17 @@ 1.22 echo " TRIPLES_URL : the URL containing the RDF triples to store" 1.23 } 1.24 1.25 -CURL_OPTS="-w HTTP_CODE=%{http_code}\n -H \"Content-Type:application/x-www-form-urlencoded\" -H \"Accept:text/xml\"" 1.26 +CURL_OPTS="-w HTTP_CODE='%{http_code}\n' -H \"Content-Type:application/x-www-form-urlencoded\" -H \"Accept:text/xml\"" 1.27 + 1.28 +# if set to 1, then only the command to be executed is printed 1.29 +DEBUG=0 1.30 + 1.31 +case "${1}" in 1.32 + -d) 1.33 + shift 1.34 + DEBUG=1 1.35 + ;; 1.36 +esac 1.37 1.38 case "${1}" in 1.39 help) 1.40 @@ -76,7 +89,7 @@ 1.41 # TODO: make it an argument 1.42 FORMAT="XML" 1.43 1.44 - curl ${CURL_OPTS} -d "format=${FORMAT}" --data-urlencode "SPARQLQuery=${QUERY}" ${URL} 1.45 + CMD="curl ${CURL_OPTS} -d \"format=${FORMAT}\" --data-urlencode \"SPARQLQuery=${QUERY}\" ${URL}" 1.46 ;; 1.47 update) 1.48 shift 1.49 @@ -87,7 +100,7 @@ 1.50 URL="${1}/Update" 1.51 QUERY="${2}" 1.52 1.53 - curl ${CURL_OPTS} --data-urlencode "SPARQLQuery=${QUERY}" ${URL} 1.54 + CMD="curl ${CURL_OPTS} --data-urlencode \"SPARQLQuery=${QUERY}\" ${URL}" 1.55 ;; 1.56 store) 1.57 shift 1.58 @@ -100,11 +113,11 @@ 1.59 case "${3}" in 1.60 -t) 1.61 TRIPLES="${4}" 1.62 - curl ${CURL_OPTS} -d "format=${FORMAT}" --data-urlencode "data=${TRIPLES}" ${URL} 1.63 + CMD="curl ${CURL_OPTS} -d \"format=${FORMAT}\" --data-urlencode \"data=${TRIPLES}\" ${URL}" 1.64 ;; 1.65 -u) 1.66 URL_TRIPLES="${4}" 1.67 - curl ${CURL_OPTS} -d "format=${FORMAT}" --data-urlencode "url=${URL_TRIPLES}" -d "fromurl=" ${URL} 1.68 + CMD="curl ${CURL_OPTS} -d \"format=${FORMAT}\" --data-urlencode \"url=${URL_TRIPLES}\" -d \"fromurl=\" ${URL}" 1.69 ;; 1.70 *) 1.71 help_store 1.72 @@ -120,3 +133,12 @@ 1.73 ;; 1.74 esac 1.75 1.76 +# execute or debug 1.77 +if test $DEBUG -eq 1; then 1.78 + echo "`basename ${0}`: Debug is ON" 1.79 + echo "`basename ${0}`: Printing command for execution" 1.80 + echo " $CMD" 1.81 +else 1.82 + eval ${CMD} 1.83 +fi 1.84 +