From e9cb243a24785f2142e19a9ba0dc75232eb39baf Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Sat, 13 Jun 2009 19:17:21 +0200 Subject: [PATCH] Replace the convert_0.2-0.3.sh script by convert_0.3-0.4.sh. --- convert_0.2-0.3.sh | 186 -------------------------------------- convert_0.3-0.4.sh | 221 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 221 insertions(+), 186 deletions(-) delete mode 100755 convert_0.2-0.3.sh create mode 100755 convert_0.3-0.4.sh diff --git a/convert_0.2-0.3.sh b/convert_0.2-0.3.sh deleted file mode 100755 index 24c937b9..00000000 --- a/convert_0.2-0.3.sh +++ /dev/null @@ -1,186 +0,0 @@ -#!/usr/bin/env bash - -#------------------------------------------------------------------------------- -## Script to convert the database of paraslash 0.2.x to version 0.3.x. -## -## Assumptions: -## - para_server 0.2.x is running and the mysql selector is active -## - para_server 0.3.x is running on another port -## - The database of paraslash 0.3.x has been initialized (i.e. -## para_client init has successfully been executed) -## - All audio files in the mysql database of paraslash 0.2.x. have -## already been added to the 0.3.x database (execute para_client add -## /my/audio/file/dir to do that) -## -## The script converts the attribute table, the set attributes for each audio -## file, the image table and all image ids, and finally the lastplayed and the -## numplayed data. -## -## However, it does not convert the paraslash stream definitions from 0.2.x to -## the moods of 0.3.x. You'll have to do this by hand. -#------------------------------------------------------------------------------- - -# Call this script without arguments to see usage info - -# How to connect to para_server 0.2.x. -client02=/usr/local/bin/para_client -port02=2991 -host02=localhost - -# How to connect to para_server 0.3.x. -client03=./para_client -port03=2990 -host03=localhost - -# Unset this to deactivate messages -debug=1 - - -client02_cmd="$client02 -p $port02 -i $host02" -client03_cmd="$client03 -p $port03 -i $host03" - -info_log() -{ - if test $debug -eq 1; then - echo "$@" - fi -} - -exec_client02_cmd() -{ - info_log "$client02_cmd -- $@" - result="$($client02_cmd -- "$@")" -} - -exec_client03_cmd() -{ - info_log "$client03_cmd -- $@" - result="$($client03_cmd -- "$@")" -} - -convert_attribute_table() -{ - local atts - exec_client02_cmd laa - atts="$result" - info_log "creating attributes: $atts" - exec_client03_cmd addatt $atts -} - -convert_attributes() -{ - local att atts current_atts cmd query="select dir.dir, dir.name" - exec_client02_cmd laa - atts="$result" - for att in $atts; do - query="$query, data.$att" - done - query="$query from dir,data where dir.name=data.name" - exec_client02_cmd verb "$query" - echo "$result" | while read dir name current_atts; do - cmd="setatt " - for att in $atts; do - if test "${current_atts#0}" = "$current_atts"; then - cmd="$cmd $att+" - current_atts=${current_atts#1 } - else - current_atts=${current_atts#0 } - fi - done - if test "$cmd" = "setatt "; then - continue - fi - exec_client03_cmd $cmd "$dir/$name" - done -} - -convert_lastplayed_numplayed() -{ - local query="select dir.dir, dir.name, unix_timestamp(data.lastplayed), data.numplayed from dir,data where data.name=dir.name" - local lp np data dir name - exec_client02_cmd verb "$query" - data="$result" - echo "$result" | while read dir name lp np; do - cmd="touch -n$np -l$lp $dir/$name" - exec_client03_cmd $cmd - done -} - -convert_image_table() -{ - local num size name - exec_client02_cmd piclist; - echo "$result" | while read num size name; do - info_log "converting $name" - $client02_cmd -- pic "#$num" | $client03_cmd -- addimg "$name" - done -} - -convert_image_ids() -{ - local query="select dir.dir, dir.name, pics.name from dir,data,pics where data.name=dir.name and pics.id=data.pic_id" - local img_ids_03 dir name img id - exec_client03_cmd lsimg -l - img_ids_03="$result" - exec_client02_cmd verb "$query" - echo "$result" | while read dir name img; do - id="$(echo "$img_ids_03" | grep " $img\$" | cut -f 1)" - exec_client03_cmd touch "-i$id" "$dir/$name" - done -} - - -usage() -{ - grep '^##' $0 | sed -e 's/^## *//' - echo ' -Usage: $0 command - -command is one of the following: - - attribute_table: create attributes - attributes: convert attributes for each audio file - lastplayed_numplayed: convert numplayed and lastplayed - data of each audio file - image_table: retrieve images from mysql and add them to the database - of paraslash-0.3.x - image_ids: convert image id of each audio file. - all: Do all of the above. - -Edit the top of the script to customize some options. -' -} - -if test $# -ne 1; then - usage - exit 1 -fi - -case "$1" in -attribute_table) - convert_attribute_table - ;; -attributes) - convert_attributes - ;; -lastplayed_numplayed) - convert_lastplayed_numplayed - ;; -image_table) - convert_image_table - ;; -image_ids) - convert_image_ids - ;; -all) - convert_attribute_table - convert_attributes - convert_lastplayed_numplayed - convert_image_table - convert_image_ids - ;; -*) - usage - exit 1 - ;; -esac diff --git a/convert_0.3-0.4.sh b/convert_0.3-0.4.sh new file mode 100755 index 00000000..aa0b239f --- /dev/null +++ b/convert_0.3-0.4.sh @@ -0,0 +1,221 @@ +#!/usr/bin/env bash + +#------------------------------------------------------------------------------- +## Script to convert the database of paraslash 0.3.5 to version 0.4.x. +## +## Assumptions: +## - para_server 0.3.5 is running +## - "para_client check" reports no errors +## - para_server 0.4.x is running, listens on another port and uses a +## different afs database and a different afs socket +## - The database of paraslash 0.4.x has been initialized (i.e. +## para_client init has successfully been executed) +## - All audio files in the 0.3.x database have already been added to +## the 0.4.x database (execute para_client add /my/audio/file/dir to +## do that) +## +#------------------------------------------------------------------------------- + +# Call this script without arguments to see usage info + +# How to connect to para_server 0.3.x. +client03=/usr/local/bin/para_client +port03=2991 +host03=localhost +database03=$HOME/.paraslash/afs_database + +# How to connect to para_server 0.4.x. +client04=$(pwd)/para_client +port04=2990 +host04=localhost +database04=$HOME/.paraslash/afs_database-0.4 + +# Any character that does not occur in any filename of an audio file +sep='|' + + +client03_cmd="$client03 -p $port03 -i $host03" +client04_cmd="$client04 -p $port04 -i $host04" + +exec_client03_cmd() +{ + result="$($client03_cmd -- "$@")" +} + +exec_client04_cmd() +{ + result="$($client04_cmd -- "$@")" +} + +convert_attribute_table() +{ + local atts + + echo "converting attribute table" + exec_client03_cmd lsatt + atts="$result" + exec_client04_cmd addatt $atts +} + +convert_attributes() +{ + local OIFS="$IFS" a p att atts + + printf "converting attributes: " + $client03_cmd -- ls -p -lv \ + | grep '^path:\|^attributes_txt:' \ + | sed -e "/^path:/N;s/\n/$sep/1" \ + | { + IFS="$sep" + while read p a; do + p=${p#path: } + a=${a#attributes_txt:} + IFS=" " + atts= + for att in $a; do + atts="$atts $att+" + done + IFS="$OIFS" + [[ -n "$atts" ]] && $client04_cmd -- setatt $atts "$p" + IFS="$sep" + printf "." + done + echo done + } + IFS="$OIFS" +} + +convert_lna() +{ + local OIFS="$IFS" p l n a + + printf "converting last_played, num_played, amplification values: " + $client03_cmd -- ls -p -d -lv \ + | grep '^path:\|^last_played: \|^num_played: \|^amplification: ' \ + | sed -e "/^path:/N;N;N;s/\n/$sep/g" \ + | { + IFS="$sep" + while read p l n a; do + #echo "p: $p, l:$l, n:$n a:$a" + p=${p#path: } + l=${l#last_played: } + n=${n#num_played: } + a=${a#amplification: } + IFS="$OIFS" + $client04_cmd -- touch "-l$l" "-n$n" "-a$a" "$p" + IFS="$sep" + printf "." + done + echo done + } + IFS="$OIFS" +} + +convert_blobs() +{ + local blob name + + for blob in img lyr mood pl; do + printf "converting $blob table: " + exec_client03_cmd ls$blob + echo "$result" | while read name; do + $client03_cmd -- cat$blob "$name" | $client04_cmd -- add$blob "$name" + printf "." + done + echo done + done +} + +convert_ids() +{ + local OIFS="$IFS" p i y iopts yopts + + printf "converting image and lyrics ids: " + $client03_cmd -- ls -p -lv \ + | grep '^path:\|^image_name: \|^lyrics_name: ' \ + | sed -e "/^path:/N;N;s/\n/$sep/g" \ + | { + IFS="$sep" + while read p i l; do + IFS="$OIFS" + iopts= + yopts= + p=${p#path: } + i=${i#image_name: } + l=${l#lyrics_name: } + if [[ "$i" != '(none)' ]]; then + exec_client04_cmd lsimg -l "$i" + iopts="-i${result%% *}" + fi + if [[ "$l" != '(none)' ]]; then + exec_client04_cmd lslyr -l "$l" + yopts="-y${result%% *}" + fi + if [[ -n "$iopts" && -n "$yopts" ]]; then + $client04_cmd -- touch "$iopts" "$yopts" "$p" + elif [[ -n "$iopts" ]]; then + $client04_cmd -- touch "$iopts" "$p" + elif [[ -n "$yopts" ]]; then + $client04_cmd -- touch "$yopts" "$p" + fi + printf "." + IFS="$sep" + done + echo done + } + IFS="$OIFS" +} + + +usage() +{ + grep '^##' $0 | sed -e 's/^## *//' + echo ' +Usage: $0 command + +command is one of the following: + + attribute_table: create attributes + attributes: convert attributes for each audio file + lna: convert the last_played/num_played/amplification values + blobs: convert the image/lyrics/moods/playlists tables + ids: convert image and the lyrics id of each audio file. + all: Do all of the above. + +Edit the top of the script to customize some options. +' +} + +if test $# -ne 1; then + usage + exit 1 +fi + +case "$1" in +attribute_table) + convert_attribute_table + ;; +attributes) + convert_attributes + ;; +lna) + convert_lna + ;; +blobs) + convert_blobs + ;; +ids) + convert_ids + ;; +all) + convert_attribute_table + convert_attributes + convert_lna + convert_blobs + convert_ids + ;; +*) + usage + exit 1 + ;; +esac -- 2.39.2