Blame Scripts/Bash/Functions/cli_getThemeName.sh

4c79b5
#!/bin/bash
4c79b5
#
fa8567
# cli_getThemeName.sh -- This function interprets the current
fa8567
# absolute path ---defined in action value variable--- to extract the
fa8567
# theme name from it. If theme name is found on absolute path, this
fa8567
# function returns an empty string. 
63bc52
#
437221
# Copyright (C) 2009-2011 Alain Reguera Delgado
4c79b5
# 
4c79b5
# This program is free software; you can redistribute it and/or
4c79b5
# modify it under the terms of the GNU General Public License as
4c79b5
# published by the Free Software Foundation; either version 2 of the
4c79b5
# 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 cli_getThemeName {
4c79b5
fa8567
    # Initialize regular expression pattern.
fa8567
    local PATTERN=''
fa8567
07efa3
    if [[ $ACTIONVAL =~ '^/home/centos/artwork/(trunk|branches|tags)/.*$' ]];then
fa8567
07efa3
        # Define theme name for trunk, branches, and tags directory
07efa3
        # structures.
07efa3
        #
07efa3
        # trunk:
07efa3
        # ------
07efa3
        # Themes are made of `Models' and `Motifs'. `Models' controls
07efa3
        # the `Motifs' characteristcs and it is not rendereable. On
07efa3
        # the other hand, `Motifs' controls the theme visual style and
07efa3
        # do is renderable. Since we only need to know the theme name
07efa3
        # when we render something, we take the `Motifs' directory
07efa3
        # structure as reference to find out the theme name we are
07efa3
        # producing images for.
07efa3
        #
07efa3
        # `Motifs' are organized by names, so when we say `a theme
07efa3
        # name' we are really saying `the artistic motif name of a
07efa3
        # theme', but for short `theme name' is used instead. `Models'
07efa3
        # are also organized by names, but we do never use model names
07efa3
        # to name a thame. We always say the `theme models' or `the
07efa3
        # models of the theme` to refere the theme component that
07efa3
        # controls the characteristics of artistic motifs. We never
07efa3
        # name a thame as its model. We use artistic motifs name for
07efa3
        # such purpose.
07efa3
        #
07efa3
        # Inside artistic motif names, we organize different versions
07efa3
        # of the same artistic motif by means of numerical worklines.
07efa3
        # Worklines, inside trunk, have an integer numerical form and
07efa3
        # begin at `1'. They increment one unit each time a new/fresh
07efa3
        # visual style ---for the same artistic motif--- is conceived.
07efa3
        #
07efa3
        # For example, the Flame theme uses the flame filter of Gimp
07efa3
        # to produce different fractal patterns randomly. We use the
07efa3
        # flame filter to produce different visual styles under the
07efa3
        # same theme since all patterns we produce are based on the
07efa3
        # same pattern (i.e., the random fractal pattern of Gimp's
07efa3
        # flame filter). This way, if you no longer want to produce
07efa3
        # visual styles from flame filter, it is time to create a new
07efa3
        # artistic motif name for it.
07efa3
        #
07efa3
        # This schema is very convenient for designers and packagers,
07efa3
        # since different designers can create their own worklines and
07efa3
        # go on with them until CentOS distribution release date is
07efa3
        # close. At that time, a workline is selected and tagged for
07efa3
        # packaging. Translators and programmers can continue working
07efa3
        # indepently, and without affection, in their own directory
07efa3
        # structures.
07efa3
        #
07efa3
        #   Example:
07efa3
        #                               +------> theme name
07efa3
        #                           |-->| 
07efa3
        #   trunk/.../Themes/Motifs/Flame/1
07efa3
        #   trunk/.../Themes/Motifs/Flame/2 
07efa3
        #   trunk/.../Themes/Motifs/Flame/3
07efa3
        #                                 |
07efa3
        #                                 +----> theme release version
07efa3
        #
07efa3
        # Sometimes we only need to retrive the theme name, but
07efa3
        # othertimes both the theme name and its work-line is
07efa3
        # required as well.
07efa3
        #
07efa3
        # branches:
07efa3
        # ---------
07efa3
        # The branch development line is treated just as trunk
07efa3
        # development line does, but we rarely use it since it could
07efa3
        # be confusing to know whether a tag was created from trunk or
07efa3
        # branches.
07efa3
        #
07efa3
        # Conceive an enumeration schema in order to differentiate
07efa3
        # branches from trunk is not convenient either, it would
07efa3
        # introduce an intermediate point to the final production of
07efa3
        # tags we would need to be aware of.  Instead of such
