Skip to content

Commit

Permalink
Move certain shell functions to library.
Browse files Browse the repository at this point in the history
These functions are either used by several scripts or will be in the future.
Move them to library to uphold DRY principle.
  • Loading branch information
Evildoor committed Apr 17, 2019
1 parent e39efe2 commit b305a69
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 40 deletions.
20 changes: 3 additions & 17 deletions Utils/Dataflow/run/data4es-consistency-check
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,15 @@
DEBUG=

base_dir=$( cd "$(dirname "$(readlink -f "$0")")"; pwd)
lib="$base_dir/../shell_lib"

# Directories with configuration files
[ -n "$DATA4ES_CONSISTENCY_CONFIG_PATH" ] && \
CONFIG_PATH="$DATA4ES_CONSISTENCY_CONFIG_PATH" || \
CONFIG_PATH="${base_dir}/../config:${base_dir}/../../Elasticsearch/config"

# Find configuration file in $CONFIG_PATH
get_config() {
[ -z "$1" ] && echo "get_config(): no arguments passed." && return 1
dirs=$CONFIG_PATH
while [ -n "$dirs" ]; do
dir=${dirs%%:*}
[ "$dirs" = "$dir" ] && \
dirs='' || \
dirs="${dirs#*:}"
[ -f "${dir}/${1}" ] && readlink -f "${dir}/${1}" && return 0
done
}

# EOP filter (required due to the unconfigurable EOP marker in pyDKB)
eop_filter() {
sed -e"s/\\x00//g"
}
source $lib/get_config
source $lib/eop_filter

# Oracle
cfg009=`get_config "consistency009.cfg"`
Expand Down
27 changes: 4 additions & 23 deletions Utils/Dataflow/run/data4es-start
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,9 @@ BATCH_SIZE=100
DEBUG=

base_dir=$( cd "$(dirname "$(readlink -f "$0")")"; pwd)
lib="$base_dir/../shell_lib"

log() {
level=INFO
[ $# -eq 2 ] && level="$1" && shift
[ -z "$SCRIPT_NAME" ] && SCRIPT_NAME="$(basename "$0")"
msg="$1"
echo "($level) `date +'%d-%m-%Y %T'` ($SCRIPT_NAME) $msg" >&2
}
source $lib/log

# Directories with configuration files
[ -n "$DATA4ES_CONFIG_PATH" ] && \
Expand Down Expand Up @@ -49,18 +44,7 @@ pidfile="$HOME_DIR/pid"
# Define commands to be used as dataflow nodes
# ---

# Find configuration file in $CONFIG_PATH
get_config() {
[ -z "$1" ] && log ERROR "get_config(): no arguments passed." && return 1
dirs=$CONFIG_PATH
while [ -n "$dirs" ]; do
dir=${dirs%%:*}
[ "$dirs" = "$dir" ] && \
dirs='' || \
dirs="${dirs#*:}"
[ -f "${dir}/${1}" ] && readlink -f "${dir}/${1}" && return 0
done
}
source $lib/get_config

# Oracle Connector
cmd_09="${base_dir}/../009_oracleConnector/Oracle2JSON.py"
Expand Down Expand Up @@ -101,10 +85,7 @@ cmd_95="${base_dir}/../095_datasetInfoAMI/amiDatasets.py -m s --userkey $AUTH_KE

# Service (glue) functions
# ---
# EOP filter (required due to the unconfigurable EOP marker in pyDKB)
eop_filter() {
sed -e"s/\\x00//g"
}
source $lib/eop_filter

# Buffer file name
get_buffer() {
Expand Down
6 changes: 6 additions & 0 deletions Utils/Dataflow/shell_lib/eop_filter
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

# EOP filter (required due to the unconfigurable EOP marker in pyDKB)
eop_filter() {
sed -e"s/\\x00//g"
}
19 changes: 19 additions & 0 deletions Utils/Dataflow/shell_lib/get_config
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash

lib=./

source $lib/log

# Find configuration file in $CONFIG_PATH
get_config() {
[ -z "$1" ] && log ERROR "get_config(): no arguments passed." && return 1
[ -z "$CONFIG_PATH" ] && CONFIG_PATH=`pwd`
dirs=$CONFIG_PATH
while [ -n "$dirs" ]; do
dir=${dirs%%:*}
[ "$dirs" = "$dir" ] && \
dirs='' || \
dirs="${dirs#*:}"
[ -f "${dir}/${1}" ] && readlink -f "${dir}/${1}" && return 0
done
}
9 changes: 9 additions & 0 deletions Utils/Dataflow/shell_lib/log
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

log() {
level=INFO
[ $# -eq 2 ] && level="$1" && shift
[ -z "$SCRIPT_NAME" ] && SCRIPT_NAME="$(basename "$0")"
msg="$1"
echo "($level) `date +'%d-%m-%Y %T'` ($SCRIPT_NAME) $msg" >&2
}

0 comments on commit b305a69

Please sign in to comment.