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

Alain Reguera Delgado 64aead
#!/bin/bash
Alain Reguera Delgado 64aead
#
Alain Reguera Delgado 64aead
# render_setThemes.sh -- This function performs theme-specific
Alain Reguera Delgado 64aead
# rendition.
Alain Reguera Delgado 64aead
#
Alain Reguera Delgado 64aead
# Copyright (C) 2009-2013 The CentOS Project
Alain Reguera Delgado 64aead
#
Alain Reguera Delgado 64aead
# This program is free software; you can redistribute it and/or modify
Alain Reguera Delgado 64aead
# it under the terms of the GNU General Public License as published by
Alain Reguera Delgado 64aead
# the Free Software Foundation; either version 2 of the License, or (at
Alain Reguera Delgado 64aead
# your option) any later version.
Alain Reguera Delgado 64aead
#
Alain Reguera Delgado 64aead
# This program is distributed in the hope that it will be useful, but
Alain Reguera Delgado 64aead
# WITHOUT ANY WARRANTY; without even the implied warranty of
Alain Reguera Delgado 64aead
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Alain Reguera Delgado 64aead
# General Public License for more details.
Alain Reguera Delgado 64aead
#
Alain Reguera Delgado 64aead
# You should have received a copy of the GNU General Public License
Alain Reguera Delgado 64aead
# along with this program; if not, write to the Free Software
Alain Reguera Delgado 64aead
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Alain Reguera Delgado 64aead
#
Alain Reguera Delgado 64aead
# ----------------------------------------------------------------------
Alain Reguera Delgado 64aead
# $Id$
Alain Reguera Delgado 64aead
# ----------------------------------------------------------------------
Alain Reguera Delgado 64aead
Alain Reguera Delgado 64aead
function render_setThemes {
Alain Reguera Delgado 64aead
Alain Reguera Delgado 64aead
    local -a DIRS
Alain Reguera Delgado 64aead
    local COUNT=0
Alain Reguera Delgado 64aead
    local NEXTDIR=''
Alain Reguera Delgado 64aead
    local MOTIF_NAME=''
Alain Reguera Delgado 64aead
    local MOTIF_DIR=''
Alain Reguera Delgado 64aead
Alain Reguera Delgado 64aead
    # Define base directory of artistic motifs. This is the location
Alain Reguera Delgado 64aead
    # where all artistic motifs are stored in.
Alain Reguera Delgado 64aead
    local MOTIF_BASEDIR="${TCAR_WORKDIR}/Identity/Images/Themes"
Alain Reguera Delgado 64aead
Alain Reguera Delgado 64aead
    # Define base directory of design models. This is the location
Alain Reguera Delgado 64aead
    # where all design models are stored in.
Alain Reguera Delgado 64aead
    local MODEL_BASEDIR="${TCAR_WORKDIR}/Identity/Models/Themes"
Alain Reguera Delgado 64aead
Alain Reguera Delgado 64aead
    # Verify directory structure for all theme-specific directories.
Alain Reguera Delgado 64aead
    render_setThemesDirStructure "${MODEL_BASEDIR}/${FLAG_THEME_MODEL}" "${MOTIF_BASEDIR}" 
Alain Reguera Delgado 64aead
Alain Reguera Delgado 64aead
    # Define directory structure of design models. Design models
Alain Reguera Delgado 64aead
    # directory structures are used as reference to create artistic
Alain Reguera Delgado 64aead
    # motifs directory structure. Use the `--pattern' option to be
Alain Reguera Delgado 64aead
    # sure any modification to FLAG_FILTER won't affect the output
Alain Reguera Delgado 64aead
    # result. We need to make matching everything here, no matter what
Alain Reguera Delgado 64aead
    # the FLAG_FILTER value be.
Alain Reguera Delgado 64aead
    local MODEL_DIR=''
Alain Reguera Delgado 64aead
    local MODEL_DIRS="$(cli_getFilesList ${MODEL_BASEDIR}/${FLAG_THEME_MODEL} \
Alain Reguera Delgado 64aead
        --pattern='^.+/[^.svn][[:alnum:]_/-]+$' --type="d" \
Alain Reguera Delgado 64aead
        | sed -e "s!^.*/${FLAG_THEME_MODEL}!!" \
Alain Reguera Delgado 64aead
              -e '/^[[:space:]]*$/d' \
Alain Reguera Delgado 64aead
              -e 's!^/!!')"
