Blame Automation/centos-art.sh-mods/Render/render_setThemes.sh

Alain Reguera Delgado 8f60cb
#!/bin/bash
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# render_setThemes.sh -- This function performs theme-specific
Alain Reguera Delgado 8f60cb
# rendition.
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_setThemes {
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    local -a DIRS
Alain Reguera Delgado 8f60cb
    local COUNT=0
Alain Reguera Delgado 8f60cb
    local NEXTDIR=''
Alain Reguera Delgado 8f60cb
    local MOTIF_NAME=''
Alain Reguera Delgado 8f60cb
    local MOTIF_DIR=''
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Define base directory of artistic motifs. This is the location
Alain Reguera Delgado 8f60cb
    # where all artistic motifs are stored in.
Alain Reguera Delgado 8f60cb
    local MOTIF_BASEDIR="${TCAR_WORKDIR}/Identity/Images/Themes"
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Define base directory of design models. This is the location
Alain Reguera Delgado 8f60cb
    # where all design models are stored in.
Alain Reguera Delgado 8f60cb
    local MODEL_BASEDIR="${TCAR_WORKDIR}/Identity/Models/Themes"
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Verify directory structure for all theme-specific directories.
Alain Reguera Delgado 8f60cb
    render_setThemesDirStructure "${MODEL_BASEDIR}/${FLAG_THEME_MODEL}" "${MOTIF_BASEDIR}" 
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Define directory structure of design models. Design models
Alain Reguera Delgado 8f60cb
    # directory structures are used as reference to create artistic
Alain Reguera Delgado 8f60cb
    # motifs directory structure. Use the `--pattern' option to be
Alain Reguera Delgado 8f60cb
    # sure any modification to FLAG_FILTER won't affect the output
Alain Reguera Delgado 8f60cb
    # result. We need to make matching everything here, no matter what
Alain Reguera Delgado 8f60cb
    # the FLAG_FILTER value be.
Alain Reguera Delgado 8f60cb
    local MODEL_DIR=''
Alain Reguera Delgado 8f60cb
    local MODEL_DIRS="$(cli_getFilesList ${MODEL_BASEDIR}/${FLAG_THEME_MODEL} \
Alain Reguera Delgado 8f60cb
        --pattern='^.+/[^.svn][[:alnum:]_/-]+$' --type="d" \
Alain Reguera Delgado 8f60cb
        | sed -e "s!^.*/${FLAG_THEME_MODEL}!!" \
Alain Reguera Delgado 8f60cb
              -e '/^[[:space:]]*$/d' \
Alain Reguera Delgado 8f60cb
              -e 's!^/!!')"
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Define design model regular expression patterns from design
Alain Reguera Delgado 8f60cb
    # models directory structure.
Alain Reguera Delgado 8f60cb
    local MODEL_PATTERN=$(echo "$MODEL_DIRS" | tr "\n" '|' \
Alain Reguera Delgado 8f60cb
        | sed -e 's!^|!!' -e 's!|$!!')
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Define regular expression pattern that match the theme artistic
Alain Reguera Delgado 8f60cb
    # motif component inside the path strings.
Alain Reguera Delgado 8f60cb
    local MOTIF_PATTERN=$(cli_getPathComponent --motif-pattern)
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Define list of render-able directory structures inside the
Alain Reguera Delgado 8f60cb
    # artistic motif. As reference, to build this list, use design
Alain Reguera Delgado 8f60cb
    # model directory structure.  The more specific you be in the path
Alain Reguera Delgado 8f60cb
    # specification the more specific theme rendition will be. Thus,
Alain Reguera Delgado 8f60cb
    # we use the path provided as argument and the --filter option as
Alain Reguera Delgado 8f60cb
    # reference to control the amount of directories considered
Alain Reguera Delgado 8f60cb
    # render-able directory.
Alain Reguera Delgado 8f60cb
    local MOTIF_RENDERABLE_DIR=''
Alain Reguera Delgado 8f60cb
    local MOTIF_RENDERABLE_DIRS=$(cli_getFilesList ${MOTIF_BASEDIR} \
Alain Reguera Delgado 8f60cb
        --pattern="^${TCAR_WORKDIR}/${MOTIF_PATTERN}/($MODEL_PATTERN)$" --type="d" \
Alain Reguera Delgado 8f60cb
        | grep "$(echo ${ACTIONVAL} | sed -r 's,/$,,')")
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # When no render-able directories are found, finish the script
Alain Reguera Delgado 8f60cb
    # execution with an error message. There is an obvious typo in the
Alain Reguera Delgado 8f60cb
    # path provided.
Alain Reguera Delgado 8f60cb
    if [[ -z ${MOTIF_RENDERABLE_DIRS} ]];then
Alain Reguera Delgado 8f60cb
        cli_printMessage "`gettext "No related model was found for the path provided."`" --as-error-line
