Blame Scripts/Bash/Cli/Functions/Identity/identity_renderBase.sh

d27df4
#!/bin/bash
d27df4
#
ad3ecd
# identity_renderBase.sh -- This function initiates base rendition
ad3ecd
# using pre-rendition configuration files.
d27df4
#
d27df4
# Copyright (C) 2009-2011 Alain Reguera Delgado
d27df4
# 
d27df4
# This program is free software; you can redistribute it and/or
d27df4
# modify it under the terms of the GNU General Public License as
d27df4
# published by the Free Software Foundation; either version 2 of the
d27df4
# License, or (at your option) any later version.
d27df4
# 
d27df4
# This program is distributed in the hope that it will be useful, but
d27df4
# WITHOUT ANY WARRANTY; without even the implied warranty of
d27df4
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
d27df4
# General Public License for more details.
d27df4
#
d27df4
# You should have received a copy of the GNU General Public License
d27df4
# along with this program; if not, write to the Free Software
d27df4
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
d27df4
# USA.
d27df4
# 
d27df4
# ----------------------------------------------------------------------
d27df4
# $Id$
d27df4
# ----------------------------------------------------------------------
d27df4
ad3ecd
function identity_renderBase {
d27df4
b76187
    local FILE=''
d659a9
    local FILES=''
b76187
    local OUTPUT=''
b76187
    local EXPORTID=''
ddde89
    local TEMPLATE=''
ddde89
    local COMMONDIR=''
b76187
    local PARENTDIR=''
b76187
    local TRANSLATION=''
b76187
    local EXTERNALFILE=''
b76187
    local EXTERNALFILES=''
ddde89
    local COMMONDIRCOUNT=0
d659a9
    local -a COMMONDIRS
d27df4
d27df4
    # Redefine parent directory for current workplace.
c979f9
    PARENTDIR=$(basename "${ACTIONVAL}")
d27df4
ddde89
    # Define base location of template files.
130f90
    identity_getDirTemplate
ddde89
    
ddde89
    # Define list of files to process. 
ddde89
    FILES=$(cli_getFilesList "${TEMPLATE}" "${FLAG_FILTER}.*\.(svgz|svg)")
ddde89
ddde89
    # Set action preamble.
ebb30d
    cli_printActionPreamble "$FILES"
ddde89
ddde89
    # Define common absolute paths in order to know when centos-art.sh
ddde89
    # is leaving a directory structure and entering into another. This
ddde89
    # information is required in order for centos-art.sh to know when
ddde89
    # to apply last-rendition actions.
ddde89
    for COMMONDIR in $(dirname "$FILES" | sort | uniq);do
ddde89
        COMMONDIRS[$COMMONDIRCOUNT]=$(dirname "$COMMONDIR")
ddde89
        COMMONDIRCOUNT=$(($COMMONDIRCOUNT + 1))
d27df4
    done
d27df4
c979f9
    # Reset common directory counter.
c979f9
    COMMONDIRCOUNT=0
c979f9
b76187
    # Define export id used inside design templates. This value
b76187
    # defines the design area we want to export.
b76187
    EXPORTID='CENTOSARTWORK'
b76187
b76187
    # Start processing the base rendition list of FILES. Fun part
b76187
    # approching :-).
b76187
    for FILE in $FILES; do
b76187
b76187
        # Define final location of translation file.
b76187
        TRANSLATION=$(dirname $FILE \
b76187
           | sed -r 's!/trunk/(Identity/)!/trunk/Locales/\1!')/$(cli_getCurrentLocale).po
b76187
b76187
        # Print final location of translation file.
b76187
        if [[ ! -f "$TRANSLATION" ]];then
b76187
            cli_printMessage "`gettext "None"`" "AsTranslationLine"
b76187
        else
b76187
            cli_printMessage "$TRANSLATION" 'AsTranslationLine'
b76187
        fi
b76187
b76187
        # Define final location of template file.
b76187
        TEMPLATE=${FILE}
b76187
b76187
        # Print final location of template file.
b76187
        if [[ ! -f "$TEMPLATE" ]];then
b76187
            cli_printMessage "`gettext "None"`" "AsDesignLine"
b76187
        else
b76187
            cli_printMessage "$TEMPLATE" 'AsDesignLine'
b76187
        fi
b76187
 
b76187
        # Define final location of output directory.
130f90
        identity_getDirOutput
b76187
b76187
        # Get relative path to file. The path string (stored in FILE)
b76187
        # has two parts: 1. the variable path and 2. the common path.
b76187
        # The variable path is before the common point in the path
b76187
        # string. The common path is after the common point in the
b76187
        # path string. The common point is the name of the parent
b76187
        # directory (stored in PARENTDIR).
b76187
        #
b76187
        # trunk/Locales/Identity/.../Firstboot/3/splash-small.svg
b76187
        # -------------------------^| the     |^------------^
b76187
        # variable path             | common  |    common path
b76187
        # -------------------------v| point   |    v------------v
b76187
        # trunk/Identity/Themes/M.../Firstboot/Img/3/splash-small.png
b76187
        #
b76187
        # What we do here is remove the varibale path, the common
b76187
        # point, and the file extension parts in the string holding
b76187
        # the path retrived from design models directory structure.
b76187
        # Then we use the common path as relative path to store the
b76187
        # the final image file.
b76187
        #
b76187
        # The file extension is removed from the common path because
b76187
        # it is set when we create the final image file. This
b76187
        # configuration let us use different extensions for the same
b76187
        # file name.
b76187
        #
b76187
        # When we render using renderImage function, the structure of
b76187
        # files under the output directory will be the same used after
b76187
        # the common point in the related design model directory
b76187
        # structure.
b76187
        FILE=$(echo ${FILE} \
b76187
            | sed -r "s!.*${PARENTDIR}/!!" \
b76187
            | sed -r "s/\.(svgz|svg)$//")
b76187
b76187
        # Define absolute path to final file (without extension).
b76187
        FILE=${OUTPUT}/$(basename "${FILE}")
b76187
b76187
        # Define instance name from design model.
b76187
        INSTANCE=$(cli_getTemporalFile ${TEMPLATE})
b76187
b76187
        if [[ -f ${TRANSLATION} ]];then
b76187
b76187
            # Create translated instance from design model.
b76187
            /usr/bin/xml2po -p ${TRANSLATION} ${TEMPLATE} > ${INSTANCE}
b76187
b76187
            # Remove .xml2po.mo temporal file.
b76187
            if [[ -f ${PWD}/.xml2po.mo ]];then
b76187
                rm ${PWD}/.xml2po.mo
b76187
            fi
b76187
b76187
        else
b76187
b76187
            # Create non-translated instance form design model.
b76187
            /bin/cat ${TEMPLATE} > ${INSTANCE}    
b76187
b76187
        fi
b76187
b76187
        # Apply replacement of translation markers to design model
b76187
        # translated instance.
b76187
        cli_replaceTMarkers ${INSTANCE}
b76187
b76187
        # Check export id inside design templates.
b76187
        grep "id=\"$EXPORTID\"" $INSTANCE > /dev/null
b76187
        if [[ $? -gt 0 ]];then
b76187
            cli_printMessage "`eval_gettext "There is no export id (\\\$EXPORTID) inside \\\$TEMPLATE."`" "AsErrorLine"
b76187
            cli_printMessage '-' 'AsSeparatorLine'
b76187
            continue
b76187
        fi
b76187
b76187
        # Check existence of external files. In order for design
b76187
        # templates to point different artistic motifs, design
b76187
        # templates make use of external files that point to specific
b76187
        # artistic motif background images. If such external files
b76187
        # doesn't exist, print a message and stop script execution.
b76187
        # We cannot continue without background information.
1787a2
        identity_checkAbsolutePaths "$INSTANCE"
b76187
b76187
        # Render template instance and modify the inkscape output to
b76187
        # reduce the amount of characters used in description column
b76187
        # at final output.
b76187
        cli_printMessage "$(inkscape $INSTANCE \
b76187
            --export-id=$EXPORTID --export-png=${FILE}.png | sed -r \
b76187
            -e "s!Area !`gettext "Area"`: !" \
b76187
            -e "s!Background RRGGBBAA:!`gettext "Background"`: RRGGBBAA!" \
b76187
            -e "s!Bitmap saved as:!`gettext "Saved as"`:!")" \
b76187
            'AsRegularLine'
