Strabon

changeset 239:612a0ddbb147

added MANY configuration options to strabon script (most of them for the connection)
author Babis Nikolaou <charnik@di.uoa.gr>
date Sun Jun 03 17:47:15 2012 +0300 (2012-06-03)
parents d34c1c13c48c
children 233f2ca0d7e3
files scripts/strabon
line diff
     1.1 --- a/scripts/strabon	Sun Jun 03 15:46:18 2012 +0300
     1.2 +++ b/scripts/strabon	Sun Jun 03 17:47:15 2012 +0300
     1.3 @@ -14,6 +14,54 @@
     1.4  
     1.5  RUNTIME="${LOC}/../runtime"
     1.6  
     1.7 +# runtime package
     1.8 +PKG="eu.earthobservatory.runtime"
     1.9 +
    1.10 +# the underlying database to use (one of `postgis' or `monetdb')
    1.11 +DATABASE="postgis"
    1.12 +
    1.13 +# the main class to run
    1.14 +CLASS=
    1.15 +
    1.16 +# the hostname at which the database runs
    1.17 +HOST="localhost"
    1.18 +
    1.19 +# the port at which the database listens
    1.20 +PORT=
    1.21 +
    1.22 +# the database name to connect to
    1.23 +DB="strabon"
    1.24 +
    1.25 +# the username for the database connection
    1.26 +DBUSER=
    1.27 +
    1.28 +# the password for the database connection
    1.29 +DBPASS=
    1.30 +
    1.31 +# the query to run
    1.32 +QUERY=
    1.33 +
    1.34 +# the RDF format of the files to store (defaults to ntriples)
    1.35 +FORMAT="ntriples"
    1.36 +
    1.37 +# predefined queries
    1.38 +QUERY_SIZE="SELECT (COUNT(*) as ?C) WHERE {?s ?p ?o}"
    1.39 +QUERY_DELETEALL="DELETE {?s ?p ?o} WHERE {?s ?p ?o}"
    1.40 +
    1.41 +# debug option for log4j configuration:
    1.42 +#-Dlog4j.debug
    1.43 +#-Dlog4j.configuration=\"${RUNTIME}/log4j.properties\"
    1.44 +
    1.45 +# just print what shall be executed
    1.46 +DEBUG=false
    1.47 +
    1.48 +# if true, DEBUG has been set in command line,
    1.49 +# so it must not be overidden
    1.50 +DEBUG_SAVE=false
    1.51 +
    1.52 +# configuration file for the Strabon connection
    1.53 +STRABON_CONF="${HOME}/.strabon"
    1.54 +
    1.55  function help() {
    1.56  	echo "Usage: ${CMD} [OPTIONS] COMMAND ARGS"
    1.57  	echo
    1.58 @@ -22,9 +70,29 @@
    1.59  	echo "	COMMAND	 : one of \`query', \`update', \`store', or \`help'"
    1.60  	echo "	ARGS	 : arguments according to selected command"
    1.61  	echo
    1.62 -	echo "OPTIONS can be any of the following"
    1.63 -	echo "	-d	 : don't run, just print what shall be executed"
    1.64 -	#echo "	-c FILE	 : configuration file to use for the connection. It defaults to \`${HOME}/.strabon'."
    1.65 +	echo "OPTIONS can be any of the following (variable names and values are case sensitive)"
    1.66 +	echo "	-d		: don't run, just print what shall be executed"
    1.67 +	echo "			  Variable for configuration file: \`DEBUG'"
    1.68 +	echo "			  Values: \`true' or \`false'" 
    1.69 +	echo "	-e DATABASE	: the database engine to connect (one of \`postgis' (default) or \`monetdb')"
    1.70 +	echo "			  Variable for configuration file: \`DATABASE'"
    1.71 +	echo "			  Values: \`postgis' or \`monetdb'" 
    1.72 +	echo "	-db DB		: the database to connect to (defaults to \`${DB}')"
    1.73 +	echo "			  Variable for configuration file: \`DB'"
    1.74 +	echo "	-p PORT		: the port to use for the database connection"
    1.75 +	echo "			: (defaults to 5432 for postgis and 50000 for monetdb)"
    1.76 +	echo "			  Variable for configuration file: \`PORT'"
    1.77 +	echo "	-h HOSTNAME	: the hostname to use for the database connection (defaults to \`${HOST}')"
    1.78 +	echo "			  Variable for configuration file: \`HOST'"
    1.79 +	echo "	-u USERNAME	: the username for the database connection"
    1.80 +	echo "			  (defaults to \`postgres' for postgis and \`monetdb' for monetdb)"
    1.81 +	echo "			  Variable for configuration file: \`DBUSER'"
    1.82 +	echo "	-pass PASS	: the password for the database connection"
    1.83 +	echo "			  (defaults to \`postgres' for postgis and \`monetdb' for monetdb)"
    1.84 +	echo "			  Variable for configuration file: \`DBPASS'"
    1.85 +	echo "	-c FILE		: configuration file to use for the connection (defaults to \`${STRABON_CONF}')."
    1.86 +	echo "			  If the default configuration file exists, it is read. Options specified in the"
    1.87 +	echo "			  command line override their values already set by the configuration file."
    1.88  }
    1.89  
    1.90  function help_query() {
    1.91 @@ -60,72 +128,175 @@
    1.92  	echo "		    \`ntriples' (default), \`n3', \`rdfxml', or \`turtle'."
    1.93  }
    1.94  
    1.95 -# runtime package
    1.96 -PKG="eu.earthobservatory.runtime"
    1.97  
    1.98 -# the underlying database to use (one of postgis or monetdb)
    1.99 -DATABASE="postgis"
   1.100 +# read configuration script first
   1.101 +if test -e "${STRABON_CONF}"; then
   1.102 +	. ${STRABON_CONF}
   1.103 +fi
   1.104  
   1.105 -# the main class to run
   1.106 -CLASS="QueryOp"
   1.107 -
   1.108 -# the hostname at which the database runs
   1.109 -HOST="localhost"
   1.110 -
   1.111 -# the port at which the database listens
   1.112 -PORT=5432
   1.113 -
   1.114 -# the database name to connect to
   1.115 -DB="endpoint"
   1.116 -DB="strabon"
   1.117 -
   1.118 -# the username for the database connection
   1.119 -DBUSER="charnik"
   1.120 -
   1.121 -# the password for the database connection
   1.122 -DBPASS="charnik"
   1.123 -
   1.124 -# the query to run
   1.125 -QUERY=
   1.126 -
   1.127 -# the RDF format of the files to store (defaults to ntriples)
   1.128 -FORMAT=
   1.129 -
   1.130 -# predefined queries
   1.131 -QUERY_SIZE="SELECT (COUNT(*) as ?C) WHERE {?s ?p ?o}"
   1.132 -QUERY_DELETEALL="DELETE {?s ?p ?o} WHERE {?s ?p ?o}"
   1.133 -
   1.134 -# debug option for log4j configuration:
   1.135 -#-Dlog4j.debug
   1.136 -#-Dlog4j.configuration=\"${RUNTIME}/log4j.properties\"
   1.137 -
   1.138 -# just print what shall be executed
   1.139 -DEBUG=0
   1.140 -
   1.141 -# configuration file for the Strabon connection
   1.142 -STRABON_CONF="${HOME}/.strabon"
   1.143 +if ${DEBUG}; then
   1.144 +	echo "${CMD}: debug is ON (from configuration file ${STRABON_CONF})"
   1.145 +fi
   1.146  
   1.147  # read script options
   1.148 -case "${1}" in
   1.149 -	-d)
   1.150 -		shift
   1.151 -		DEBUG=1
   1.152 -		;;
   1.153 -	-c)
   1.154 -		shift
   1.155 -		if ! test $# -gt 1; then
   1.156 +while test $# -gt 0 -a "X${1:0:1}" == "X-"; do
   1.157 +	case "${1}" in
   1.158 +		-d)
   1.159 +			shift
   1.160 +			if ! ${DEBUG}; then
   1.161 +				echo "${CMD}: debug is ON"
   1.162 +			fi
   1.163 +			DEBUG=true
   1.164 +			DEBUG_SAVE=true
   1.165 +			;;
   1.166 +		-e)
   1.167 +			shift
   1.168 +			if ! test $# -gt 1; then
   1.169 +				help
   1.170 +				exit 1
   1.171 +			fi
   1.172 +
   1.173 +			DATABASE=${1}
   1.174 +			case "${DATABASE}" in
   1.175 +				monetdb|postgis)
   1.176 +					shift
   1.177 +					;;
   1.178 +				postgis)
   1.179 +					shift
   1.180 +					;;
   1.181 +				*)
   1.182 +					echo "${CMD}: invalid database engine"
   1.183 +					echo "${CMD}: valid database engines are \`postgis' or \`monetdb'"
   1.184 +					exit 2
   1.185 +					;;
   1.186 +			esac
   1.187 +			;;
   1.188 +		-db)
   1.189 +			shift
   1.190 +			if ! test $# -gt 1; then
   1.191 +				help
   1.192 +				exit 1
   1.193 +			fi
   1.194 +			DB="${1}"
   1.195 +			shift
   1.196 +			;;
   1.197 +		-p)
   1.198 +			shift
   1.199 +			if ! test $# -gt 1; then
   1.200 +				help
   1.201 +				exit 1
   1.202 +			fi
   1.203 +			PORT=${1}
   1.204 +			shift
   1.205 +			;;
   1.206 +		-h)
   1.207 +			shift
   1.208 +			if ! test $# -gt 1; then
   1.209 +				help
   1.210 +				exit 1
   1.211 +			fi
   1.212 +			HOST=${1}
   1.213 +			shift
   1.214 +			;;
   1.215 +		-u)
   1.216 +			shift
   1.217 +			if ! test $# -gt 1; then
   1.218 +				help
   1.219 +				exit 1
   1.220 +			fi
   1.221 +			DBUSER=${1}
   1.222 +			shift
   1.223 +			;;
   1.224 +		-pass)
   1.225 +			shift
   1.226 +			if ! test $# -gt 1; then
   1.227 +				help
   1.228 +				exit 1
   1.229 +			fi
   1.230 +			DBPASS=${1}
   1.231 +			shift
   1.232 +			;;
   1.233 +		-c)
   1.234 +			shift
   1.235 +			if ! test $# -gt 1; then
   1.236 +				help
   1.237 +				exit 1
   1.238 +			fi
   1.239 +
   1.240 +			STRABON_CONF="${1}"
   1.241 +			if ! test -e "${STRABON_CONF}"; then
   1.242 +				echo "${CMD}: configuration file \"${1}\" does not exist"
   1.243 +				exit 1
   1.244 +			else
   1.245 +				# if true, then debug has been set ON in command line
   1.246 +				if $DEBUG; then
   1.247 +					echo "${CMD}: Reading configuration file \"${STRABON_CONF}\""
   1.248 +				fi
   1.249 +
   1.250 +				. ${STRABON_CONF}
   1.251 +
   1.252 +				if $DEBUG_SAVE; then
   1.253 +					# restore debug value set on command line
   1.254 +					DEBUG=true
   1.255 +				fi
   1.256 +				shift
   1.257 +			fi
   1.258 +			;;
   1.259 +		-*)
   1.260 +			echo "${CMD}: unknown option \"${1}\""
   1.261  			help
   1.262  			exit 1
   1.263 +			;;
   1.264 +	esac
   1.265 +done
   1.266 +
   1.267 +# set defaults
   1.268 +case "${DATABASE}" in
   1.269 +	postgis)
   1.270 +		if test -z "${PORT}";
   1.271 +		then
   1.272 +			PORT=5432
   1.273  		fi
   1.274 -		STRABON_CONF="${1}"
   1.275 -		if ! test -e "${STRABON_CONF}"; then
   1.276 -			echo "${CMD}: configuration file \"${1}\" does not exist."
   1.277 -			exit 1
   1.278 +
   1.279 +		if test -z "${DBUSER}";
   1.280 +		then
   1.281 +			DBUSER="postgres"
   1.282  		fi
   1.283 -		shift
   1.284 +		
   1.285 +		if test -z "${DBPASS}";
   1.286 +		then
   1.287 +			DBPASS="postgres"
   1.288 +		fi
   1.289 +		;;
   1.290 +	monetdb)
   1.291 +		if test -z "${PORT}";
   1.292 +		then
   1.293 +			PORT=50000
   1.294 +		fi
   1.295 +
   1.296 +		if test -z "${DBUSER}";
   1.297 +		then
   1.298 +			DBUSER="monetdb"
   1.299 +		fi
   1.300 +		
   1.301 +		if test -z "${DBPASS}";
   1.302 +		then
   1.303 +			DBPASS="monetdb"
   1.304 +		fi
   1.305  		;;
   1.306  esac
   1.307  
   1.308 +# print configuration/options
   1.309 +if ${DEBUG}; then
   1.310 +	echo "${CMD}: printing database connection details"
   1.311 +	echo "	 Database Engine : ${DATABASE}"
   1.312 +	echo "	 Database Name	 : ${DB}"
   1.313 +	echo "	 Hostname	 : ${HOST}"
   1.314 +	echo "	 Port		 : ${PORT}"
   1.315 +	echo "	 Username	 : ${DBUSER}"
   1.316 +	echo "	 Password	 : ${DBPASS}"
   1.317 +fi
   1.318 +
   1.319  # determine command to execute
   1.320  case "${1}" in
   1.321  	help)
   1.322 @@ -193,7 +364,7 @@
   1.323  		if test "${1}" = "-f"; then
   1.324  			shift
   1.325  			if ! test $# -ge 1; then
   1.326 -				echo "${CMD}: Option -f requires an RDF format (\`ntriples', \`n3', \`rdfxml', or \`turtle')."
   1.327 +				echo "${CMD}: Option -f requires an RDF format (\`ntriples', \`n3', \`rdfxml', or \`turtle')"
   1.328  				exit 2
   1.329  			else
   1.330  				FORMAT="${1}"
   1.331 @@ -203,7 +374,7 @@
   1.332  						;;
   1.333  					*)
   1.334  						echo "${CMD}: invalid RDF format \"${FORMAT}\"."
   1.335 -						echo "${CMD}: valid RDF formats are \`ntriples', \`n3', \`rdfxml', or \`turtle'."
   1.336 +						echo "${CMD}: valid RDF formats are \`ntriples', \`n3', \`rdfxml', or \`turtle'"
   1.337  						exit 2
   1.338  						;;
   1.339  				esac
   1.340 @@ -238,9 +409,8 @@
   1.341  fi
   1.342  
   1.343  # execute command or debug
   1.344 -if test ${DEBUG} -eq 1; then
   1.345 -	echo "${CMD}: Debug is ON"
   1.346 -	echo "${CMD}: Printing command for execution"	
   1.347 +if ${DEBUG}; then
   1.348 +	echo "${CMD}: printing command for execution"	
   1.349  	echo "${STRABON_EXEC}"
   1.350  else
   1.351  	eval ${STRABON_EXEC}