Blame Automation/Modules/Render/render_setBaseRendition.sh

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