diff --git a/Scripts/Bash/Functions/Svg/svg.sh b/Scripts/Bash/Functions/Svg/svg.sh new file mode 100755 index 0000000..24a6acb --- /dev/null +++ b/Scripts/Bash/Functions/Svg/svg.sh @@ -0,0 +1,42 @@ +#!/bin/bash +# +# svg.sh -- This function provides very basic SVG manipulations to +# help maintain svg files inside the repository. +# +# Copyright (C) 2009-2010 Alain Reguera Delgado +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +# USA. +# +# ---------------------------------------------------------------------- +# $Id$ +# ---------------------------------------------------------------------- + +function svg { + + local FILES='' + + # Define list of scalable vector graphic files to process using + # option value as reference. + if [[ -d $OPTIONVAL ]];then + FILES=$(find $OPTIONVAL -regextype posix-egrep -type f -regex '.*/*.svg$') + elif [[ -f $OPTIONVAL ]];then + FILES=$OPTIONVAL + fi + + # Define command line interface for svg-based actions. + svg_getActions + +} diff --git a/Scripts/Bash/Functions/Svg/svg_getActions.sh b/Scripts/Bash/Functions/Svg/svg_getActions.sh new file mode 100755 index 0000000..6670793 --- /dev/null +++ b/Scripts/Bash/Functions/Svg/svg_getActions.sh @@ -0,0 +1,46 @@ +#!/bin/bash +# +# svg_getActions.sh -- This function initializes SVG string +# manipulation functionalities, using the option value of +# centos-art.sh script as reference. +# +# Copyright (C) 2009-2010 Alain Reguera Delgado +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +# USA. +# +# ---------------------------------------------------------------------- +# $Id$ +# ---------------------------------------------------------------------- + +function svg_getActions { + + # Evaluate option name and define which actions does centos-art.sh + # script supports. + case $OPTIONNAM in + + '--update-metadata' ) + # Update metadata inside svg files using metadata + # templates. + svg_updateMetadata + ;; + + * ) + cli_printMessage "`eval_gettext "The option provided is not valid."`" + ;; + + esac + +} diff --git a/Scripts/Bash/Functions/Svg/svg_updateMetadata.sh b/Scripts/Bash/Functions/Svg/svg_updateMetadata.sh new file mode 100755 index 0000000..7d5e8a2 --- /dev/null +++ b/Scripts/Bash/Functions/Svg/svg_updateMetadata.sh @@ -0,0 +1,137 @@ +#!/bin/bash +# +# svg_updateMetadata.sh -- This function replaces metadata section +# inside scalable vector graphic (SVG) files with one of pre-defined +# metadata templates available. Use this function to maintain metadata +# information inside repository. +# +# Usage: +# centos-art svg --update-metadata=path/to/dir --filter=filename +# +# In the above usage example `path/to/dir' represents the parent +# directory where scalable vector graphics you want to update metadata +# information are. The `--filter=filename' is optional and if provided +# just the file specificed is affected. Otherwise all files ending in +# `.svg' are massively modified. +# +# Copyright (C) 2009-2010 Alain Reguera Delgado +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +# USA. +# +# ---------------------------------------------------------------------- +# $Id$ +# ---------------------------------------------------------------------- + +function svg_updateMetadata { + + local TITLE='' + local DATE='' + local CREATOR='' + local RIGHTS='' + local PUBLISHER='' + local COVERAGE='' + local TEMPLATES='' + local KEYWORDS='' + local INSTANCE='' + + # Define absolute path to metadata templates parent directory. + # This is the place where we store metadata template files. + TEMPLATES=~/artwork/trunk/Scripts/Bash/Functions/Svg/Tpl + + # Define metadata template file we want to apply. More than one + # metadata template file may exist, so let choosing which one to + # use. + cli_printMessage "`gettext "Select the metadata template you want to apply:"`" + select TEMPLATE in $(ls $TEMPLATES);do + TEMPLATE=$TEMPLATES/$TEMPLATE + break + done + + # Check metadata template file existence. + cli_checkFiles $TEMPLATE 'f' '' '--quiet' + if [[ $? -ne 0 ]];then + cli_printMessage "`gettext "The template file you provided doesn't exist."`" + cli_printMessage "$(caller)" 'AsToKnowMoreLine' + fi + + # Define metadata template instance. + INSTANCE=${TMPFILE}-$(basename $TEMPLATE) + + # Define svg document date. + DATE=$(date +%Y-%m-%d) + + # Define svg document creator. + CREATOR='CentOS Artwork SIG' + + # Define svg document rights. + RIGHTS=$CREATOR + + # Define svg document publisher. + PUBLISHER='The CentOS Project' + + # Define svg document coverage. + COVERAGE=$PUBLISHER + + for FILE in $FILES;do + + # Define svg document title. + TITLE=$(basename $FILE) + + # Define svg document keywords. + KEYWORDS=$(echo $FILE | cut -d/ -f6- | tr '/' '\n') + + # Redifine keywords using SVG standard format. Note that this + # information is inserted inside metadata template file. The + # metadata template file is a replacement set of sed commands + # so we need to escape the new line of each line using one + # backslash (\). As we are doing this inside bash, it is + # required to escape the backslash with another backslash so + # it passes literally. + KEYWORDS=$(\ + for KEY in $KEYWORDS;do + echo " $KEY\\" + done) + + # Create metadata template instance. + sed -r \ + -e "s!=TITLE=!$TITLE!" \ + -e "s!=DATE=!$DATE!" \ + -e "s!=CREATOR=!$CREATOR!" \ + -e "s!=RIGHTS=!$RIGHTS!" \ + -e "s!=PUBLISHER=!$PUBLISHER!" \ + -e "s!=COVERAGE=!$COVERAGE!" \ + -e "/=KEYWORDS=/c\\${KEYWORDS}" \ + $TEMPLATE > $INSTANCE + sed -i -r -e 's/>$/>\\/g' $INSTANCE + + # Apply metadata template instance to scalable vector graphic + # file. + sed -i -f $INSTANCE $FILE + + # Remove metadata template instance. + cli_checkFiles $INSTANCE 'f' '' '--quiet' + if [[ $? -eq 0 ]];then + rm $INSTANCE + fi + + done \ + | awk -f /home/centos/artwork/trunk/Scripts/Bash/Styles/output_forTwoColumns.awk + + # Check repository changes and ask you to commit them up to + # central repository. + cli_commitRepoChanges + +}