07efa3
        # configuration, we prefer to go straightforward from trunk to
07efa3
        # tags.
07efa3
        #
07efa3
        # Intermediate branches for quality assurance might be good in
07efa3
        # some situations, but not when we produce themes. We need a
07efa3
        # simple structure, where we could design, render content
07efa3
        # (using centos-art.sh), and release for testing (through
07efa3
        # tags).  If something goes wrong in the released tag, it
07efa3
        # would be fixed in trunk and later released in another tagged
07efa3
        # relase.
07efa3
        #
07efa3
        # Of course, care should be taken to avoid making of trunk
07efa3
        # development line a chaotic place.  Everbody should know
07efa3
        # exactly what they are doing therein. We need to design
07efa3
        # protections to isolate possible damages and that way, we
07efa3
        # could know exactly what and where we need to concentrate in
07efa3
        # and put our time on.
07efa3
        #
07efa3
        # In resume, do not use branches if you don't need to.  Use
07efa3
        # trunk development line instead.
07efa3
        #
07efa3
        # tags:
07efa3
        # -----
07efa3
        # The tag frozen line is mainly used to perform theme
07efa3
        # releases.
07efa3
        #
07efa3
        #   Example:
07efa3
        #                                  +------> theme name
07efa3
        #                              |-->| 
07efa3
        #       tags/.../Themes/Motifs/Flame/1.0
07efa3
        #      trunk/.../Themes/Motifs/Flame/1 |--> minor update
07efa3
        #                                    |----> major udpate
07efa3
        #
07efa3
        # Tags have the format X.Z, where X is the first number in the
07efa3
        # name (e.g., `1') and represents the trunk/branches artistic
07efa3
        # motif version. The Z represents the second number in the
07efa3
        # name (e.g., `0') which is the tag version itself.  
07efa3
        #
07efa3
        # Tag versions start at `0' and increment one unit each time a
07efa3
        # new tag is created from the same artistic motif version.
07efa3
        # When a new tag is created for the same artistic motif
07efa3
        # version, the first number in the tag name remains intact.
07efa3
        # The first number in the tag name only changes when we create
07efa3
        # a new tag for a new artistic motif version.
07efa3
        #
07efa3
        #   Consider the following relations: 
07efa3
        #
07efa3
        #       trunk/.../Themes/Motifs/Flame/1
07efa3
        #       tags/.../Themes/Motifs/Flame/1.0
07efa3
        #       tags/.../Themes/Motifs/Flame/1.1
07efa3
        #       tags/.../Themes/Motifs/Flame/1.2
07efa3
        #
07efa3
        #       trunk/.../Themes/Motifs/Flame/2
07efa3
        #       tags/.../Themes/Motifs/Flame/2.0
07efa3
        #       tags/.../Themes/Motifs/Flame/2.1
07efa3
        #       tags/.../Themes/Motifs/Flame/2.2
07efa3
        #
07efa3
        #       trunk/.../Themes/Motifs/TreeFlower/1
07efa3
        #       tags/.../Themes/Motifs/TreeFlower/1.0
07efa3
        #       tags/.../Themes/Motifs/TreeFlower/1.1
07efa3
        #       ...
07efa3
        #       and so on. 
07efa3
        #
07efa3
        # Tag versions are created to release fixes and improvements,
07efa3
        # Tags are immutable (i.e., once tags are created, they
07efa3
        # shouldn't be modified.).
07efa3
        PATTERN="^.+/Identity/Themes/Motifs/(([A-Za-z0-9]+)/(${RELEASE_FORMAT})).+$"
fa8567
fa8567
    else
fa8567
        cli_printMessage "`gettext "The working copy parent directory structure is incorrect."`" 'AsErrorLine'
fa8567
        cli_printMessage "$(caller)" 'AsToKnowMoreLine'
4c79b5
    fi
4c79b5
63bc52
    # Print theme name to standard output.
07efa3
    case "$1" in
07efa3
        '--name' )
07efa3
            echo $ACTIONVAL | sed -r "s!${PATTERN}!\2!"
07efa3
            ;;
07efa3
        '--release' )
07efa3
            echo $ACTIONVAL | sed -r "s!${PATTERN}!\3!"
07efa3
            ;;
07efa3
        '--none' )
07efa3
            echo $ACTIONVAL | sed -r "s!${PATTERN}!!"
07efa3
            ;;
07efa3
        '--both'|* )
07efa3
            echo $ACTIONVAL | sed -r "s!${PATTERN}!\1!"
07efa3
            ;;
07efa3
    esac
63bc52
4c79b5
}