Blame Scripts/Functions/Help/Backends/Texinfo/texinfo_copyEntry.sh

2bd980
#!/bin/bash
2bd980
#
45e570
# texinfo_copyEntry.sh -- This function copies documentation entries
45e570
# inside the working copy and updates the documentation structure to
45e570
# reflect the changes.
2bd980
#
2d3646
# Copyright (C) 2009, 2010, 2011 The CentOS Project
fa95b1
#
fa95b1
# This program is free software; you can redistribute it and/or modify
fa95b1
# it under the terms of the GNU General Public License as published by
dcd347
# the Free Software Foundation; either version 2 of the License, or (at
dcd347
# your option) any later version.
fa95b1
#
74a058
# This program is distributed in the hope that it will be useful, but
74a058
# WITHOUT ANY WARRANTY; without even the implied warranty of
2bd980
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
2bd980
# General Public License for more details.
2bd980
#
2bd980
# You should have received a copy of the GNU General Public License
2bd980
# along with this program; if not, write to the Free Software
dcd347
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
7ac5a5
#
2bd980
# ----------------------------------------------------------------------
2bd980
# $Id$
2bd980
# ----------------------------------------------------------------------
2bd980
1afa3c
function texinfo_copyEntry {
56f126
45e570
    # Verify number of non-option arguments passed to centos-art.sh
45e570
    # script.
b45dde
    if [[ $# -lt 2 ]];then
45e570
        cli_printMessage "`gettext "Two paths are required."`" --as-error-line
b45dde
    elif [[ $# -gt 2 ]];then
45e570
        cli_printMessage "`gettext "Only two paths are supported."`" --as-error-line
45e570
    fi
45e570
b182ba
    # Print separator line.
18be6e
    cli_printMessage '-' --as-separator-line
b182ba
b45dde
    # Define source documentation entry. This is the documentation
b45dde
    # entry that will be duplicated.
efaf25
    local MANUAL_ENTRY_SRC=$(${FLAG_BACKEND}_getEntry "${1}")
b45dde
45e570
    # Define target documentation entry. This is the new documentation
45e570
    # entry created from the source documentation entry.
efaf25
    local MANUAL_ENTRY_DST=$(${FLAG_BACKEND}_getEntry "${2}")
a484de
45e570
    # Verify parent directory of target documentation entry. If it
45e570
    # doesn't exist, create it and add it to version control.
efaf25
    if [[ ! -d $(dirname ${MANUAL_ENTRY_DST}) ]];then
efaf25
        mkdir -p $(dirname ${MANUAL_ENTRY_DST})
efaf25
        svn add $(dirname ${MANUAL_ENTRY_DST}) --quiet
608fb4
    fi
608fb4
45e570
    # Copy source documentation entry to target documentation entry.
efaf25
    if [[ -f ${MANUAL_ENTRY_SRC} ]];then
efaf25
        if [[ ! -f ${MANUAL_ENTRY_DST} ]];then
efaf25
            cli_printMessage "${MANUAL_ENTRY_DST}" --as-creating-line
efaf25
            svn cp "${MANUAL_ENTRY_SRC}" "${MANUAL_ENTRY_DST}" --quiet
45e570
        else
45e570
            cli_printMessage "`gettext "The target location is not valid."`" --as-error-line
45e570
        fi
45e570
    else
45e570
        cli_printMessage "`gettext "The source location is not valid."`" --as-error-line
7dc6cc
    fi
56f126
45e570
    # Redefine both source and target locations to refer the directory
45e570
    # where dependent documentation entries are stored in.
efaf25
    MANUAL_ENTRY_SRC=$(echo ${MANUAL_ENTRY_SRC} | sed -r "s/\.${FLAG_BACKEND}$//")
efaf25
    MANUAL_ENTRY_DST=$(echo ${MANUAL_ENTRY_DST} | sed -r "s/\.${FLAG_BACKEND}$//")
7dc6cc
a484de
    # Copy dependent documentation entries, if any.
efaf25
    if [[ -d ${MANUAL_ENTRY_SRC} ]];then
efaf25
        if [[ ! -a ${MANUAL_ENTRY_DST} ]];then
efaf25
            cli_printMessage "${MANUAL_ENTRY_DST}" --as-creating-line
efaf25
            svn cp "${MANUAL_ENTRY_SRC}" "${MANUAL_ENTRY_DST}" --quiet
45e570
        fi
7dc6cc
    fi
45e570
45e570
    # Define list of target documentation entries.
efaf25
    local MANUAL_ENTRY=''
efaf25
    local MANUAL_ENTRIES=$(cli_getFilesList \
efaf25
        $(dirname ${MANUAL_ENTRY_DST}) \
efaf25
        --pattern=".*$(basename ${MANUAL_ENTRY_DST}).*\.${FLAG_BACKEND}")
56f126
a484de
    # Print separator line.
18be6e
    cli_printMessage '-' --as-separator-line
a484de
a484de
    # Print action message.
45e570
    cli_printMessage "`gettext "Updating menus, nodes and cross-references."`" --as-response-line
a484de
45e570
    # Loop through target documentation entries in order to update
45e570
    # the documentation structure (e.g., It is not enough with copying
45e570
    # documentation entry files, it is also needed to update menu,
45e570
    # nodes and related cross-references).
efaf25
    for MANUAL_ENTRY in ${MANUAL_ENTRIES};do
2bd980
7dc6cc
        # Update menu and node definitions from manual sections to
7dc6cc
        # reflect the changes.
45e570
        ${FLAG_BACKEND}_updateMenu
45e570
        ${FLAG_BACKEND}_updateNodes
2bd980
7dc6cc
        # Update cross reference definitions from manual to reflect
7dc6cc
        # the changes.
45e570
        ${FLAG_BACKEND}_restoreCrossReferences
2bd980
7dc6cc
    done
2bd980
2bd980
}