b76187
b76187
        # Remove template instance. 
b76187
        if [[ -a $INSTANCE ]];then
b76187
            rm $INSTANCE
b76187
        fi
ddde89
b76187
        # Execute post-rendition actions.
c979f9
        identity_renderPostActions
b76187
b76187
        # Output separator line.
b76187
        cli_printMessage '-' 'AsSeparatorLine'
b76187
c979f9
        # Verify position of file being produced in the list of files
c979f9
        # been currently processed.  As convenction, last-rendition
b76187
        # actions are applied after all images inside the same
c979f9
        # directory structure have being produced. Notice that, in
b76187
        # order to apply last-rendition actions correctly,
b76187
        # centos-art.sh needs to "predict" what the last file in the
b76187
        # same directory structure would be. There is no magic here,
b76187
        # so we need to previously define which are the common
c979f9
        # directory structures centos-art.sh could produce content for
c979f9
        # inside an array variable. Later, using the index of that
b76187
        # array variable we could check the next item in the array
b76187
        # against the file being currently produced. If they match, we
b76187
        # haven't reached the end of the same directory structure, but
b76187
        # if they don't match, we do have reach the end of the same
b76187
        # directory structure and it is time for last-rendition
b76187
        # actions to be evaluated before go producing the next
b76187
        # directory structure in the list of files to process.
b76187
        if [[ $(dirname "$TEMPLATE") != ${COMMONDIRS[$(($COMMONDIRCOUNT + 1))]} ]];then
b76187
b76187
            # At this point centos-art.sh should be producing the last
b76187
            # file from the same unique directory structure, so,
b76187
            # before producing images for the next directory structure
c979f9
            # lets execute last-rendition actions for the current
b76187
            # directory structure. 
c979f9
            identity_renderLastActions
b76187
b76187
        fi
b76187
b76187
        # Increment common directory counter.
b76187
        COMMONDIRCOUNT=$(($COMMONDIRCOUNT + 1))
b76187
b76187
    done
c979f9
d27df4
}