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.
45e570
    if [[ ${#ACTIONVALS[*]} -lt 2 ]];then
45e570
        cli_printMessage "`gettext "Two paths are required."`" --as-error-line
45e570
    elif [[ ${#ACTIONVALS[*]} -gt 2 ]];then
45e570
        cli_printMessage "`gettext "Only two paths are supported."`" --as-error-line
45e570
    fi
45e570
45e570
    # Define source documentation entry. This is the documentation
45e570
    # entry that will be duplicated.
45e570
    local ENTRY_SRC=$(${FLAG_BACKEND}_getEntry ${ACTIONVALS[0]})
45e570
45e570
    # Define directory where documentation entries are stored in.
45e570
    local MANUAL_CHAPTER_DIR=$(${FLAG_BACKEND}_getChapterDir "$ENTRY_SRC")
45e570
45e570
    # Syncronize changes between repository and working copy. At this
45e570
    # point, changes in the repository are merged in the working copy
45e570
    # and changes in the working copy committed up to repository.
45e570
    cli_syncroRepoChanges ${MANUAL_CHAPTER_DIR}
45e570
b182ba
    # Print separator line.
18be6e
    cli_printMessage '-' --as-separator-line
b182ba
45e570
    # Define target documentation entry. This is the new documentation
45e570
    # entry created from the source documentation entry.
45e570
    local ENTRY_DST=$(${FLAG_BACKEND}_getEntry "${ACTIONVALS[1]}")
a484de
45e570
    # Verify parent directory of target documentation entry. If it
45e570
    # doesn't exist, create it and add it to version control.
608fb4
    if [[ ! -d $(dirname ${ENTRY_DST}) ]];then
608fb4
        mkdir -p $(dirname ${ENTRY_DST})
608fb4
        svn add $(dirname ${ENTRY_DST}) --quiet
608fb4
    fi
608fb4
45e570
    # Copy source documentation entry to target documentation entry.
45e570
    if [[ -f ${ENTRY_SRC} ]];then
45e570
        if [[ ! -f ${ENTRY_DST} ]];then
45e570
            cli_printMessage "${ENTRY_DST}" --as-creating-line
45e570
            svn cp "${ENTRY_SRC}" "${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.
45e570
    ENTRY_SRC=$(echo ${ENTRY_SRC} | sed -r "s/\.${FLAG_BACKEND}$//")
66b6ae
    ENTRY_DST=$(echo ${ENTRY_DST} | sed -r "s/\.${FLAG_BACKEND}$//")
7dc6cc
a484de
    # Copy dependent documentation entries, if any.
45e570
    if [[ -d ${ENTRY_SRC} ]];then
45e570
        if [[ ! -a ${ENTRY_DST} ]];then
45e570
            cli_printMessage "${ENTRY_DST}" --as-creating-line
45e570
            svn cp "${ENTRY_SRC}" "${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
45e570
45e570
    # Define list of target documentation entries.
45e570
    local ENTRY=''
45e570
    local ENTRIES=$(cli_getFilesList $(dirname ${ENTRY_DST}) --pattern=".*$(basename ${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).
7dc6cc
    for ENTRY in ${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
45e570
    # Commit changes from working copy to central repository only.  At
45e570
    # this point, changes in the repository are not merged in the
45e570
    # working copy, but chages in the working copy do are committed up
45e570
    # to repository.
45e570
    cli_commitRepoChanges ${MANUAL_CHAPTER_DIR}
45e570
2bd980
}