Blame Scripts/Functions/Render/render_doThemeActions.sh

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