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

4c79b5
#!/bin/bash
4c79b5
#
4c79b5
# render_getIdentityDefs.sh -- This function provides shared variables
15b1d2
# re-definition for all rendition actions inside centos-art.sh script.
4c79b5
#
9f5f2e
# Copyright (C) 2009-2011 Alain Reguera Delgado
4c79b5
# 
7cd8e9
# This program is free software; you can redistribute it and/or
7cd8e9
# modify it under the terms of the GNU General Public License as
7cd8e9
# published by the Free Software Foundation; either version 2 of the
7cd8e9
# License, or (at your option) any later version.
4c79b5
# 
4c79b5
# This program is distributed in the hope that it will be useful, but
4c79b5
# WITHOUT ANY WARRANTY; without even the implied warranty of
4c79b5
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
4c79b5
# General Public License for more details.
4c79b5
#
4c79b5
# You should have received a copy of the GNU General Public License
4c79b5
# along with this program; if not, write to the Free Software
4c79b5
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
4c79b5
# USA.
4c79b5
# 
4c79b5
# ----------------------------------------------------------------------
418249
# $Id$
4c79b5
# ----------------------------------------------------------------------
4c79b5
4c79b5
function render_getIdentityDefs {
4c79b5
4c79b5
    # Do not render translation template directories (Tpl/).
4c79b5
    if [[ $FILE =~ '/Tpl/.+\.sed$' ]];then
4c79b5
        continue
4c79b5
    fi
4c79b5
4c79b5
    # Define the translation file absolute path. Only if we have a
4c79b5
    # .sed extension at file's end we can consider that file as a
4c79b5
    # translation file.  Otherwise there is not translation file.
4c79b5
    if [[ $FILE =~ '\.sed$' ]];then
4c79b5
        TRANSLATION=$FILE
4c79b5
    else
4c79b5
        TRANSLATION=`gettext "None"`
4c79b5
    fi
4c79b5
07c2fe
    # Check translation file existence. This may seem unnecessary
4c79b5
    # because we already built the file list using existent files.
07c2fe
    # But what happen if any of the files already loaded are removed
07c2fe
    # after being loaded? well, just skip it.
4c79b5
    if [[ "$TRANSLATION" == 'None' ]];then
4c79b5
        cli_printMessage "`gettext "None"`" "AsTranslationLine"
4c79b5
    else
b76c02
        cli_checkFiles "$TRANSLATION" 'fh'
5187da
        cli_printMessage "$TRANSLATION" 'AsTranslationLine'
4c79b5
    fi
4c79b5
    
4c79b5
    # Define the design template absolute path. This definition is
4c79b5
    # done by interpreting the matching list and translation path
4c79b5
    # information.  This defintion needs to be coherent with those
8219f0
    # defined in render_getFilesList function.
4c79b5
    if [[ "${MATCHINGLIST}" != "" ]] \
4c79b5
        && [[ "${TRANSLATIONPATH}" == "" ]];then
4c79b5
    
4c79b5
        # Remove the template (`Tpl/') string from FILE for those
15b1d2
        # images based on design templates. This avoids the creation
15b1d2
        # of an extra `Tpl' directory under Img. We want to save
15b1d2
        # primary PNG file structure directly under Img/ not Img/Tpl/.
4c79b5
        FILE=$(echo $FILE | sed -r "s!^${SVG}/!!")
4c79b5
    
4c79b5
        # In this case just one primary image is rendered.
4c79b5
        # Template points to the value passed in the template
4c79b5
        # argument.
4c79b5
        TEMPLATE=${MATCHINGLIST}
4c79b5
    
4c79b5
    elif [[ "${MATCHINGLIST}" == "" ]] \
4c79b5
        && [[ "${TRANSLATIONPATH}" == "" ]];then
4c79b5
    
4c79b5
        # Remove the template (`Tpl/') string from FILE for those
15b1d2
        # images based on design templates. This avoids the creation
15b1d2
        # of an extra `Tpl' directory under Img. We want to save
15b1d2
        # primary PNG file structure directly under Img/ not Img/Tpl/.
4c79b5
        FILE=$(echo $FILE | sed -r "s!^${SVG}/!!")
4c79b5
    
4c79b5
        # In this case one primary image is rendered for each
4c79b5
        # design template. Template absolute path points to a
4c79b5
        # design template (see LOCATION's definition).
4c79b5
        TEMPLATE=$FILE
4c79b5
        
4c79b5
    elif [[ "${MATCHINGLIST}" == "" ]] \
4c79b5
        && [[ "${TRANSLATIONPATH}" != "" ]];then
4c79b5
    
4c79b5
        # In this case translation files are applied to design
4c79b5
        # templates with the same name (without extension). One
4c79b5
        # primary image is rendered for each translation file
4c79b5
        # matching.  Template and translation files use the same
4c79b5
        # path and name relative to their PARENTDIR. Translations
4c79b5
        # use .sed extension and templates .svg extension.
4c79b5
        TEMPLATE=$(echo $FILE | sed -r "s!.*/${PARENTDIR}/(.*)!\1!" \
4c79b5
            | sed 's!\.sed$!.svg!')
4c79b5
    
4c79b5
    elif [[ "${MATCHINGLIST}" != "" ]] \
4c79b5
        && [[ "${TRANSLATIONPATH}" != "" ]];then
4c79b5
    
4c79b5
        # Create a template and translation matching list.  With this
15b1d2
        # configuration we can optimize the rendition process for
4c79b5
        # artworks like Anaconda progress slides and installation
4c79b5
        # media, where many translation files apply one unique design
4c79b5
        # template file.
4c79b5
        #
4c79b5
        # Previous to this feature, there was one (repeated) design
4c79b5
        # template for each design holding the same design in all
4c79b5
        # cases, basically a raw copy. This structure is very hard to
4c79b5
        # maintain so it was reduced and optimized as we described
4c79b5
        # above.
4c79b5
        #
4c79b5
        # The idea is to create a link and customizable relation
4c79b5
        # between translation files and design template files in
15b1d2
        # pre-rendition configuration scripts and then interpret it
4c79b5
        # here.
4c79b5
        #
4c79b5
        # This way we pretend to eliminate duplicated design templates
4c79b5
        # saying something like translation 1.sed, 2.sed, 3.sed,
4c79b5
        # 4.sed, and 5.sed apply to the single design template A.svg.
4c79b5
        # Or, 1.sed, 3.sed, 4.sed to A.svg and 2.sed and 5.sed to
4c79b5
        # B.svg.
4c79b5
        #
4c79b5
        # Possible configuration 1: In this first case,
4c79b5
        # translation files and design templates share a common
4c79b5
        # portion of the path.  Sometimes, we call this common
4c79b5
        # portion of path the ``bond path''. This configuration is
4c79b5
        # strictly used under the following situations: 
4c79b5
        #
4c79b5
        #  1. There are too many translation files to apply to a
4c79b5
        #  single design template. This is the case of Brands
15b1d2
        #  artworks (see: trunk/Identity/Brands) rendition, where it
15b1d2
        #  is very difficult to maintain the relation list of design
15b1d2
        #  templates and translation files. E.g.:
4c79b5
        #
4c79b5
        #  bond/path/template.svg: \
4c79b5
        #     bond/path/translation1.sed \
4c79b5
        #     bond/path/translation2.sed
4c79b5
        #
4c79b5
        #  2. Translation files are under a directory with the same
4c79b5
        #  name of that used in the design template. All translation
4c79b5
        #  files inside this directory will be applied to the single
4c79b5
        #  design template that has the same name of the directory
4c79b5
        #  containing the translation files. E.g.:
4c79b5
        #
4c79b5
        #  bond/path/green.svg: \
4c79b5
        #     bond/path/green/translation1.sed \
4c79b5
        #     bond/path/green/translation2.sed
4c79b5
        #
4c79b5
        BOND=$(echo $TRANSLATION | sed -r "s/^.*\/$PARENTDIR\/(.+)\/.*\.sed$/\1/")
4c79b5
4c79b5
        # If there is no template at this point, start reducing the
4c79b5
        # bond path and try to use the result as template.  This is
4c79b5
        # needed in those cases where you have a directory structure
4c79b5
        # with various levels of translations inside it and want to
4c79b5
        # apply the last available design template that match to all
4c79b5
        # translation files in the directory structure.
4c79b5
        if [[ ! -f "$SVG/${BOND}.svg" ]];then
4c79b5
            until [[ -f "$SVG/${BOND}.svg" ]] ;do
4c79b5
                [[ $BOND =~ '^(\.|/)$' ]] && break
4c79b5
                BOND=$(dirname $BOND)
4c79b5
            done
4c79b5
        fi
4c79b5
4c79b5
        # Possible configuration 2: If no template is found using the
4c79b5
        # previous bond paths reduction, then lets look using design
4c79b5
        # template and translation file base name bond only.  Use this
4c79b5
        # configuration as much as possible.  Note that it is much
4c79b5
        # more flexible than possible configuration 1.
4c79b5
        #
15b1d2
        # In this configuration, the pre-rendition configuration takes
4c79b5
        # the following form:
4c79b5
        #
4c79b5
        #  template.svg: \
4c79b5
        #     translation1.sed \
4c79b5
        #     translation2.sed
4c79b5
        #
4c79b5
        if [[ ! -f "$SVG/${BOND}.svg" ]];then
4c79b5
            BOND=$(basename $TRANSLATION)
4c79b5
        fi
4c79b5
  
4c79b5
        # Possible configuration 2.1: If not design template was found
4c79b5
        # with the .svg extension, lets try design template without
15b1d2
        # extension. This configuration is useful to render plain text
15b1d2
        # files that doesn't use an extension (e.g., see inside
07c2fe
        # `trunk/Identity/Release' directory structure).
4c79b5
        #
4c79b5
        #  template: \
4c79b5
        #     translation1.sed \
4c79b5
        #     translation2.sed
4c79b5
        #
4c79b5
        if [[ ! -f "$SVG/${BOND}.svg" ]] \
4c79b5
            && [[ ! -f $SVG/{$BOND} ]];then
4c79b5
            BOND=$(basename $TRANSLATION)
4c79b5
        fi
4c79b5
        
4c79b5
        # Define design template applying bond filtering.
4c79b5
        TEMPLATE=$(echo "${MATCHINGLIST}" \
4c79b5
            | egrep "$BOND" \
4c79b5
            | cut -d: -f1 \
4c79b5
            | sort )
4c79b5
4c79b5
        # Sometimes one BOND pattern can match more than one design
4c79b5
        # template (i.e. 2c-tm pattern match in: 2c-tm, 2c-tmd,
4c79b5
        # 2c-tmdr).  It makes no sence to apply one translation file
4c79b5
        # to many differnt design templates at the same time.  This
4c79b5
        # way we need to reduce the design templates found to just
4c79b5
        # one, the one matching the BOND translation path exactly,
4c79b5
        # without .sed extension.
4c79b5
        if [[ $(echo "$TEMPLATE" | wc -l ) -gt 1 ]];then
4c79b5
        
4c79b5
            # Remove `.sed' extension from BOND. This is required in
4c79b5
            # order to build the BOND design template correctly.
4c79b5
            BOND=$(echo $BOND | sed 's!\.sed$!!')
4c79b5
        
4c79b5
            # Reduce template designs found to match BOND design
4c79b5
            # template. Take into account design templates extensions.
4c79b5
            TEMPLATE=$(echo "$TEMPLATE" \
4c79b5
                | egrep "${BOND}(\.svg|\.html|\.htm)?$")
4c79b5
        
4c79b5
        fi
4c79b5
 
4c79b5
        # Sometimes we need to apply all translation files to a single
4c79b5
        # design template.  At this point, if there is no design
4c79b5
        # template available yet, look inside matching list and use
4c79b5
        # its value as design template for all translation files.
4c79b5
        if [[ "$TEMPLATE" == '' ]] \
4c79b5
            && [[ "$MATCHINGLIST" =~ '^[[:alnum:][:digit:][:punct:]]+(\.svg|\.html|\.htm)?$' ]];then
4c79b5
            TEMPLATE="$MATCHINGLIST"
4c79b5
        fi
4c79b5
        
4c79b5
        # If there is no template found at this point, we need to
4c79b5
        # prevent an empty template from being used. It is a missing
15b1d2
        # assignment definition in the pre-rendition script surely.
4c79b5
        if [[ "$TEMPLATE" == '' ]];then
07c2fe
            cli_printMessage "`eval_gettext "There is no design template defined for \\\`\\\$FILE'."`" 'AsErrorLine'
1f1b3c
            cli_printMessage "$(caller)" "AsToKnowMoreLine"
4c79b5
        fi
4c79b5
    
4c79b5
    fi
4c79b5
    
4c79b5
    # Remove any release number from design template's path.  Release
4c79b5
    # directories are used under Translations structure only.
4c79b5
    # Removing release numbers from design template path makes
4c79b5
    # possible to match many release-specific translations to the same
4c79b5
    # design template. There is no need to duplicate the release
4c79b5
    # structure inside design template structure.
4c79b5
    TEMPLATE=$(echo $TEMPLATE | sed -r "s!^${RELEASE_FORMAT}/!!")
4c79b5
    
4c79b5
    # Remove any language from design template's path. Language
4c79b5
    # code directories are used under Translation structure only.
4c79b5
    # Removing language code directories from design template path
4c79b5
    # makes possible to match many language translations to the
4c79b5
    # same design templates. There is no need to duplicate
4c79b5
    # language code directories inside design template structure.
4c79b5
    if [[ $TEMPLATE =~ '^[[:alpha:]]{2}(_[[:alpha:]]{2}){,1}/' ]];then
4c79b5
    
4c79b5
        # It seems like the first directory referes to a language
4c79b5
        # code. At this point we check if that value is a valid
4c79b5
        # language code. 
4c79b5
        if [[ "$(cli_getLangCodes $(echo $TEMPLATE | cut -d/ -f1))" != '' ]];then
4c79b5
    
4c79b5
            # The value is a valid language code. Remove it from path
4c79b5
            # so design template path can be built correctly.
4c79b5
            TEMPLATE=$(echo $TEMPLATE | sed "s!$(echo $TEMPLATE | cut -d/ -f1)/!!")
4c79b5
    
4c79b5
         fi
4c79b5
    fi
4c79b5
    
07c2fe
    # Redefine design template using absolute path.
4c79b5
    if [[ -f $SVG/$(basename $TEMPLATE) ]];then
4c79b5
        # Generally, template files are stored one level inside
4c79b5
        # Tpl/ directory.
4c79b5
        TEMPLATE=$SVG/$(basename $TEMPLATE)
4c79b5
    else
4c79b5
        # Others, template designs may be stored some levels inside
4c79b5
        # the template structure. At this point, we look deeper inside
4c79b5
        # template's directory structure and redefine template path.
4c79b5
        # Avoid using duplicated names inside template directory
4c79b5
        # structure. If there are duplicate names, the first one in
4c79b5
        # the list is used and the rest is discarded.
4c79b5
        TEMPLATE=$(find $SVG -regextype posix-egrep -regex \
4c79b5
            ".*/${TEMPLATE}" | sort | head -n 1)
4c79b5
    fi
4c79b5
    
e4d34a
    # Check existence of TEMPLATE file. If design template doesn't
e4d34a
    # exist we cannot render it; in such case, stop working for it and
e4d34a
    # try the next one in the list.
b76c02
    cli_checkFiles "$TEMPLATE"  'f'
5187da
    cli_printMessage "$TEMPLATE" 'AsSavedAsLine'
4c79b5
     
4c79b5
    # Get relative path to file. The path string (stored in FILE) has
4c79b5
    # two parts: 1. the variable path and 2. the common path.  The
4c79b5
    # variable path is before the common point in the path string. The
4c79b5
    # common path is after the common point in the path string. The
4c79b5
    # common point is the name of the parent directory (stored in
4c79b5
    # PARENTDIR).
4c79b5
    #
4c79b5
    # ... trunk/Translations/.../Firstboot/3/splash-small.sed
4c79b5
    # -------------------------^| the     |^------------^
4c79b5
    # variable path             | common  |    common path
4c79b5
    # -------------------------v| point   |    v------------v
4c79b5
    # ... trunk/Identity/Them.../Firstboot/Img/3/splash-small
4c79b5
    #
4c79b5
    # What we do here is remove the varibale path, the common point,
4c79b5
    # and the file extension parts in the string holding the path
4c79b5
    # retrived from translations structure. Then we use the common
4c79b5
    # path as relative path to the image file.
4c79b5
    #
4c79b5
    # The .sed file extension is removed from the common path.
4c79b5
    # Instead we assign the appropriate file extension when defining
4c79b5
    # file name.
4c79b5
    #
15b1d2
    # When we render using renderImage function, the structure of
4c79b5
    # files under Img/ directory will be the same of that used after
4c79b5
    # the common point in its related Translations or Template
4c79b5
    # directory depending in which one was taken as reference when
4c79b5
    # LOCATION variable was defined. 
4c79b5
    FILE=$(echo $FILE \
4c79b5
        | sed -r "s!.*${PARENTDIR}/!!" \
4c79b5
        | sed -r 's!\.(sed|svg|html|htm)$!!')
4c79b5
    
4c79b5
    # Re-define absolute path to directory holding image file.
4c79b5
    DIRNAME=$IMG/$(dirname $FILE)
4c79b5
    
4c79b5
    # Check existence of output image directory.
4c79b5
    if [[ ! -d $DIRNAME ]];then
4c79b5
        mkdir -p $DIRNAME
4c79b5
    fi
4c79b5
    
4c79b5
    # Define absolute path to file.
4c79b5
    FILE=$IMG/$FILE
4c79b5
4c79b5
    # Define instance name.
93705a
    INSTANCE=$(cli_getTemporalFile $TEMPLATE)
4c79b5
4c79b5
    # Remove template instance if it is already present.
4c79b5
    if [[ -a $INSTANCE ]];then
4c79b5
        rm $INSTANCE
4c79b5
    fi
4c79b5
4c79b5
    # Create the design template instance. When building the instance,
4c79b5
    # take into account the matching list and translation path. It
4c79b5
    # should be coherent with previous definitions above and in
8219f0
    # render_getFilesList.
4c79b5
    if [[ "${MATCHINGLIST}" == "" ]] \
4c79b5
        && [[ "${TRANSLATIONPATH}" != "" ]];then
4c79b5
   
4c79b5
        sed -f $TRANSLATION $TEMPLATE > $INSTANCE
4c79b5
   
4c79b5
    elif [[ "${MATCHINGLIST}" == "" ]] \
4c79b5
        && [[ "${TRANSLATIONPATH}" == "" ]];then
4c79b5
   
4c79b5
        cat $TEMPLATE > $INSTANCE
4c79b5
   
4c79b5
    elif [[ "${MATCHINGLIST}" != "" ]] \
4c79b5
        && [[ "${TRANSLATIONPATH}" == "" ]];then
4c79b5
   
4c79b5
        cat $TEMPLATE > $INSTANCE
4c79b5
   
4c79b5
    elif [[ "${MATCHINGLIST}" != "" ]] \
4c79b5
        && [[ "${TRANSLATIONPATH}" != "" ]];then
4c79b5
   
4c79b5
        sed -f $TRANSLATION $TEMPLATE > $INSTANCE
4c79b5
4c79b5
    fi
4c79b5
7ac81d
    # Replace common translation markers inside instance.
7ac81d
    render_doTranslationMarkers
7ac81d
4c79b5
}