Alain Reguera Delgado 8f60cb
    fi
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Rebuild list of render-able directory structures using an array
Alain Reguera Delgado 8f60cb
    # variable. This let us to predict what directory is one step
Alain Reguera Delgado 8f60cb
    # forward or backward from the current directory structure.
Alain Reguera Delgado 8f60cb
    for MOTIF_RENDERABLE_DIR in $MOTIF_RENDERABLE_DIRS;do
Alain Reguera Delgado 8f60cb
        DIRS[((++${#DIRS[*]}))]=${MOTIF_RENDERABLE_DIR}
Alain Reguera Delgado 8f60cb
    done
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Define total number of directories to process. This is required
Alain Reguera Delgado 8f60cb
    # in order to correct the counting value and so, make it to match
Alain Reguera Delgado 8f60cb
    # the zero based nature of bash array variables.
Alain Reguera Delgado 8f60cb
    local DIRS_TOTAL=$((${#DIRS[*]} - 1))
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    while [[ $COUNT -le ${DIRS_TOTAL} ]];do
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Redefine action value to refer the theme-specific render-able
Alain Reguera Delgado 8f60cb
        # directory.
Alain Reguera Delgado 8f60cb
        ACTIONVAL=${DIRS[$COUNT]}
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Refine artistic motif name using the current action value.
Alain Reguera Delgado 8f60cb
        MOTIF_NAME=$(cli_getPathComponent $ACTIONVAL --motif)
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Verify artistic motif name. The name of the artistic motif
Alain Reguera Delgado 8f60cb
        # must be present in order for theme rendition to happen.
Alain Reguera Delgado 8f60cb
        # Theme rendition takes place inside artistic motifs and the
Alain Reguera Delgado 8f60cb
        # artistic motif name is an indispensable part of it. Take
Alain Reguera Delgado 8f60cb
        # care of not using design models directory structure as name
Alain Reguera Delgado 8f60cb
        # for artistic motifs. They, sometimes, match the pattern used
Alain Reguera Delgado 8f60cb
        # to verify artistic motifs names but must not be confused.
Alain Reguera Delgado 8f60cb
        if [[ $MOTIF_NAME == '' ]] || [[ $MOTIF_NAME =~ "^($MODEL_PATTERN)" ]];then
Alain Reguera Delgado 8f60cb
            COUNT=$(($COUNT + 1))
Alain Reguera Delgado 8f60cb
            continue
Alain Reguera Delgado 8f60cb
        fi
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Refine artistic motif directory. This is the top directory
Alain Reguera Delgado 8f60cb
        # where all visual manifestations of an artistic motif are
Alain Reguera Delgado 8f60cb
        # stored in (e.g., Backgrounds, Brushes, Concept, Distro,
Alain Reguera Delgado 8f60cb
        # etc.).
Alain Reguera Delgado 8f60cb
        MOTIF_DIR="${MOTIF_BASEDIR}/${MOTIF_NAME}"
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Define what is the next directory in the list, so we could
Alain Reguera Delgado 8f60cb
        # verify whether to render or not the current theme-specific
Alain Reguera Delgado 8f60cb
        # render-able directory.
Alain Reguera Delgado 8f60cb
        if [[ $COUNT -lt ${DIRS_TOTAL} ]];then
Alain Reguera Delgado 8f60cb
            NEXTDIR=$(dirname ${DIRS[(($COUNT + 1))]})
Alain Reguera Delgado 8f60cb
        else
Alain Reguera Delgado 8f60cb
            NEXTDIR=''
Alain Reguera Delgado 8f60cb
        fi
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Verify whether to render or not the current theme's
Alain Reguera Delgado 8f60cb
        # render-able directory. This verification is needed in order
Alain Reguera Delgado 8f60cb
        # to avoid unnecessary rendition loops. For example, don't
Alain Reguera Delgado 8f60cb
        # render `path/to/dir/A' when `path/to/dir/A/B' does exist,
Alain Reguera Delgado 8f60cb
        # that configuration would produce `/path/to/dir/A/B twice.
Alain Reguera Delgado 8f60cb
        if [[ $ACTIONVAL =~ '[[:digit:]]$' ]] || [[ $ACTIONVAL == $NEXTDIR ]];then
Alain Reguera Delgado 8f60cb
            COUNT=$(($COUNT + 1))
Alain Reguera Delgado 8f60cb
            continue
Alain Reguera Delgado 8f60cb
        fi
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Execute direct rendition on theme specific render-able
Alain Reguera Delgado 8f60cb
        # directory as specified by action value.
Alain Reguera Delgado 8f60cb
        render_setBaseRendition
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Increment counter to match the correct count value.
Alain Reguera Delgado 8f60cb
        COUNT=$(($COUNT + 1))
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    done
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
}