Blob Blame History Raw
#!/bin/bash
#
# texinfo_copyEntry.sh -- This function copies documentation entries
# inside the working copy and updates the documentation structure to
# reflect the changes.
#
# Copyright (C) 2009, 2010, 2011 The CentOS Project
#
# 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., 675 Mass Ave, Cambridge, MA 02139, USA.
#
# ----------------------------------------------------------------------
# $Id$
# ----------------------------------------------------------------------

function texinfo_copyEntry {

    # Verify number of non-option arguments passed to centos-art.sh
    # script.
    if [[ ${#ACTIONVALS[*]} -lt 2 ]];then
        cli_printMessage "`gettext "Two paths are required."`" --as-error-line
    elif [[ ${#ACTIONVALS[*]} -gt 2 ]];then
        cli_printMessage "`gettext "Only two paths are supported."`" --as-error-line
    fi

    # Define source documentation entry. This is the documentation
    # entry that will be duplicated.
    local ENTRY_SRC=$(${FLAG_BACKEND}_getEntry ${ACTIONVALS[0]})

    # Define directory where documentation entries are stored in.
    local MANUAL_CHAPTER_DIR=$(${FLAG_BACKEND}_getChapterDir "$ENTRY_SRC")

    # Syncronize changes between repository and working copy. At this
    # point, changes in the repository are merged in the working copy
    # and changes in the working copy committed up to repository.
    cli_syncroRepoChanges ${MANUAL_CHAPTER_DIR}

    # Print separator line.
    cli_printMessage '-' --as-separator-line

    # Define target documentation entry. This is the new documentation
    # entry created from the source documentation entry.
    local ENTRY_DST=$(${FLAG_BACKEND}_getEntry "${ACTIONVALS[1]}")

    # Verify parent directory of target documentation entry. If it
    # doesn't exist, create it and add it to version control.
    if [[ ! -d $(dirname ${ENTRY_DST}) ]];then
        mkdir -p $(dirname ${ENTRY_DST})
        svn add $(dirname ${ENTRY_DST}) --quiet
    fi

    # Copy source documentation entry to target documentation entry.
    if [[ -f ${ENTRY_SRC} ]];then
        if [[ ! -f ${ENTRY_DST} ]];then
            cli_printMessage "${ENTRY_DST}" --as-creating-line
            svn cp "${ENTRY_SRC}" "${ENTRY_DST}" --quiet
        else
            cli_printMessage "`gettext "The target location is not valid."`" --as-error-line
        fi
    else
        cli_printMessage "`gettext "The source location is not valid."`" --as-error-line
    fi

    # Redefine both source and target locations to refer the directory
    # where dependent documentation entries are stored in.
    ENTRY_SRC=$(echo ${ENTRY_SRC} | sed -r "s/\.${FLAG_BACKEND}$//")
    ENTRY_DST=$(echo ${ENTRY_DST} | sed -r "s/\.${FLAG_BACKEND}$//")

    # Copy dependent documentation entries, if any.
    if [[ -d ${ENTRY_SRC} ]];then
        if [[ ! -a ${ENTRY_DST} ]];then
            cli_printMessage "${ENTRY_DST}" --as-creating-line
            svn cp "${ENTRY_SRC}" "${ENTRY_DST}" --quiet
        else
            cli_printMessage "`gettext "The target location is not valid."`" --as-error-line
        fi
    else
        cli_printMessage "`gettext "The source location is not valid."`" --as-error-line
    fi

    # Define list of target documentation entries.
    local ENTRY=''
    local ENTRIES=$(cli_getFilesList $(dirname ${ENTRY_DST}) --pattern=".*$(basename ${ENTRY_DST}).*\.${FLAG_BACKEND}")

    # Print separator line.
    cli_printMessage '-' --as-separator-line

    # Print action message.
    cli_printMessage "`gettext "Updating menus, nodes and cross-references."`" --as-response-line

    # Loop through target documentation entries in order to update
    # the documentation structure (e.g., It is not enough with copying
    # documentation entry files, it is also needed to update menu,
    # nodes and related cross-references).
    for ENTRY in ${ENTRIES};do

        # Update menu and node definitions from manual sections to
        # reflect the changes.
        ${FLAG_BACKEND}_updateMenu
        ${FLAG_BACKEND}_updateNodes

        # Update cross reference definitions from manual to reflect
        # the changes.
        ${FLAG_BACKEND}_restoreCrossReferences

    done

    # Commit changes from working copy to central repository only.  At
    # this point, changes in the repository are not merged in the
    # working copy, but chages in the working copy do are committed up
    # to repository.
    cli_commitRepoChanges ${MANUAL_CHAPTER_DIR}

}