Blame Scripts/Bash/Functions/Render/render_doBaseActions.sh

878a2b
#!/bin/bash
878a2b
#
878a2b
# render_doBaseActions.sh -- This function performs base-rendition
878a2b
# action for all files.
878a2b
#
e6bbbf
# Copyright (C) 2009-2013 The CentOS Project
878a2b
#
878a2b
# This program is free software; you can redistribute it and/or modify
878a2b
# it under the terms of the GNU General Public License as published by
878a2b
# the Free Software Foundation; either version 2 of the License, or (at
878a2b
# your option) any later version.
878a2b
#
878a2b
# This program is distributed in the hope that it will be useful, but
878a2b
# WITHOUT ANY WARRANTY; without even the implied warranty of
878a2b
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
878a2b
# General Public License for more details.
878a2b
#
878a2b
# You should have received a copy of the GNU General Public License
878a2b
# along with this program; if not, write to the Free Software
878a2b
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
878a2b
#
878a2b
# ----------------------------------------------------------------------
878a2b
# $Id$
878a2b
# ----------------------------------------------------------------------
878a2b
878a2b
function render_doBaseActions {
878a2b
878a2b
    local -a FILES
878a2b
    local FILE=''
878a2b
    local OUTPUT=''
878a2b
    local TEMPLATE=''
b4a50f
    local TEMPLATES=''
878a2b
    local PARENTDIR=''
878a2b
    local TRANSLATION=''
878a2b
    local EXTERNALFILE=''
878a2b
    local EXTERNALFILES=''
878a2b
    local THIS_FILE_DIR=''
878a2b
    local NEXT_FILE_DIR=''
878a2b
    local RENDER_EXTENSION=''
13e8af
    local EXPORTID=''
878a2b
    local COUNT=0
878a2b
878a2b
    # Verify default directory where design models are stored in.
819c26
    cli_checkFiles -e "${TCAR_WORKDIR}/Identity/Models/Themes/${FLAG_THEME_MODEL}"
878a2b
878a2b
    # Redefine parent directory for current workplace.
878a2b
    PARENTDIR=$(basename "${ACTIONVAL}")
a7e7b4
 
878a2b
    # Loop through list of supported file extensions. 
878a2b
    for RENDER_EXTENSION in ${RENDER_EXTENSIONS};do
878a2b
a7e7b4
        # Redefine rendition format name based on supported file
878a2b
        # extension.
f55962
        if [[ $RENDER_EXTENSION =~ '^(svgz|svg)$' ]];then
56cf52
            RENDER_FORMAT='svg'
56cf52
        elif [[ $RENDER_EXTENSION =~ '^(docbook)$' ]];then
56cf52
            RENDER_FORMAT='docbook'
a7e7b4
        elif [[ $RENDER_EXTENSION =~ '^(conf)$' ]];then
a7e7b4
            RENDER_FORMAT='conf'
878a2b
        else
878a2b
           cli_printMessage "`eval_gettext "The \\\"\\\$RENDER_EXTENSION\\\" file extension is not supported yet."`" --as-error-line 
878a2b
        fi
878a2b
13e8af
        # Redefine specific function export id. 
13e8af
        EXPORTID="${CLI_FUNCDIRNAM}/$(cli_getRepoName ${RENDER_FORMAT} -d)/$(cli_getRepoName ${RENDER_FORMAT} -f)"
13e8af
a7e7b4
        # Define base location of template files using paths passed to
a7e7b4
        # centos-art.sh script as argument to.
a7e7b4
        render_getDirTemplate
a7e7b4
878a2b
        # Define the list of files to process. Use an array variable
b4a50f
        # to store the list of files to process. This make possible to
878a2b
        # realize verifications like: is the current base directory
878a2b
        # equal to the next one in the list of files to process?
b4a50f
        # Questions like this let us to know when centos-art.sh is
878a2b
        # leaving a directory structure and entering another. This
878a2b
        # information is required in order for centos-art.sh to know
878a2b
        # when to apply last-rendition actions.
878a2b
        #
878a2b
        # Another issue is that some directories might be named as if
13e8af
        # they were files (e.g., using a render able extension like
878a2b
        # .docbook).  In these situations we need to avoid such
b4a50f
        # directories from being interpreted as a render able file.
b4a50f
        # For this, pass the `--type="f"' option when building the
b4a50f
        # list of files to process in order to retrieve regular files
b4a50f
        # only.
878a2b
        #
a7e7b4
        # Another issue to consider here is that, in some cases, both
878a2b
        # templates and outputs might be in the same location. In
878a2b
        # these cases localized content are stored in the same
b4a50f
        # location where template files are retrieved from and we need
878a2b
        # to avoid using localized content from being interpreted as
b4a50f
        # design models. In that sake, build the list of files to
a7e7b4
        # process using the files directly stored in the directory
b4a50f
        # passed as argument to centos-art.sh command-line. Don't go
a7e7b4
        # recursively here.
878a2b
        #
a7e7b4
        # Another issue to consider here, is the way of restricting
a7e7b4
        # the list of files to process. We cannot expand the pattern
a7e7b4
        # specified by FLAG_FILTER with a `.*' here (e.g.,
a7e7b4
        # "${FLAG_FILTER}.*\.${RENDER_EXTENSION}") because that would
a7e7b4
        # suppress any possibility from the user to specify just one
a7e7b4
        # file name in locations where more than one file with the
a7e7b4
        # same name as prefix exists (e.g., `repository.docbook',
a7e7b4
        # `repository-preamble.docbook' and
878a2b
        # `repository-parts.docbook').  Instead, pass filtering
878a2b
        # control to the user whom can use regular expression markup
878a2b
        # in the `--filter' option to decide whether to match
878a2b
        # `repository.docbook' only (e.g., through
878a2b
        # `--filter="repository"') or `repository-preamble.docbook'
878a2b
        # and `repository-parts.docbook' but not `repository.docbook'
878a2b
        # (e.g., through `--filter="repository-.*"').
689eeb
        if [[ ${RENDER_FORMAT} =~ "^docbook$" ]];then
689eeb
689eeb
            # When the render format is docbook, don't build a list of
689eeb
            # files to process. Instead, build the absolute path of
689eeb
            # the main file used to render docbook from models to
689eeb
            # final output manuals. This file must be stored directly
689eeb
            # inside the main manual's directory and named as it but
689eeb
            # with all letters in lowercase.
a7e7b4
            for FILE in $(cli_getFilesList ${TEMPLATE} \
b4a50f
                --maxdepth="1" --mindepth="1" \
689eeb
                --pattern="^.*$(cli_getRepoName ${TEMPLATE} -f)\.${RENDER_EXTENSION}$" \
a7e7b4
                --type="f");do
a7e7b4
                FILES[((++${#FILES[*]}))]=$FILE
a7e7b4
            done
a7e7b4
b4a50f
        else
a7e7b4
1334c4
            # For all other cases, build a list of files to process
1334c4
            # using the path value pass as argument.
a7e7b4
            for FILE in $(cli_getFilesList ${TEMPLATE} \
1334c4
                --pattern="^/.*${FLAG_FILTER}\.${RENDER_EXTENSION}$" \
a7e7b4
                --type="f");do
a7e7b4
                FILES[((++${#FILES[*]}))]=$FILE
a7e7b4
            done
a7e7b4
b4a50f
        fi
878a2b
689eeb
        # Verify list of files to process. Assuming no file was found,
878a2b
        # evaluate the next supported file extension.
878a2b
        if [[ ${#FILES[*]} -eq 0 ]];then
878a2b
            continue
878a2b
        fi
878a2b
24ece8
        # Initialize format-specific functionalities.
13e8af
        cli_exportFunctions "${EXPORTID}"
878a2b
878a2b
        # Start processing the base rendition list of FILES. Fun part
b4a50f
        # approaching :-).
878a2b
        while [[ $COUNT -lt ${#FILES[*]} ]];do
878a2b
878a2b
            # Define base file.
878a2b
            FILE=${FILES[$COUNT]}
878a2b
878a2b
            # Define the base directory path for the current file being
878a2b
            # process.
878a2b
            THIS_FILE_DIR=$(dirname ${FILES[$COUNT]})
878a2b
878a2b
            # Define the base directory path for the next file that will
878a2b
            # be process.
878a2b
            if [[ $(($COUNT + 1)) -lt ${#FILES[*]} ]];then
878a2b
                NEXT_FILE_DIR=$(dirname ${FILES[$(($COUNT + 1))]})
878a2b
            else
878a2b
                NEXT_FILE_DIR=''
878a2b
            fi
878a2b
878a2b
            # Print separator line.
878a2b
            cli_printMessage '-' --as-separator-line
878a2b
878a2b
            # Verify design models file existence. We cannot continue
878a2b
            # with out it.
7fb679
            cli_checkFiles ${FILE} -f
878a2b
b4a50f
            # Print action message.
7fb679
            cli_printMessage "${FILE}" --as-template-line
7fb679
878a2b
            # Define final location of output directory.
878a2b
            render_getDirOutput
878a2b
7fb679
            # Define final location of translation file.
7fb679
            TRANSLATION=$(dirname ${FILE} \
819c26
               | sed -r 's!(Documentation|Identity)!Locales/\1!')/${CLI_LANG_LC}/messages.po
7fb679
7fb679
            # Define final location of template file.
7fb679
            TEMPLATE=${FILE}
7fb679
            
878a2b
            # Get relative path to file. The path string (stored in
878a2b
            # FILE) has two parts: 1. the variable path and 2. the
878a2b
            # common path.  The variable path is before the common
878a2b
            # point in the path string. The common path is after the
878a2b
            # common point in the path string. The common point is the
878a2b
            # name of the parent directory (stored in PARENTDIR).
878a2b
            #
878a2b
            # Identity/Models/Themes/.../Firstboot/3/splash-small.svg
878a2b
            # -------------------------^| the     |^------------^
878a2b
            # variable path             | common  |    common path
878a2b
            # -------------------------v| point   |    v------------v
878a2b
            # Identity/Images/Themes/.../Firstboot/Img/3/splash-small.png
878a2b
            #
819c26
            # What we do here is remove the variable path, the common
878a2b
            # point, and the file extension parts in the string
819c26
            # holding the path retrieved from design models directory
878a2b
            # structure.  Then we use the common path as relative path
819c26
            # to store the final image file.
878a2b
            #
878a2b
            # The file extension is removed from the common path
878a2b
            # because it is set when we create the final image file.
878a2b
            # This configuration let us use different extensions for
878a2b
            # the same file name.
878a2b
            #
878a2b
            # When we render using base-rendition action, the
878a2b
            # structure of files under the output directory will be
878a2b
            # the same used after the common point in the related
878a2b
            # design model directory structure.
878a2b
            FILE=$(echo ${FILE} \
878a2b
                | sed -r "s!.*${PARENTDIR}/!!" \
878a2b
                | sed -r "s/\.${RENDER_EXTENSION}$//")
878a2b
878a2b
            # Define absolute path to final file (without extension).
878a2b
            FILE=${OUTPUT}/$(basename "${FILE}")
878a2b
878a2b
            # Define instance name from design model.
878a2b
            INSTANCE=$(cli_getTemporalFile ${TEMPLATE})
878a2b
24ece8
            # Perform format base-rendition.
24ece8
            ${RENDER_FORMAT}
878a2b
878a2b
            # Remove template instance. 
878a2b
            if [[ -f $INSTANCE ]];then
878a2b
                rm $INSTANCE
878a2b
            fi
878a2b
878a2b
            # Increment file counter.
878a2b
            COUNT=$(($COUNT + 1))
878a2b
878a2b
        done
878a2b
a7e7b4
        # Reset counter to prevent accumulation of values.
a7e7b4
        COUNT=0
a7e7b4
24ece8
        # Unset format-specific functionalities.
13e8af
        cli_unsetFunctions "${EXPORTID}"
878a2b
a7e7b4
        # Unset files list to prevent accumulation of values.
a7e7b4
        unset FILES
a7e7b4
878a2b
    done
878a2b
}