Skip to content
Snippets Groups Projects
Commit 7ed9c2d5 authored by Andreas Romeyke's avatar Andreas Romeyke
Browse files

- fixes #3

- changed help doc for --mode param
parent e9978307
No related branches found
No related tags found
No related merge requests found
...@@ -44,7 +44,7 @@ ...@@ -44,7 +44,7 @@
#hh -s, --statistics #hh -s, --statistics
#hh print a statistic #hh print a statistic
#hh -m, --mode [auto, mediathek, fotothek, save, kitodo, lfulg] #hh -m, --mode [auto, mediathek, fotothek, save, kitodo, lfulg]
#hh the mode 'auto' tries to check files based on file extensions. #hh the mode 'auto' tries to check files based on file mime-types.
#hh The other modes are actual workflow names. #hh The other modes are actual workflow names.
#hh -d, --daemon #hh -d, --daemon
#hh starts a daemon, works only in --files-mode=delete #hh starts a daemon, works only in --files-mode=delete
...@@ -109,9 +109,14 @@ calc_statistics() { ...@@ -109,9 +109,14 @@ calc_statistics() {
} }
print_statistics() { print_statistics() {
local stat
local cnt_total
local cnt_valid
local cnt_invalid
local ratio
stat=$(calc_statistics) stat=$(calc_statistics)
cnt_total=$(echo $stat | awk 'END {print $1}') cnt_total=$(echo "$stat" | awk 'END {print $1}')
cnt_valid=$(echo $stat | awk 'END {print $2}') cnt_valid=$(echo "$stat" | awk 'END {print $2}')
cnt_invalid=$((cnt_total - cnt_valid)) cnt_invalid=$((cnt_total - cnt_valid))
ratio=$(( 100*cnt_valid / cnt_total )) ratio=$(( 100*cnt_valid / cnt_total ))
echo "Validation Statistics" echo "Validation Statistics"
...@@ -122,11 +127,12 @@ print_statistics() { ...@@ -122,11 +127,12 @@ print_statistics() {
} }
update_statistics() { update_statistics() {
is_valid=$1 local is_valid=$1
duration=$2 local duration=$2
ftype=$3 local ftype=$3
workflow=$4 local workflow=$4
stage=$5 local stage=$5
local date
date=$(date +"%F%T") date=$(date +"%F%T")
debug "date=$date" debug "date=$date"
flock -x $LOCKFILE echo "$date,$is_valid,$duration,$ftype,$workflow,$stage" >> "$STATFILE" flock -x $LOCKFILE echo "$date,$is_valid,$duration,$ftype,$workflow,$stage" >> "$STATFILE"
...@@ -149,13 +155,16 @@ error() { ...@@ -149,13 +155,16 @@ error() {
} }
get_mimetype() { get_mimetype() {
filename=$1 local filename=$1
local res
res=$(file --mime-type "$filename" | sed -e "s/^.*: //") res=$(file --mime-type "$filename" | sed -e "s/^.*: //")
echo "$res" echo "$res"
} }
get_cli_args() { get_cli_args() {
local lines
local cachedir
while [[ $# -gt 0 ]]; do while [[ $# -gt 0 ]]; do
case ${1} in case ${1} in
-h | --help) -h | --help)
...@@ -235,10 +244,10 @@ get_cli_args() { ...@@ -235,10 +244,10 @@ get_cli_args() {
if [ "$WITH_PIPE" -eq 1 ]; then if [ "$WITH_PIPE" -eq 1 ]; then
if if
[ "$WITH_DAEMON" -eq 1 ] \ [ "$WITH_DAEMON" -eq 1 ] \
|| [ "$WATCH_FOLDER" ] \ || [ -n "$WATCH_FOLDER" ] \
|| [ "$RESULT_FOLDER" ] \ || [ -n "$RESULT_FOLDER" ] \
|| [ "$VALID_FOLDER" ] \ || [ -n "$VALID_FOLDER" ] \
|| [ "$INVALID_FOLDER" ] \ || [ -n "$INVALID_FOLDER" ] \
|| [ "$FILES_MODE" = "sort" ] \ || [ "$FILES_MODE" = "sort" ] \
; then ; then
error "param --pipe not combineable with params --daemon, --result-folder, --watch-folder, --valid-folder, --invalid-folder, --files-mode" error "param --pipe not combineable with params --daemon, --result-folder, --watch-folder, --valid-folder, --invalid-folder, --files-mode"
...@@ -289,9 +298,11 @@ get_cli_args() { ...@@ -289,9 +298,11 @@ get_cli_args() {
} }
prepare_cmd() { prepare_cmd() {
mode=$1 local mode=$1
ftype=$2 local ftype=$2
stage=$3 local stage=$3
local key
local cmd
key=$(printf "%11s%4s%9s" "$mode" "$ftype" "$stage"|sed -e "y/ /_/") key=$(printf "%11s%4s%9s" "$mode" "$ftype" "$stage"|sed -e "y/ /_/")
debug "prepare_cmd, key=$key" debug "prepare_cmd, key=$key"
if [[ ${validators[$key]:+1} ]]; then if [[ ${validators[$key]:+1} ]]; then
...@@ -304,7 +315,8 @@ prepare_cmd() { ...@@ -304,7 +315,8 @@ prepare_cmd() {
} }
prepare_ftype() { prepare_ftype() {
mimetype=$1 local mimetype=$1
local ftype
debug "prepare_ftype, using mimetype: $mimetype" debug "prepare_ftype, using mimetype: $mimetype"
case ${mimetype} in case ${mimetype} in
"image/tiff") "image/tiff")
...@@ -323,7 +335,7 @@ prepare_ftype() { ...@@ -323,7 +335,7 @@ prepare_ftype() {
} }
estimate_mode() { estimate_mode() {
mimetype=$1 local mimetype=$1
debug "estimate_mode, using mimetype: $mimetype" debug "estimate_mode, using mimetype: $mimetype"
case ${mimetype} in case ${mimetype} in
"image/tiff") "image/tiff")
...@@ -338,29 +350,31 @@ estimate_mode() { ...@@ -338,29 +350,31 @@ estimate_mode() {
;; ;;
esac esac
debug "estimate_mode, detected mode: $MODE" debug "estimate_mode, detected mode: $MODE"
echo $MODE echo "$MODE"
} }
exec_cmd() { exec_cmd() {
cmd=$1 local cmd=$1
ftype=$2 local ftype=$2
workflow=$3 local workflow=$3
stage=$4 local stage=$4
log=$5 local log=$5
local start_t
local stop_t
start_t=$(date +"%s") start_t=$(date +"%s")
debug "scan_file, calling cmd='$cmd'" debug "scan_file, calling cmd='$cmd'"
$cmd >>"$log" 2>&1 $cmd >>"$log" 2>&1
is_valid=$? local is_valid=$?
stop_t=$(date +"%s") stop_t=$(date +"%s")
duration=$((stop_t - start_t)) local duration=$((stop_t - start_t))
debug "scan_file, duration=$duration is_valid=$is_valid log=$log" debug "scan_file, duration=$duration is_valid=$is_valid log=$log"
update_statistics "$is_valid" "$duration" "$ftype" "$workflow" "$stage" update_statistics "$is_valid" "$duration" "$ftype" "$workflow" "$stage"
echo "$is_valid" echo "$is_valid"
} }
handle_input_if_requested() { handle_input_if_requested() {
filename=$1 local filename=$1
is_valid=$2 local is_valid=$2
debug "handle_input_if_requested, filename=$filename is_valid=$is_valid" debug "handle_input_if_requested, filename=$filename is_valid=$is_valid"
if [ "$FILES_MODE" = "sort" ]; then if [ "$FILES_MODE" = "sort" ]; then
if [ "$is_valid" -eq 0 ]; then if [ "$is_valid" -eq 0 ]; then
...@@ -377,7 +391,8 @@ handle_input_if_requested() { ...@@ -377,7 +391,8 @@ handle_input_if_requested() {
} }
get_logfile() { get_logfile() {
filename=$1 local filename=$1
local logname
logname=$(echo "$filename"| sed -e "s#^${WATCH_FOLDER}#${RESULT_FOLDER}#" -e "s#\$#.log#") logname=$(echo "$filename"| sed -e "s#^${WATCH_FOLDER}#${RESULT_FOLDER}#" -e "s#\$#.log#")
debug "get_logfile, logname=$logname (filename=$filename)" debug "get_logfile, logname=$logname (filename=$filename)"
echo "$logname" echo "$logname"
...@@ -385,7 +400,12 @@ get_logfile() { ...@@ -385,7 +400,12 @@ get_logfile() {
scan_file() { scan_file() {
filename="$1" local filename="$1"
local mimetype
local ftype
local logname
local cmd
local is_valid
debug "scan_file, using filename: $filename" debug "scan_file, using filename: $filename"
mimetype=$(get_mimetype "$filename") mimetype=$(get_mimetype "$filename")
ftype=$(prepare_ftype "$mimetype") ftype=$(prepare_ftype "$mimetype")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment