Blob Blame History Raw
#!/bin/bash
#
# manual_deleteEntry.sh -- This function removes a documentation entry
# from documentation directory structure.
#
# Copyright (C) 2009-2011 Alain Reguera Delgado
# 
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
# USA.
# 
# ----------------------------------------------------------------------
# $Id$
# ----------------------------------------------------------------------

function manual_deleteEntry {

    local ENTRIES=''
    local ENTRYSTATUS=''
    local LOCATION=''

    # Check if the entry has been already removed.
    cli_checkFiles $ENTRY 'f'

    # Define root location to look for entries.
    LOCATION=$(echo $ENTRY | sed -r 's!\.texi$!!')

    # Redefine location to match the chapter's root directory. This
    # applies when you try to remove the whole chapter from the
    # working copy (e.g., centos-art manual --delete=/home/centos/artwork/trunk/).
    if [[ $ENTRY =~ "chapter-intro\.texi$" ]];then
        LOCATION=$(dirname "$ENTRY")
    fi

    # Define list of dependent entries. Dependent entries are stored
    # inside a directory with the same name of the entry you are
    # trying to remove. If such directory location doesn't exists, the
    # related entry doesn't have dependent entries either.
    if [[ -d $LOCATION ]];then
        ENTRIES=$(cli_getFilesList $LOCATION ".*\.texi")
    fi
    
    # Add entry being currently processed to list of files to precess.
    ENTRIES="${ENTRIES} ${ENTRY}"

    # Remove duplicated lines from entries list, be sure there is just
    # one path per line and they are ordered in reverse. At this
    # point, it is hard to find duplicated lines since the list of
    # entries is built from files and it is not possible to have two
    # files in the very same directory using the same name exactly, so
    # this could be considered a bit paranoid. ~:-)
    ENTRIES=$(echo "$ENTRIES" | tr ' ' "\n" | sort -r | uniq)

    # Print action preamble.
    cli_printActionPreamble "$ENTRIES" 'doDelete' 'AsResponseLine'

    # Process list of entries.
    for ENTRY in $ENTRIES;do

        # Define the versioning status of entry.
        if [[ -d $(dirname $ENTRY)/.svn ]];then
            ENTRYSTATUS=$(cli_getRepoStatus "$ENTRY")
        else
            # At this point we don't know what the entry versioning
            # status is, so consider the entry an unversion file.
            ENTRYSTATUS='?'
        fi

        # Verify entry inside the working copy. 
        if [[ "$ENTRYSTATUS" =~ '^(\?)?$' ]];then

            # Print action message.
            cli_printMessage "$ENTRY" "AsDeletingLine"

        else

            # Do not remove a versioned documentation entry with
            # changes inside. Print a message about it and stop script
            # execution instead.
            cli_printMessage "`gettext "There are changes that need to be committed first."`" 'AsErrorLine'
            cli_printMessage "$(caller)" 'AsToKnowMoreLine'

        fi

        # Remove documentation entry. At this point, documentation
        # entry can be under version control or not versioned at all.
        # Here we need to decide how to remove documentation entries
        # based on whether they are under version control or not.
        if [[ "$ENTRYSTATUS" == ' ' ]];then

            # Documentation entry is under version control and there
            # is no change to be committed up to central repository.
            # We are safe to schedule it for deletion.
            svn del "$ENTRY" --quiet

        elif [[ "$ENTRYSTATUS" == '?' ]];then

            # Documentation entry is not under version control, so we
            # don't care about changes inside it. If you say
            # centos-art.sh script to remove an unversion
            # documentation entry it will do so, using convenctional
            # `rm' command.
            rm -r "$ENTRY"

        fi

        # Remove entry on section's menu and nodes to reflect the
        # fact that documentation entry has been removed.
        manual_updateMenu "remove-entry"
        manual_updateNodes

        # Remove entry cross references from documentation manual.
        manual_deleteCrossReferences

    done
 
    # Update chapter's menu and nodes in the master texinfo document.
    # This is mainly applied when one of the chapters (e.g., trunk/,
    # tags/, or branches/) is removed.
    if [[ ! -d $MANUAL_DIR_CHAPTER ]];then
        manual_updateChaptersMenu 'remove-entry'
        manual_updateChaptersNodes
    fi

    # Update documentation output-related files.
    manual_updateOutputFiles

}