Blame Scripts/CentOS-Art/Functions/Render/Svg/svg_groupBy.sh

4c79b5
#!/bin/bash
4c79b5
#
3a5418
# svg_groupBy.sh -- This function provides post-rendition action to
3a5418
# group files inside directories named as their file extensions.  For
3a5418
# example: if the current file is a .png file, it is moved inside a
3a5418
# Png/ directory; if the current file is a .jpg file, it is stored
3a5418
# inside a Jpg/ directory, and so on.
ff3ea9
#
ff3ea9
# For this function to work correctly, you need to specify which file
15b1d2
# type you want to group. This is done in the post-rendition ACTIONS
ff3ea9
# array inside the appropriate `render.conf.sh' pre-configuration
d52b32
# script. This function cannot be used as last-rendition action.
ff3ea9
#
2fe9b7
# Copyright (C) 2009, 2010, 2011 The CentOS Project
fa95b1
#
fa95b1
# This program is free software; you can redistribute it and/or modify
fa95b1
# it under the terms of the GNU General Public License as published by
dcd347
# the Free Software Foundation; either version 2 of the License, or (at
dcd347
# your option) any later version.
fa95b1
#
74a058
# This program is distributed in the hope that it will be useful, but
74a058
# 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
dcd347
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
7ac5a5
#
4c79b5
# ----------------------------------------------------------------------
418249
# $Id$
4c79b5
# ----------------------------------------------------------------------
4c79b5
3a5418
function svg_groupBy {
ff3ea9
ff3ea9
    local SOURCE=''
ff3ea9
    local TARGET=''
ff3ea9
15b1d2
    # Sanitate file types passed from render.conf.sh pre-rendition
ff3ea9
    # configuration script.
3a5418
    local FORMAT=''
8c13b6
    local FORMATS=$(render_getConfigOption "$ACTION" '2-')
4c79b5
d52b32
    for FORMAT in $FORMATS;do
f94e5c
d52b32
        # Redifine source file we want to move.
d52b32
        SOURCE=${FILE}.${FORMAT}
4c79b5
d52b32
        # Define target directory where source file will be moved
d52b32
        # into.
cfe42b
        TARGET=$(dirname "$FILE")/$(cli_getRepoName $FORMAT -d)
4c79b5
d52b32
        # Check existence of source file.
d7dbba
        cli_checkFiles $SOURCE
4c79b5
d52b32
        # Check existence of target directory.
d52b32
        if [[ ! -d $TARGET ]];then
d52b32
            mkdir -p $TARGET
d52b32
        fi
4c79b5
d52b32
        # Redifine file path to add file and its type.
cfe42b
        TARGET=${TARGET}/$(cli_getRepoName $FILE -f).${FORMAT}
4c79b5
d52b32
        # Move file into its final location.
0ff158
        cli_printMessage "$TARGET" --as-movedto-line
d52b32
        mv ${SOURCE} ${TARGET}
4c79b5
ff3ea9
    done
4c79b5
4c79b5
}