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

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