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
#
2d3646
# 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
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
}