Alain Reguera Delgado 64aead
Alain Reguera Delgado 64aead
    # Define design model regular expression patterns from design
Alain Reguera Delgado 64aead
    # models directory structure.
Alain Reguera Delgado 64aead
    local MODEL_PATTERN=$(echo "$MODEL_DIRS" | tr "\n" '|' \
Alain Reguera Delgado 64aead
        | sed -e 's!^|!!' -e 's!|$!!')
Alain Reguera Delgado 64aead
Alain Reguera Delgado 64aead
    # Define regular expression pattern that match the theme artistic
Alain Reguera Delgado 64aead
    # motif component inside the path strings.
Alain Reguera Delgado 64aead
    local MOTIF_PATTERN=$(cli_getPathComponent --motif-pattern)
Alain Reguera Delgado 64aead
Alain Reguera Delgado 64aead
    # Define list of render-able directory structures inside the
Alain Reguera Delgado 64aead
    # artistic motif. As reference, to build this list, use design
Alain Reguera Delgado 64aead
    # model directory structure.  The more specific you be in the path
Alain Reguera Delgado 64aead
    # specification the more specific theme rendition will be. Thus,
Alain Reguera Delgado 64aead
    # we use the path provided as argument and the --filter option as
Alain Reguera Delgado 64aead
    # reference to control the amount of directories considered
Alain Reguera Delgado 64aead
    # render-able directory.
Alain Reguera Delgado 64aead
    local MOTIF_RENDERABLE_DIR=''
Alain Reguera Delgado 64aead
    local MOTIF_RENDERABLE_DIRS=$(cli_getFilesList ${MOTIF_BASEDIR} \
Alain Reguera Delgado 64aead
        --pattern="^${TCAR_WORKDIR}/${MOTIF_PATTERN}/($MODEL_PATTERN)$" --type="d" \
Alain Reguera Delgado 64aead
        | grep "$(echo ${ACTIONVAL} | sed -r 's,/$,,')")
Alain Reguera Delgado 64aead
Alain Reguera Delgado 64aead
    # When no render-able directories are found, finish the script
Alain Reguera Delgado 64aead
    # execution with an error message. There is an obvious typo in the
Alain Reguera Delgado 64aead
    # path provided.
Alain Reguera Delgado 64aead
    if [[ -z ${MOTIF_RENDERABLE_DIRS} ]];then
Alain Reguera Delgado 4971f2
        cli_printMessage "`gettext "No related model was found for the path provided."`" --as-error-line
Alain Reguera Delgado 64aead
    fi
Alain Reguera Delgado 64aead
Alain Reguera Delgado 64aead
    # Rebuild list of render-able directory structures using an array
Alain Reguera Delgado 64aead
    # variable. This let us to predict what directory is one step
Alain Reguera Delgado 64aead
    # forward or backward from the current directory structure.
Alain Reguera Delgado 64aead
    for MOTIF_RENDERABLE_DIR in $MOTIF_RENDERABLE_DIRS;do
