|
|
4c79b5 |
#!/bin/bash
|
|
|
4c79b5 |
#
|
|
|
ff3ea9 |
# render_doIdentityGroupByTypes.sh -- This function provides
|
|
|
ff3ea9 |
# post-rendering and last-rendering action to group file inside
|
|
|
ff3ea9 |
# directories named as their file type.
|
|
|
4c79b5 |
#
|
|
|
7cd8e9 |
# Usage:
|
|
|
7cd8e9 |
# ------
|
|
|
7cd8e9 |
# Post-rendering --> render_doIdentityGroupByTypes "$FILE" "$ACTION"
|
|
|
7cd8e9 |
# Last-rendering --> render_doIdentityGroupByTypes "$ACTION"
|
|
|
4c79b5 |
#
|
|
|
7cd8e9 |
# Note that post-rendering uses 2 arguments ($FILE and $ACTION) and
|
|
|
7cd8e9 |
# last-rendering just one ($ACTION). This function uses the amount
|
|
|
7cd8e9 |
# of arguments to determine when it is acting as post-rendering and
|
|
|
7cd8e9 |
# when as last-rendering.
|
|
|
ff3ea9 |
#
|
|
|
ff3ea9 |
# This function create one directory for each different file type.
|
|
|
ff3ea9 |
# Later files are moved inside directories respectively. For example:
|
|
|
ff3ea9 |
# if the current file is a .png file, it is moved inside a Png/
|
|
|
ff3ea9 |
# directory; if the current file is a .jpg file, it is stored inside a
|
|
|
ff3ea9 |
# Jpg/ directory, and so on.
|
|
|
ff3ea9 |
#
|
|
|
ff3ea9 |
# For this function to work correctly, you need to specify which file
|
|
|
ff3ea9 |
# type you want to group. This is done in the post-rendering ACTIONS
|
|
|
ff3ea9 |
# array inside the appropriate `render.conf.sh' pre-configuration
|
|
|
ff3ea9 |
# script.
|
|
|
ff3ea9 |
#
|
|
|
ff3ea9 |
# For example, the following three lines will create one jpg, ppm,
|
|
|
ff3ea9 |
# xpm, and tif file for each png file available and groups them all by
|
|
|
ff3ea9 |
# its file type, inside directories named as their file type (i.e.
|
|
|
ff3ea9 |
# Png, Jpg, Ppm, Xpm, Tif). Note that in the example, groupByType is
|
|
|
ff3ea9 |
# ivoked as post-rendering action. If you want to invoke it as
|
|
|
ff3ea9 |
# last-rendering action use LAST definition instead of POST.
|
|
|
7cd8e9 |
#
|
|
|
7cd8e9 |
# ACTIONS[0]='BASE:renderImage'
|
|
|
7cd8e9 |
# ACTIONS[1]='POST:renderFormats: jpg, ppm, xpm, tif'
|
|
|
7cd8e9 |
# ACTIONS[2]='POST:groupByType: png, jpg, ppm, xpm, tif'
|
|
|
4c79b5 |
#
|
|
|
ff3ea9 |
# groupByType function is generally used with renderFormats function.
|
|
|
ff3ea9 |
# Both definitions must match the file type you want to have rendered
|
|
|
ff3ea9 |
# and grouped. You don't need to specify the png file type in
|
|
|
ff3ea9 |
# renderFormats' definition, but in groupByType's definition it must
|
|
|
ff3ea9 |
# be specified. Otherwise png files will not be grouped inside a png
|
|
|
ff3ea9 |
# directory.
|
|
|
4c79b5 |
#
|
|
|
7cd8e9 |
# Copyright (C) 2009, 2010 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 |
|
|
|
ff3ea9 |
function render_doIdentityGroupByType {
|
|
|
ff3ea9 |
|
|
|
ff3ea9 |
local FILE=''
|
|
|
ff3ea9 |
local -a FILES
|
|
|
ff3ea9 |
local -a PATTERNS
|
|
|
ff3ea9 |
local FORMATS=''
|
|
|
ff3ea9 |
local SOURCE=''
|
|
|
ff3ea9 |
local TARGET=''
|
|
|
ff3ea9 |
local COUNT=0
|
|
|
ff3ea9 |
|
|
|
ff3ea9 |
if [[ $# -eq 1 ]];then
|
|
|
ff3ea9 |
# Define file types for post-rendering action.
|
|
|
ff3ea9 |
FORMATS=$1
|
|
|
ff3ea9 |
elif [[ $# -eq 2 ]];then
|
|
|
ff3ea9 |
# Define file types for last-rendering action.
|
|
|
ff3ea9 |
FORMATS=$2
|
|
|
ff3ea9 |
else
|
|
|
ff3ea9 |
cli_printMessage "`gettext "groupByType: Wrong invokation."`"
|
|
|
ff3ea9 |
cli_printMessage $(caller) "AsToKnowMoreLine"
|
|
|
ff3ea9 |
fi
|
|
|
ff3ea9 |
|
|
|
ae8a10 |
# Sanitate file types passed from render.conf.sh pre-rendering
|
|
|
ff3ea9 |
# configuration script.
|
|
|
eb0e14 |
FORMATS=$(render_getConfOption "$FORMATS" '2-')
|
|
|
ff3ea9 |
|
|
|
ff3ea9 |
# Check file types passed from render.conf.sh pre-rendering
|
|
|
ff3ea9 |
# configuration script.
|
|
|
ff3ea9 |
if [[ "$FORMATS" == "" ]];then
|
|
|
eb0e14 |
cli_printMessage "`gettext "There is no file type information to process."`"
|
|
|
ff3ea9 |
cli_printMessage $(caller) "AsToKnowMoreLine"
|
|
|
ff3ea9 |
fi
|
|
|
ff3ea9 |
|
|
|
ff3ea9 |
if [[ $# -eq 1 ]];then
|
|
|
ff3ea9 |
|
|
|
ff3ea9 |
# Define pattern for file extensions.
|
|
|
ff3ea9 |
PATTERNS[0]=$(echo "$FORMATS" | sed 's! !|!g')
|
|
|
ff3ea9 |
|
|
|
ff3ea9 |
# Define pattern for directories.
|
|
|
a31714 |
PATTERNS[1]=$(echo $(for i in $FORMATS; do cli_getRepoName $i 'd'; done) | sed 's! !|!g')
|
|
|
ff3ea9 |
|
|
|
ff3ea9 |
# Define pattern for path. The path pattern combines both file
|
|
|
ff3ea9 |
# extension and directories patterns. This pattern is what we
|
|
|
ff3ea9 |
# use to match rendered file.
|
|
|
ff3ea9 |
PATTERNS[2]="^.*[^(${PATTERNS[1]})]/[[:alpha:]_-]+\.(${PATTERNS[0]})$"
|
|
|
ff3ea9 |
|
|
|
ff3ea9 |
# Define list of files to process when acting as
|
|
|
ff3ea9 |
# last-rendering action. There may be many different files to
|
|
|
ff3ea9 |
# process here, so we need to build a list with them all
|
|
|
ff3ea9 |
# (without duplications).
|
|
|
ff3ea9 |
for FILE in $(find $OPTIONVAL -regextype posix-egrep -type f -regex ${PATTERNS[2]} \
|
|
|
ff3ea9 |
| sed -r 's!\.[[:alpha:]]{1,4}$!!' | sort | uniq \
|
|
|
ff3ea9 |
| egrep $REGEX);do
|
|
|
ff3ea9 |
FILES[$COUNT]="$FILE"
|
|
|
ff3ea9 |
COUNT=$(($COUNT + 1))
|
|
|
ff3ea9 |
done
|
|
|
4c79b5 |
|
|
|
ff3ea9 |
elif [[ $# -eq 2 ]];then
|
|
|
4c79b5 |
|
|
|
ff3ea9 |
# Define list of files to process when action as
|
|
|
ff3ea9 |
# post-rendering action. There is just one value to process
|
|
|
ff3ea9 |
# here, the one being currently rendered.
|
|
|
ff3ea9 |
FILES[0]="$1"
|
|
|
ff3ea9 |
|
|
|
ff3ea9 |
fi
|
|
|
4c79b5 |
|
|
|
ff3ea9 |
# Start processing list of files.
|
|
|
ff3ea9 |
for FILE in "${FILES[@]}";do
|
|
|
4c79b5 |
|
|
|
ff3ea9 |
for FORMAT in $FORMATS;do
|
|
|
4c79b5 |
|
|
|
ff3ea9 |
# Redifine file path to add file type directory
|
|
|
ff3ea9 |
SOURCE=${FILE}.${FORMAT}
|
|
|
a31714 |
TARGET=$(dirname $FILE)/$(cli_getRepoName "$FORMAT" 'd')
|
|
|
4c79b5 |
|
|
|
ff3ea9 |
# Check existence of source file.
|
|
|
b76c02 |
cli_checkFiles $SOURCE 'f'
|
|
|
4c79b5 |
|
|
|
ff3ea9 |
# Check existence of target directory.
|
|
|
b76c02 |
cli_checkFiles $TARGET 'd'
|
|
|
4c79b5 |
|
|
|
ff3ea9 |
# Redifine file path to add file and its type.
|
|
|
ff3ea9 |
TARGET=${TARGET}/$(basename $FILE).${FORMAT}
|
|
|
4c79b5 |
|
|
|
ff3ea9 |
# Move file into its final location.
|
|
|
ff3ea9 |
cli_printMessage "$TARGET" 'AsMovedToLine'
|
|
|
ff3ea9 |
mv ${SOURCE} ${TARGET}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
done
|
|
|
4c79b5 |
|
|
|
ff3ea9 |
done
|
|
|
4c79b5 |
|
|
|
4c79b5 |
}
|