Skip to content
Snippets Groups Projects
Select Git revision
  • 58b2e6151bdd8b40e66c2e97a9cb970f558d1950
  • main default protected
  • dev
  • f-docs-pylib
  • f-parse-value
  • f-compare
  • f-string-ids
  • f-217-set-special-property
  • f-filesystem-import
  • f-filesystem-link
  • f-filesystem-directory
  • f-filesystem-core
  • f-filesystem-cleanup
  • f-check-merge-entities
  • f-compare-enid
  • f-select-subproperties
  • v0.18.0
  • v0.17.0
  • v0.16.0
  • v0.15.1
  • v0.15.0
  • v0.14.0
  • v0.13.2
  • v0.13.1
  • v0.13.0
  • linkahead-rename-step-2
  • linkahead-rename-step-1
  • v0.12.0
  • v0.11.2
  • v0.11.1
  • v0.11.0
  • v0.10.0
  • v0.9.0
  • v0.8.0
  • v0.7.4
  • v0.7.3
36 results

test_utils.py

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    helpers.sh 2.86 KiB
    # This file is a part of the CaosDB Project.
    #
    # Copyright (C) 2018 Research Group Biomedical Physics,
    # Max-Planck-Institute for Dynamics and Self-Organization Göttingen
    # Copyright 2019, 2020 Daniel Hornung
    # Copyright 2020 Henrik tom Wörden, IndiScale GmbH
    #
    # This program is free software: you can redistribute it and/or modify
    # it under the terms of the GNU Affero General Public License as
    # published by the Free Software Foundation, either version 3 of the
    # License, or (at your option) any later version.
    #
    # This program is distributed in the hope that it will be useful,
    # but WITHOUT ANY WARRANTY; without even the implied warranty of
    # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    # GNU Affero General Public License for more details.
    #
    # You should have received a copy of the GNU Affero General Public License
    # along with this program. If not, see <https://www.gnu.org/licenses/>.
    
    
    
    ###############################################################################
    #                         Helper function definitions                         #
    ###############################################################################
    
    # When sourcing this file, the following variables must be set:
    #
    # MYSQL_CMD : source $UTILSPATH/load_settings.sh
    
    
    
    function mysql_execute {
    	  #TODO is it meaningful that here always the database user is used???
    	  set +e
        env
    	  $MYSQL_CMD $(get_db_args) -e "$1"
    	  ret=${PIPESTATUS[0]}
    	  if [ "$ret" -ne 0 ]; then
    		    failure "MYSQL ERROR"
    	  fi
    	  set -e
    }
    
    function get_mysql_args {
    	echo "$(get_mysql_args_nodb) --database=$DATABASE_NAME"
    }
    
    function get_db_args {
    	echo "$(get_db_args_nodb) --database=$DATABASE_NAME"
    }
    
    function get_db_args_nodb {
    	if [ "$DATABASE_USER" ]; then
    		mysql_con_arguments="--user=$DATABASE_USER"
    	fi
    	if [ "$DATABASE_USER_PW" ]; then
    		mysql_con_arguments="$mysql_con_arguments --password=$DATABASE_USER_PW"
    	fi
    	if [[ "$MYSQL_HOST" && ( "$MYSQL_HOST" != "localhost" ) ]]; then
    		mysql_con_arguments="$mysql_con_arguments --host=$MYSQL_HOST"
    		if [ "$MYSQL_PORT" ]; then
    			mysql_con_arguments="$mysql_con_arguments --port=$MYSQL_PORT"
    		fi
    	fi
    	echo $mysql_con_arguments
    }
    
    function get_mysql_args_nodb {
    	if [ "$LOGIN_PATH" ]; then
    		mysql_con_arguments="--login-path=$LOGIN_PATH"
    	else
    		if [ "$MYSQL_USER" ]; then
    			mysql_con_arguments="--user=$MYSQL_USER"
    		fi
    		if [ "$MYSQL_USER_PASSWORD" ]; then
    			mysql_con_arguments="$mysql_con_arguments --password=$MYSQL_USER_PASSWORD"
    		fi
    		if [[ "$MYSQL_HOST" && ( "$MYSQL_HOST" != "localhost" ) ]]; then
    			mysql_con_arguments="$mysql_con_arguments --host=$MYSQL_HOST"
    			if [ "$MYSQL_PORT" ]; then
    				mysql_con_arguments="$mysql_con_arguments --port=$MYSQL_PORT"
    			fi
    		fi
    	fi
    	echo $mysql_con_arguments
    }
    
    function success {
        echo "[OK]"
        exit 0
    }
    
    function failure {
        echo "[FAILED] $*"
        exit 1
    }
    
    function uptodate {
        echo "[UPTODATE]"
        exit 0
    }