Add "cron" mode (suppress most progress info)

This commit is contained in:
Vincent Riquer 2013-09-28 00:09:02 +02:00
parent 178f6a82af
commit 5e006ae7cc
5 changed files with 69 additions and 34 deletions

62
atom
View File

@ -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[@]}"

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}