From 5e006ae7cc8a74c1416183e8bb5809bd58abe4f2 Mon Sep 17 00:00:00 2001 From: Vincent Riquer Date: Sat, 28 Sep 2013 00:09:02 +0200 Subject: [PATCH] Add "cron" mode (suppress most progress info) --- atom | 62 ++++++++++++++++++++++++++++-------------- lib/copy/action | 9 ++++-- lib/files/getFiles | 5 ++-- lib/tags/update | 8 ++++-- lib/tools/progressSpin | 19 ++++++++----- 5 files changed, 69 insertions(+), 34 deletions(-) diff --git a/atom b/atom index df88835..d1c7316 100755 --- a/atom +++ b/atom @@ -68,6 +68,7 @@ help() { -S Run setup -h Show this text -D Increase debug + -q Cron mode EOF } @@ -101,6 +102,9 @@ do D) (( debug++ )) ;; + q) + cron=1 + ;; :) echo "-$OPTARG requires an argument" help @@ -115,7 +119,13 @@ do done askconf() { - read -p"Create one now? [Y/n/q] " createconf + if (( cron )) + then + echo 'Non-interactive, not running setup. Please run atom -S.' >&2 + createconf=n + else + read -p"Create one now? [Y/n/q] " createconf + fi case $createconf in ''|[yY]) setup @@ -282,16 +292,19 @@ elif (( sanitywarn )) then echo " Sanity checks raised $sanitywarn warnings... Hit Control-C to abort." >&2 - timeout=$(( sanitywarn * 10 )) - echo -n "Starting in $(printf %3i $timeout)" \ - $'seconds...\b\b\b\b\b\b\b\b\b\b\b' >&2 - while (( timeout )) - do - echo -n $'\b\b\b'"$(printf %3i $timeout)" >&2 - sleep 1 - (( timeout-- )) - done - echo -en "\r\033[K" + if ! (( cron )) + then + timeout=$(( sanitywarn * 10 )) + echo -n "Starting in $(printf %3i $timeout)" \ + $'seconds...\b\b\b\b\b\b\b\b\b\b\b' >&2 + while (( timeout )) + do + echo -n $'\b\b\b'"$(printf %3i $timeout)" >&2 + sleep 1 + (( timeout-- )) + done + echo -en "\r\033[K" + fi fi openDatabase @@ -457,9 +470,9 @@ read -u4 line while ! [[ $line = AtOM:NoMoreFiles ]] do decodefiles+=("$line::AtOM:SQL:Sep::") +(( cron )) || echo -n 'Creating tasks... ' read -u4 line done -echo -n 'Creating tasks... ' echo 'BEGIN TRANSACTION;' >&3 for line in "${decodefiles[@]}" @@ -634,7 +647,7 @@ do ${seconds:-0} seconds" \ +'%d/%m %H:%M:%S' )" - printf \ + (( cron )) || printf \ "\r$fmtload $fmtworkers $fmtprogress $fmttime $eta\033[K"\ $humanload \ $maxload \ @@ -676,8 +689,11 @@ endtime=$(date +%s) ( ( ( ( days*24 + hours ) *60 ) + minutes ) *60 ) )) || true -echo -e "\rRan ${ran:=0} tasks, $failed of which failed, in $days" \ - "days, $hours hours, $minutes minutes and $seconds seconds.\033[K" +(( cron )) || echo -n $'\r' +echo -n "Ran ${ran:=0} tasks, $failed of which failed, in $days" \ + "days, $hours hours, $minutes minutes and $seconds seconds." +(( cron )) || echo -en "\033[K" +echo if [ -n "$quit" ] then @@ -737,7 +753,7 @@ do 'opus') extension=opus ;; 'vorbis') extension=ogg ;; esac - echo -n "$destination: rename pattern changed, renaming files... " + (( cron )) || echo -n "$destination: rename pattern changed, renaming files... " echo 'BEGIN TRANSACTION;' >&3 for line in "${renamefiles[@]}" do @@ -793,7 +809,10 @@ do fi done echo 'COMMIT;' >&3 - echo -e $'\r'"$destination: Renamed ${changedcount:-0} files\033[K" + (( cron )) || echo -n $'\r' + echo -n "$destination: Renamed ${changedcount:-0} files" + (( cron )) || echo -en "\033[K" + echo fi unset count changedcount renamefiles done @@ -810,7 +829,7 @@ echo ' SELECT "AtOM:NoMoreFiles"; ' >&3 -echo -n 'Removing obsolete files... ' +(( cron )) || echo -n 'Removing obsolete files... ' lines=() read -u4 line while [[ $line != AtOM:NoMoreFiles ]] @@ -831,10 +850,13 @@ do fi Update destination_files old_filename NULL <<<"id = $id" (( count++ )) - printf '\b\b\b\b%3i%%' $(( (100 * count) / ${#lines[@]} )) + (( cron )) || printf '\b\b\b\b%3i%%' $(( (100 * count) / ${#lines[@]} )) done echo 'COMMIT;' >&3 -echo -e "\rRemoved ${count:-0} obsolete files.\033[K" +(( cron )) || echo -n $'\r' +echo -n "Removed ${count:-0} obsolete files." +(( cron )) || echo -en "\033[K" +echo echo "Purging empty directories." for path in "${destinationpath[@]}" diff --git a/lib/copy/action b/lib/copy/action index 42a9823..95bbb4a 100644 --- a/lib/copy/action +++ b/lib/copy/action @@ -1,6 +1,6 @@ #!/bin/bash copyFiles_action() { - echo -n "Copying files... " + (( cron )) || echo -n "Copying files... " echo ' SELECT source_files.filename, @@ -85,9 +85,12 @@ copyFiles_action() { echo 'COMMIT;' >&3 if (( count )) then - echo -e "\rCopied ${done:-0} of $count files.\033[K" + (( cron )) || echo -n $'\r' + echo -n "Copied ${done:-0} of $count files." + (( cron )) || echo -en "\033[K" + echo else - echo -e "\rNothing to copy.\033[K" + (( cron )) || echo -e "\rNothing to copy.\033[K" fi unset count done } diff --git a/lib/files/getFiles b/lib/files/getFiles index 08a145f..cd79f5f 100644 --- a/lib/files/getFiles +++ b/lib/files/getFiles @@ -5,7 +5,7 @@ getFiles() { do prunes+="-path $sourcepath$prune_expression -prune -o " done - echo -n "Scanning $sourcepath... " + (( cron )) || echo -n "Scanning $sourcepath... " # We probably have thousands of files, don't waste time on disk writes echo 'BEGIN TRANSACTION;' >&3 while read time size filename @@ -59,6 +59,7 @@ getFiles() { find "$sourcepath" $prunes -type f -printf "%T@ %s %P\n" ) echo 'COMMIT;' >&3 - echo -e "\r${count:-0} files found, ${new:=0} new or changed." + (( cron )) || echo $'\r' + echo "${count:-0} files found, ${new:=0} new or changed." unset count } diff --git a/lib/tags/update b/lib/tags/update index 9881843..09af6e7 100644 --- a/lib/tags/update +++ b/lib/tags/update @@ -85,7 +85,8 @@ updateTags() { oldchannels=${rest%%::AtOM:SQL:Sep::*} rest=${rest#*::AtOM:SQL:Sep::} oldbitrate=${rest%%::AtOM:SQL:Sep::*} - echo -en "\rTags: $((++count*100/filecount))%" + ((++count)) + (( cron )) || echo -en "\rTags: $((count*100/filecount))%" if (( count % 1000 == 0 )) then echo 'COMMIT;BEGIN TRANSACTION;' >&3 @@ -153,6 +154,9 @@ updateTags() { fi done echo 'COMMIT;' >&3 - echo -e "\rRead tags from ${count:-0} files.\033[K" + (( cron )) || echo -n $'\r' + echo -n "Read tags from ${count:-0} files." + (( cron )) || echo -ne "\033[K" + echo unset count tagfiles } diff --git a/lib/tools/progressSpin b/lib/tools/progressSpin index cecff55..3cd54b8 100644 --- a/lib/tools/progressSpin +++ b/lib/tools/progressSpin @@ -1,10 +1,15 @@ #!/bin/bash progressSpin() { - case $(( ++count % 40 )) in - 0) echo -ne '\b|' ;; - 10) echo -ne '\b/' ;; - 20) echo -en '\b-' ;; - 30) echo -ne '\b\\' ;; - *) ;; - esac + if (( cron )) + then + (( ++count )) + else + case $(( ++count % 40 )) in + 0) echo -ne '\b|' ;; + 10) echo -ne '\b/' ;; + 20) echo -en '\b-' ;; + 30) echo -ne '\b\\' ;; + *) ;; + esac + fi }