From 11ccd143fa09ebfdb6164db06f698bce7472f222 Mon Sep 17 00:00:00 2001 From: Andreas Romeyke <art1@andreas-romeyke.de> Date: Wed, 12 Oct 2022 09:50:43 +0200 Subject: [PATCH] - added --pipe (wished by Joerg) --- DESIGN.asciidoc | 1 + validate_workflow.sh | 109 ++++++++++++++++++++++++++++--------------- 2 files changed, 72 insertions(+), 38 deletions(-) diff --git a/DESIGN.asciidoc b/DESIGN.asciidoc index cc0a5a2..06d75a1 100644 --- a/DESIGN.asciidoc +++ b/DESIGN.asciidoc @@ -31,6 +31,7 @@ A cli tool which uses different validators to validate workflows. * --daemon - starts a daemon, works only with delete mode * --stage=[current,upcoming,any] - valides with current or upcoming profile /validator or any if any is valid +* --pipe - use program as a filter == related files diff --git a/validate_workflow.sh b/validate_workflow.sh index 1061a72..e20785f 100755 --- a/validate_workflow.sh +++ b/validate_workflow.sh @@ -26,19 +26,19 @@ #hh #hh -h, --help #hh help output -#hh -w, -i, --watch-folder <DIR> +#hh -w, --watch-folder <DIR> #hh watches folder for files which should be evaluated -#hh -r, -o, --result-folder <DIR> +#hh -r, --result-folder <DIR> #hh target folder to store validation results #hh -f, --files-mode [sort|delete|nothing] #hh mode=sort it sorts files to valid- and invalid-folder, #hh mode=delete it deletes already checked files from watch-folder #hh mode=nothing files in watch-folder are untouched #hh The mode=delete is default. -#hh -p, --valid-folder <DIR> +#hh -v, --valid-folder <DIR> #hh only needed if files-mode=sort, moves valid files from #hh watch-folder to valid-folder -#hh -n, --invalid-folder <DIR> +#hh -i, --invalid-folder <DIR> #hh only needed if files-mode=sort, moves invalid files from #hh watch-folder to invalid folder #hh -s, --statistics @@ -51,16 +51,24 @@ #hh -t, --stage [current,upcoming,any] #hh valides with current or upcoming profile/validator #hh or any if any is valid +#hh -p, --pipe +#hh validates a single filestream from STDIN, writes result to STDOUT +#hh no daemon, no folder nor filemode params needed #hh #hh #DEFAULTS WITH_DAEMON=0 +WITH_PIPE=0 STAGE=any MODE=auto FILES_MODE=nothing STATFILE=${HOME}/.cache/validate_workflows/statistics.cnt LOCKFILE=/var/run/lock/validate_workflows.lock +WATCH_FOLDER="" +RESULT_FOLDER="" +VALID_FOLDER="" +INVALID_FOLDER="" set -o nounset # Treat unset variables as an error @@ -84,22 +92,22 @@ get_cli_args() { print_statistics exit 0 ;; - -w | -i | --watch-folder) + -w | --watch-folder) WATCH_FOLDER="${2}" shift shift ;; - -r | -o | --result-folder) + -r | --result-folder) RESULT_FOLDER="${2}" shift shift ;; - -p | --valid-folder) + -v | --valid-folder) VALID_FOLDER="${2}" shift shift ;; - -n | --invalid-folder) + -i | --invalid-folder) INVALID_FOLDER="${2}" shift shift @@ -123,6 +131,10 @@ get_cli_args() { shift shift ;; + -p | --pipe) + WITH_PIPE=1 + shift + ;; *) >&2 echo "'${1}' ist kein gültiger Parameter. Bitte benutzen Sie '$(basename "${0}") --help'." exit 1 @@ -138,33 +150,46 @@ get_cli_args() { >&2 echo "param --mode must be 'auto', 'mediathek', 'fotothek', 'save', 'kitodo' or 'lfulg'!" exit 1 fi - if [ "$WITH_DAEMON" -eq 1 -a "$FILES_MODE" = "sort" ]; then - >&2 echo "param --daemon does only work with param --mode='delete' or --mode='nothing'!" - exit 1 - fi - if [ "$STAGE" != "current" -a "$STAGE" != "upcoming" -a "$STAGE" != "any" ]; then - >&2 echo "--param stage must be 'any', 'current' or 'upcoming'!" - exit 1 - fi - if [ ! -d "$WATCH_FOLDER" ]; then - >&2 echo "watch folder '$WATCH_FOLDER' does not exist!" - exit 1 - fi - if [ ! -d "$RESULT_FOLDER" ]; then - >&2 echo "result folder '$RESULT_FOLDER' does not exist!" - exit 1 - fi - if [ "$FILES_MODE" = "sort" ]; then - if [ ! -d "$VALID_FOLDER" ]; then - >&2 echo "valid folder '$VALID_FOLDER' does not exist!" + if [ "$WITH_PIPE" -eq 1 ]; then + if + [ "$WITH_DAEMON" -eq 1 ] \ + || [ "$WATCH_FOLDER" ] \ + || [ "$RESULT_FOLDER" ] \ + || [ "$VALID_FOLDER" ] \ + || [ "$INVALID_FOLDER" ] \ + || [ "$FILES_MODE" = "sort" ] \ + ; then + >&2 echo "param --pipe not combineable with params --daemon, --result-folder, --watch-folder, --valid-folder, --invalid-folder, --files-mode" exit 1 fi - if [ ! -d "$INVALID_FOLDER" ]; then - >&2 echo "invalid folder '$INVALID_FOLDER' does not exist!" + else + if [ "$WITH_DAEMON" -eq 1 -a "$FILES_MODE" = "sort" ]; then + >&2 echo "param --daemon does only work with param --mode='delete' or --mode='nothing'!" exit 1 fi + if [ "$STAGE" != "current" -a "$STAGE" != "upcoming" -a "$STAGE" != "any" ]; then + >&2 echo "--param stage must be 'any', 'current' or 'upcoming'!" + exit 1 + fi + if [ ! -d "$WATCH_FOLDER" ]; then + >&2 echo "watch folder '$WATCH_FOLDER' does not exist!" + exit 1 + fi + if [ ! -d "$RESULT_FOLDER" ]; then + >&2 echo "result folder '$RESULT_FOLDER' does not exist!" + exit 1 + fi + if [ "$FILES_MODE" = "sort" ]; then + if [ ! -d "$VALID_FOLDER" ]; then + >&2 echo "valid folder '$VALID_FOLDER' does not exist!" + exit 1 + fi + if [ ! -d "$INVALID_FOLDER" ]; then + >&2 echo "invalid folder '$INVALID_FOLDER' does not exist!" + exit 1 + fi + fi fi - } scan_file() { @@ -181,12 +206,20 @@ scan_dir() { #### MAIN get_cli_args "$@" -if [ "$WITH_DAEMON" -eq 1 ]; then - # echo daemon mode, use inotify to watch changes - echo "starting daemon" - echo "stopping daemon" -else - # cli mode, scan watch folder once - echo "checking dir $WATCH_FOLDER" - scan_dir "$WATCH_FOLDER" +if [ "$WITH_PIPE" -eq 1 ]; then + #cli mode, use stdin + echo "checking stream" + filename=$(mktemp validate_wrg.XXXX) + scan_file "$filename" + rm -f $filename +else + if [ "$WITH_DAEMON" -eq 1 ]; then + # echo daemon mode, use inotify to watch changes + echo "starting daemon" + echo "stopping daemon" + else + # cli mode, scan watch folder once + echo "checking dir $WATCH_FOLDER" + scan_dir "$WATCH_FOLDER" + fi fi -- GitLab