Blame Scripts/Functions/Render/render_groupSimilarFiles.sh

4c79b5
#!/bin/bash
4c79b5
#
ab1d67
# render_groupSimilarFiles.sh -- This function provides
d52b32
# post-rendition action to group files inside directories named as
d52b32
# their file extensions.  For example: if the current file is a .png
d52b32
# file, it is moved inside a Png/ directory; if the current file is a
d52b32
# .jpg file, it is stored 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
#
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
ab1d67
function render_groupSimilarFiles {
ff3ea9
ff3ea9
    local SOURCE=''
ff3ea9
    local TARGET=''
ff3ea9
15b1d2
    # Sanitate file types passed from render.conf.sh pre-rendition
ff3ea9
    # configuration script.
ab1d67
    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.
d52b32
        TARGET=$(dirname "$FILE")/$(cli_getRepoName "$FORMAT" 'd')
4c79b5
d52b32
        # Check existence of source file.
d52b32
        cli_checkFiles $SOURCE 'f'
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.
d52b32
        TARGET=${TARGET}/$(cli_getRepoName "$FILE" 'f').${FORMAT}
4c79b5
d52b32
        # Move file into its final location.
d52b32
        cli_printMessage "$TARGET" 'AsMovedToLine'
d52b32
        mv ${SOURCE} ${TARGET}
4c79b5
ff3ea9
    done
4c79b5
4c79b5
}