Alain Reguera Delgado 64aead
        DIRS[((++${#DIRS[*]}))]=${MOTIF_RENDERABLE_DIR}
Alain Reguera Delgado 64aead
    done
Alain Reguera Delgado 64aead
Alain Reguera Delgado 64aead
    # Define total number of directories to process. This is required
Alain Reguera Delgado 64aead
    # in order to correct the counting value and so, make it to match
Alain Reguera Delgado 64aead
    # the zero based nature of bash array variables.
Alain Reguera Delgado 64aead
    local DIRS_TOTAL=$((${#DIRS[*]} - 1))
Alain Reguera Delgado 64aead
Alain Reguera Delgado 64aead
    while [[ $COUNT -le ${DIRS_TOTAL} ]];do
Alain Reguera Delgado 64aead
Alain Reguera Delgado 64aead
        # Redefine action value to refer the theme-specific render-able
Alain Reguera Delgado 64aead
        # directory.
Alain Reguera Delgado 64aead
        ACTIONVAL=${DIRS[$COUNT]}
Alain Reguera Delgado 64aead
Alain Reguera Delgado 64aead
        # Refine artistic motif name using the current action value.
Alain Reguera Delgado 64aead
        MOTIF_NAME=$(cli_getPathComponent $ACTIONVAL --motif)
Alain Reguera Delgado 64aead
Alain Reguera Delgado 64aead
        # Verify artistic motif name. The name of the artistic motif
Alain Reguera Delgado 64aead
        # must be present in order for theme rendition to happen.
Alain Reguera Delgado 64aead
        # Theme rendition takes place inside artistic motifs and the
Alain Reguera Delgado 64aead
        # artistic motif name is an indispensable part of it. Take
Alain Reguera Delgado 64aead
        # care of not using design models directory structure as name
Alain Reguera Delgado 64aead
        # for artistic motifs. They, sometimes, match the pattern used
Alain Reguera Delgado 64aead
        # to verify artistic motifs names but must not be confused.
Alain Reguera Delgado 64aead
        if [[ $MOTIF_NAME == '' ]] || [[ $MOTIF_NAME =~ "^($MODEL_PATTERN)" ]];then
Alain Reguera Delgado 64aead
            COUNT=$(($COUNT + 1))
Alain Reguera Delgado 64aead
            continue
Alain Reguera Delgado 64aead
        fi
Alain Reguera Delgado 64aead
Alain Reguera Delgado 64aead
        # Refine artistic motif directory. This is the top directory
Alain Reguera Delgado 64aead
        # where all visual manifestations of an artistic motif are
Alain Reguera Delgado 64aead
        # stored in (e.g., Backgrounds, Brushes, Concept, Distro,
Alain Reguera Delgado 64aead
        # etc.).
Alain Reguera Delgado 64aead
        MOTIF_DIR="${MOTIF_BASEDIR}/${MOTIF_NAME}"
Alain Reguera Delgado 64aead
Alain Reguera Delgado 64aead
        # Define what is the next directory in the list, so we could
Alain Reguera Delgado 64aead
        # verify whether to render or not the current theme-specific
Alain Reguera Delgado 64aead
        # render-able directory.
Alain Reguera Delgado 64aead
        if [[ $COUNT -lt ${DIRS_TOTAL} ]];then
Alain Reguera Delgado 64aead
            NEXTDIR=$(dirname ${DIRS[(($COUNT + 1))]})
Alain Reguera Delgado 64aead
        else
Alain Reguera Delgado 64aead
            NEXTDIR=''
Alain Reguera Delgado 64aead
        fi
Alain Reguera Delgado 64aead
Alain Reguera Delgado 64aead
        # Verify whether to render or not the current theme's
Alain Reguera Delgado 64aead
        # render-able directory. This verification is needed in order
Alain Reguera Delgado 64aead
        # to avoid unnecessary rendition loops. For example, don't
Alain Reguera Delgado 64aead
        # render `path/to/dir/A' when `path/to/dir/A/B' does exist,
Alain Reguera Delgado 64aead
        # that configuration would produce `/path/to/dir/A/B twice.
Alain Reguera Delgado 64aead
        if [[ $ACTIONVAL =~ '[[:digit:]]$' ]] || [[ $ACTIONVAL == $NEXTDIR ]];then
Alain Reguera Delgado 64aead
            COUNT=$(($COUNT + 1))
Alain Reguera Delgado 64aead
            continue
Alain Reguera Delgado 64aead
        fi
Alain Reguera Delgado 64aead
Alain Reguera Delgado 64aead
        # Execute direct rendition on theme specific render-able
Alain Reguera Delgado 64aead
        # directory as specified by action value.
Alain Reguera Delgado 64aead
        render_setBaseRendition
Alain Reguera Delgado 64aead
Alain Reguera Delgado 64aead
        # Increment counter to match the correct count value.
Alain Reguera Delgado 64aead
        COUNT=$(($COUNT + 1))
Alain Reguera Delgado 64aead
Alain Reguera Delgado 64aead
    done
Alain Reguera Delgado 64aead
Alain Reguera Delgado 64aead
}