From 8ba5a0f997aa0f24711a824dd5242d31d79a27fe Mon Sep 17 00:00:00 2001 From: Alain Reguera Delgado Date: Dec 28 2010 21:40:00 +0000 Subject: Update `path' functionality: - Update path_doCopy.sh to reflect changes inside texinfo documentation structure definition. - Update command-line arguments interpretation inside path_getActions.sh. - Remove `Define global variables' comment from path.sh. --- diff --git a/Scripts/Bash/Functions/Path/path.sh b/Scripts/Bash/Functions/Path/path.sh index 7c46af5..183625d 100755 --- a/Scripts/Bash/Functions/Path/path.sh +++ b/Scripts/Bash/Functions/Path/path.sh @@ -26,8 +26,6 @@ function path { - # Define global variables. - # Define command-line interface. path_getActions diff --git a/Scripts/Bash/Functions/Path/path_doCopy.sh b/Scripts/Bash/Functions/Path/path_doCopy.sh index 6a55174..e5fb6ca 100755 --- a/Scripts/Bash/Functions/Path/path_doCopy.sh +++ b/Scripts/Bash/Functions/Path/path_doCopy.sh @@ -28,73 +28,82 @@ function path_doCopy { local -a SRC local -a DST + local -a DOC local COUNT=0 - - # Define source locations. - SRC[0]=$SOURCE - SRC[1]=$(cli_getRepoDirParallel ${SRC[0]} "$(cli_getRepoTLDir)/Manuals/$(cli_getCurrentLocale)/Texinfo/Repository/$(cli_getRepoTLDir '--basename')").texi - SRC[2]=$(cli_getRepoDirParallel ${SRC[0]} "$(cli_getRepoTLDir)/Scripts/Bash/Functions/Render/Config") - SRC[3]=$(cli_getRepoDirParallel ${SRC[0]} "$(cli_getRepoTLDir)/Translations") - - # Define target locations. + + # Verify target variable. We can't continue if target is empty. + if [[ $TARGET == '' ]];then + cli_printMessage "`gettext "There is no target to work with."`" 'AsErrorLine' + cli_printMessage "$(caller)" 'AsToKnowMoreLine' + fi + + # Define source locations. Start with parent directory at position + # zero and continue with parent directory related parallel + # directories. + SRC[0]=$ACTIONVAL + SRC[1]=$(cli_getRepoDirParallel "${SRC[0]}" "$(cli_getRepoTLDir "${SRC[0]}")/Manuals/$(cli_getCurrentLocale)/Texinfo/Repository/$(cli_getRepoTLDir "${SRC[0]}" "--relative")").texi + SRC[2]=$(cli_getRepoDirParallel "${SRC[0]}" "$(cli_getRepoTLDir "${SRC[0]}")/Scripts/Bash/Functions/Render/Config") + SRC[3]=$(cli_getRepoDirParallel "${SRC[0]}" "$(cli_getRepoTLDir "${SRC[0]}")/Translations") + + # Define target locations. Start with parent directory at position + # zero and continue with parent directory related parallel + # directories. DST[0]=$TARGET - DST[1]=$(cli_getRepoDirParallel ${DST[0]} "$(cli_getRepoTLDir)/Manuals/$(cli_getCurrentLocale)/Texinfo/Repository/$(cli_getRepoTLDir '--basename')").texi - DST[2]=$(cli_getRepoDirParallel ${DST[0]} "$(cli_getRepoTLDir)/Scripts/Bash/Functions/Render/Config") - DST[3]=$(cli_getRepoDirParallel ${DST[0]} "$(cli_getRepoTLDir)/Translations") + DST[1]=$(cli_getRepoDirParallel "${DST[0]}" "$(cli_getRepoTLDir "${DST[0]}")/Manuals/$(cli_getCurrentLocale)/Texinfo/Repository/$(cli_getRepoTLDir "${DST[0]}" "--relative")").texi + DST[2]=$(cli_getRepoDirParallel "${DST[0]}" "$(cli_getRepoTLDir "${DST[0]}")/Scripts/Bash/Functions/Render/Config") + DST[3]=$(cli_getRepoDirParallel "${DST[0]}" "$(cli_getRepoTLDir "${DST[0]}")/Translations") + + # Define documentation files that need to be counted inside + # changes commited up to central repository. + DOC[0]=/home/centos/artwork/trunk/Manuals/$(cli_getCurrentLocale)/Texinfo/Repository/$(cli_getRepoTLDir "${DST[0]}" '--relative')/chapter-menu.texi + DOC[1]=/home/centos/artwork/trunk/Manuals/$(cli_getCurrentLocale)/Texinfo/Repository/$(cli_getRepoTLDir "${DST[0]}" '--relative')/chapter-nodes.texi # Syncronize changes between working copy and central repository. - cli_commitRepoChanges "${SRC[@]} ${DST[@]}" + cli_commitRepoChanges "${SRC[@]} ${DST[@]} ${DOC[@]}" - # Output entries affected by action. - cli_printMessage "`ngettext "The following entry will be created:" \ - "The following entries will be created:" \ - "${#DST[*]}"`" - while [[ $COUNT -lt ${#SRC[*]} ]];do + # Print preamble with affected entries. + cli_printMessage "`ngettext "The following entry will be created" \ + "The following entries will be created" "${#DST[*]}"`" + while [[ $COUNT -lt ${#DST[*]} ]];do + # Print affected entry. cli_printMessage "${DST[$COUNT]}" 'AsResponseLine' + # Increment counter. COUNT=$(($COUNT + 1)) done - # Request confirmation to perform action. - cli_printMessage "`gettext "Do you want to continue?"`" 'AsYesOrNoRequestLine' + # Request confirmation question to continue with action. + cli_printMessage "`gettext "Do you want to continue"`" 'AsYesOrNoRequestLine' # Reset counter. COUNT=0 - # Perform action. - while [[ $COUNT -lt ${#SRC[*]} ]];do - - cli_printMessage ${DST[$COUNT]} 'AsCreatingLine' + while [[ $COUNT -lt ${#DST[*]} ]];do - # Verify repository entry. We cannot duplicate an entry if its - # parent directory doesn't exist as entry inside the working - # copy. + # Verify relation between source and target locations. We + # cannot duplicate an entry if its parent directory doesn't + # exist as entry inside the working copy. if [[ -f ${SRC[$COUNT]} ]];then - if [[ -d $(dirname ${SRC[$COUNT]}) ]];then - if [[ ! -d $(dirname ${DST[$COUNT]}) ]];then - mkdir -p $(dirname ${DST[$COUNT]}) - svn add $(dirname ${DST[$COUNT]}) --quiet - fi - fi - elif [[ -d ${SRC[$COUNT]} ]];then - if [[ -d ${DST[$COUNT]} ]];then - cli_printMessage "`gettext "cannot create "` \`${DST[$COUNT]}': `gettext "Directory already exists."`" 'AsErrorLine' - cli_printMessage "$(caller)" 'AsToKnowMoreLine' + if [[ ! -d $(dirname ${DST[$COUNT]}) ]];then + mkdir -p $(dirname ${DST[$COUNT]}) + svn add $(dirname ${DST[$COUNT]}) --quiet fi fi - # Copy using subversion command. + # Print action message. + cli_printMessage "${DST[$COUNT]}" 'AsCreatingLine' + + # Perform action. svn copy ${SRC[$COUNT]} ${DST[$COUNT]} --quiet # Increase counter. COUNT=$(($COUNT + 1)) - done + done - # Update documentation chapter, menu and nodes inside Texinfo - # documentation structure. - . ~/bin/centos-art manual --update-structure=${DST[0]} + # Update texinfo documentation structure. + . /home/centos/bin/centos-art manual --update-structure="${DST[0]}" # Syncronize changes between working copy and central repository. - cli_commitRepoChanges "${DST[@]}" + cli_commitRepoChanges "${SRC[@]} ${DST[@]} ${DOC[@]}" } diff --git a/Scripts/Bash/Functions/Path/path_getActions.sh b/Scripts/Bash/Functions/Path/path_getActions.sh index ce25392..42ab140 100755 --- a/Scripts/Bash/Functions/Path/path_getActions.sh +++ b/Scripts/Bash/Functions/Path/path_getActions.sh @@ -1,7 +1,7 @@ #!/bin/bash # -# path_getActions.sh -- This function defines the command-line -# interface used to manipulate repository files. +# path_getActions.sh -- This function interpretes arguments passed to +# `path' functionality and calls actions accordingly. # # Copyright (C) 2009, 2010 Alain Reguera Delgado # @@ -26,14 +26,11 @@ function path_getActions { - # Define source location we are going to work with. - local SOURCE="$ACTIONVAL" - # Define short options we want to support. - local ARGSS="r:m:t:" + local ARGSS="" # Define long options we want to support. - local ARGSL="revision:,message:,to:" + local ARGSL="copy:,move:,delete:,to:" # Parse arguments using getopt(1) command parser. cli_doParseArguments @@ -42,59 +39,121 @@ function path_getActions { # parser. eval set -- "$ARGUMENTS" - # Define target locations using positonal parameters as - # reference. + # Define action to take for each option passed. while true; do case "$1" in - -t|--to ) - TARGET="$2" - cli_checkRepoDirTarget - shift 2 - ;; - * ) - break - esac - done - # Redefine positional parameters stored inside ARGUMENTS variable. - cli_doParseArgumentsReDef "$@" + --copy ) - # Parse positional parameters stored inside ARGUMENTS variable. - cli_doParseArguments + # Define action value passed through the command-line. + ACTIONVAL="$2" - # Evaluate action name and define which actions does centos-art.sh - # script supports. - while true; do - case "$ACTIONNAM" in + # Check action value passed through the command-line + # using source directory definition as reference. + cli_checkRepoDirSource - '--copy' ) - # Duplicate something in working copy or repository, - # remembering history. - path_doCopy - ;; + # Define action name using action value as reference. + ACTIONNAM="${FUNCNAM}_doCopy" - '--move' ) - # Move and/or rename something in working copy or - # repository. - # --- path_doMove - ;; + # Look for related sub-options. + while true; do + case "$3" in - '--delete' ) - # Remove files and directories from version control. - # --- path_doDelete + --to ) + + # Redefine target directory. + TARGET="$4" + + # Verify target directory. + cli_checkRepoDirTarget + + # Rotate positional parameters. + shift 4 + ;; + + * ) + # Break sub-options loop. + break + ;; + esac + done + + # Break options loop. + break ;; - - '--sync' ) - # Syncronize parallel dirctories with parent directory. - # --- path_doSync + + --move ) + + # Define action value passed through the command-line. + ACTIONVAL="$2" + + # Check action value passed through the command-line + # using source directory definition as reference. + cli_checkRepoDirSource + + # Define action name using action value as reference. + ACTIONNAM="${FUNCNAM}_doMove" + + # Look for related sub-options. + while true; do + case "$3" in + + --to ) + + # Redefine target directory. + TARGET="$4" + + # Verify target directory. + cli_checkRepoDirTarget + + # Rotate positional parameters. + shift 4 + ;; + + * ) + # Break sub-options loop. + break + ;; + esac + done + + # Break options loop. + break ;; - * ) - cli_printMessage "`gettext "The action provided is not valid."`" 'AsErrorLine' - cli_printMessage "$(caller)" 'AsToKnowMoreLine' + --delete ) + + # Define action value passed through the command-line. + ACTIONVAL="$2" + + # Check action value passed through the command-line + # using source directory definition as reference. + cli_checkRepoDirSource + + # Define action name using action value as reference. + ACTIONNAM="${FUNCNAM}_doDelete" + + # Break options loop. + break ;; + * ) + # Break options loop. + break esac done - + + # Verify action value variable. + if [[ $ACTIONVAL == '' ]];then + cli_printMessage "$(caller)" 'AsToKnowMoreLine' + fi + + # Execute action name. + if [[ $ACTIONNAM =~ "^${FUNCNAM}_[A-Za-z]+$" ]];then + eval $ACTIONNAM + else + cli_printMessage "`gettext "A valid action is required."`" 'AsErrorLine' + cli_printMessage "$(caller)" 'AsToKnowMoreLine' + fi + }