Blame Scripts/Bash/centos-art/Functions/Manual/manual_deleteEntry.sh

4c79b5
#!/bin/bash
4c79b5
#
742c46
# manual_deleteEntry.sh -- This function removes a documentation entry
5285d6
# from documentation directory structure.
4c79b5
#
9f5f2e
# Copyright (C) 2009-2011 Alain Reguera Delgado
4c79b5
# 
7cd8e9
# This program is free software; you can redistribute it and/or
7cd8e9
# modify it under the terms of the GNU General Public License as
7cd8e9
# published by the Free Software Foundation; either version 2 of the
7cd8e9
# License, or (at your option) any later version.
4c79b5
# 
4c79b5
# This program is distributed in the hope that it will be useful, but
4c79b5
# WITHOUT ANY WARRANTY; without even the implied warranty of
4c79b5
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
4c79b5
# General Public License for more details.
4c79b5
#
4c79b5
# You should have received a copy of the GNU General Public License
4c79b5
# along with this program; if not, write to the Free Software
4c79b5
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
4c79b5
# USA.
4c79b5
# 
4c79b5
# ----------------------------------------------------------------------
418249
# $Id$
4c79b5
# ----------------------------------------------------------------------
4c79b5
742c46
function manual_deleteEntry {
4c79b5
4c79b5
    local ENTRIES=''
5285d6
    local ENTRYSTATUS=''
4c79b5
    local LOCATION=''
4c79b5
4c79b5
    # Check if the entry has been already removed.
638bf8
    cli_checkFiles $ENTRY 'f'
4c79b5
4c79b5
    # Define root location to look for entries.
4c79b5
    LOCATION=$(echo $ENTRY | sed -r 's!\.texi$!!')
4c79b5
638bf8
    # Redefine location to match the chapter's root directory. This
4c79b5
    # applies when you try to remove the whole chapter from the
638bf8
    # working copy (e.g., centos-art manual --delete=/home/centos/artwork/trunk/).
5285d6
    if [[ $ENTRY =~ "chapter-intro\.texi$" ]];then
919fda
        LOCATION=$(dirname "$ENTRY")
4c79b5
    fi
4c79b5
5285d6
    # Define list of dependent entries. Dependent entries are stored
5285d6
    # inside a directory with the same name of the entry you are
5285d6
    # trying to remove. If such directory location doesn't exists, the
5285d6
    # related entry doesn't have dependent entries either.
4c79b5
    if [[ -d $LOCATION ]];then
5285d6
        ENTRIES=$(cli_getFilesList $LOCATION ".*\.texi")
4c79b5
    fi
5285d6
    
5285d6
    # Add entry being currently processed to list of files to precess.
5285d6
    ENTRIES="${ENTRIES} ${ENTRY}"
5285d6
5285d6
    # Remove duplicated lines from entries list, be sure there is just
5285d6
    # one path per line and they are ordered in reverse. At this
5285d6
    # point, it is hard to find duplicated lines since the list of
5285d6
    # entries is built from files and it is not possible to have two
5285d6
    # files in the very same directory using the same name exactly, so
5285d6
    # this could be considered a bit paranoid. ~:-)
4c79b5
    ENTRIES=$(echo "$ENTRIES" | tr ' ' "\n" | sort -r | uniq)
4c79b5
638bf8
    # Print action preamble.
638bf8
    cli_printActionPreamble "$ENTRIES" 'doDelete' 'AsResponseLine'
638bf8
5285d6
    # Process list of entries.
4c79b5
    for ENTRY in $ENTRIES;do
4c79b5
5285d6
        # Define the versioning status of entry.
5285d6
        if [[ -d $(dirname $ENTRY)/.svn ]];then
5285d6
            ENTRYSTATUS=$(cli_getRepoStatus "$ENTRY")
5285d6
        else
5285d6
            # At this point we don't know what the entry versioning
5285d6
            # status is, so consider the entry an unversion file.
5285d6
            ENTRYSTATUS='?'
5285d6
        fi
5285d6
638bf8
        # Verify entry inside the working copy. 
5285d6
        if [[ "$ENTRYSTATUS" =~ '^(\?)?$' ]];then
4c79b5
638bf8
            # Print action message.
638bf8
            cli_printMessage "$ENTRY" "AsDeletingLine"
638bf8
638bf8
        else
4c79b5
638bf8
            # Do not remove a versioned documentation entry with
638bf8
            # changes inside. Print a message about it and stop script
638bf8
            # execution instead.
125fdf
            cli_printMessage "`gettext "There are changes that need to be committed first."`" 'AsErrorLine'
638bf8
            cli_printMessage "$(caller)" 'AsToKnowMoreLine'
638bf8
638bf8
        fi
4c79b5
4456e8
        # Remove documentation entry. At this point, documentation
4456e8
        # entry can be under version control or not versioned at all.
4456e8
        # Here we need to decide how to remove documentation entries
476434
        # based on whether they are under version control or not.
5285d6
        if [[ "$ENTRYSTATUS" == ' ' ]];then
4456e8
638bf8
            # Documentation entry is under version control and there
d2b9ba
            # is no change to be committed up to central repository.
d2b9ba
            # We are safe to schedule it for deletion.
f8fb31
            svn del "$ENTRY" --quiet
4456e8
5285d6
        elif [[ "$ENTRYSTATUS" == '?' ]];then
4456e8
4456e8
            # Documentation entry is not under version control, so we
638bf8
            # don't care about changes inside it. If you say
638bf8
            # centos-art.sh script to remove an unversion
638bf8
            # documentation entry it will do so, using convenctional
638bf8
            # `rm' command.
638bf8
            rm -r "$ENTRY"
4456e8
4456e8
        fi
4456e8
f8fb31
        # Remove entry on section's menu and nodes to reflect the
f8fb31
        # fact that documentation entry has been removed.
4de5d4
        manual_updateMenu "remove-entry"
4de5d4
        manual_updateNodes
4456e8
f8fb31
        # Remove entry cross references from documentation manual.
742c46
        manual_deleteCrossReferences
f8fb31
4456e8
    done
4456e8
 
4456e8
    # Update chapter's menu and nodes in the master texinfo document.
4456e8
    # This is mainly applied when one of the chapters (e.g., trunk/,
4456e8
    # tags/, or branches/) is removed.
5285d6
    if [[ ! -d $MANUAL_DIR_CHAPTER ]];then
4de5d4
        manual_updateChaptersMenu 'remove-entry'
4de5d4
        manual_updateChaptersNodes
4c79b5
    fi
4c79b5
5285d6
    # Update documentation output-related files.
5285d6
    manual_updateOutputFiles
5285d6
4c79b5
}