Blame Scripts/Bash/Functions/Svg/svg_updateMetadata.sh

641be4
#!/bin/bash
641be4
#
641be4
# svg_updateMetadata.sh -- This function replaces metadata section
641be4
# inside scalable vector graphic (SVG) files with one of pre-defined
641be4
# metadata templates available. Use this function to maintain metadata
641be4
# information inside repository.
641be4
#
641be4
#   Usage:
641be4
#   centos-art svg --update-metadata=path/to/dir --filter=filename
641be4
#
641be4
# In the above usage example `path/to/dir' represents the parent
641be4
# directory where scalable vector graphics you want to update metadata
641be4
# information are. The `--filter=filename' is optional and if provided
641be4
# just the file specificed is affected. Otherwise all files ending in
641be4
# `.svg' are massively modified.
641be4
#
641be4
# Copyright (C) 2009-2010 Alain Reguera Delgado
641be4
# 
641be4
# This program is free software; you can redistribute it and/or modify
641be4
# it under the terms of the GNU General Public License as published by
641be4
# the Free Software Foundation; either version 2 of the License, or
641be4
# (at your option) any later version.
641be4
# 
641be4
# This program is distributed in the hope that it will be useful, but
641be4
# WITHOUT ANY WARRANTY; without even the implied warranty of
641be4
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
641be4
# General Public License for more details.
641be4
#
641be4
# You should have received a copy of the GNU General Public License
641be4
# along with this program; if not, write to the Free Software
641be4
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
641be4
# USA.
641be4
#
641be4
# ----------------------------------------------------------------------
641be4
# $Id$
641be4
# ----------------------------------------------------------------------
641be4
641be4
function svg_updateMetadata {
641be4
641be4
    local TITLE=''
641be4
    local DATE=''
641be4
    local CREATOR=''
641be4
    local RIGHTS=''
641be4
    local PUBLISHER=''
641be4
    local COVERAGE=''
641be4
    local TEMPLATES=''
641be4
    local KEYWORDS=''
641be4
    local INSTANCE=''
641be4
641be4
    # Define absolute path to metadata templates parent directory.
641be4
    # This is the place where we store metadata template files.
641be4
    TEMPLATES=~/artwork/trunk/Scripts/Bash/Functions/Svg/Tpl
641be4
641be4
    # Define metadata template file we want to apply. More than one
641be4
    # metadata template file may exist, so let choosing which one to
641be4
    # use.
641be4
    cli_printMessage "`gettext "Select the metadata template you want to apply:"`"
641be4
    select TEMPLATE in $(ls $TEMPLATES);do
641be4
       TEMPLATE=$TEMPLATES/$TEMPLATE
641be4
       break
641be4
    done
641be4
641be4
    # Check metadata template file existence.
b76c02
    cli_checkFiles $TEMPLATE 'f'
641be4
641be4
    # Define metadata template instance.
641be4
    INSTANCE=${TMPFILE}-$(basename $TEMPLATE)
641be4
641be4
    # Define svg document date.
641be4
    DATE=$(date +%Y-%m-%d)
641be4
641be4
    # Define svg document creator.
641be4
    CREATOR='CentOS Artwork SIG'
641be4
641be4
    # Define svg document rights.
641be4
    RIGHTS=$CREATOR
641be4
641be4
    # Define svg document publisher.
641be4
    PUBLISHER='The CentOS Project'
641be4
641be4
    # Define svg document coverage.
641be4
    COVERAGE=$PUBLISHER
641be4
641be4
    for FILE in $FILES;do
641be4
641be4
        # Define svg document title.
641be4
        TITLE=$(basename $FILE)
641be4
641be4
        # Define svg document keywords.
641be4
        KEYWORDS=$(echo $FILE | cut -d/ -f6- | tr '/' '\n')
641be4
641be4
        # Redifine keywords using SVG standard format. Note that this
641be4
        # information is inserted inside metadata template file. The
641be4
        # metadata template file is a replacement set of sed commands
641be4
        # so we need to escape the new line of each line using one
641be4
        # backslash (\). As we are doing this inside bash, it is
641be4
        # required to escape the backslash with another backslash so
641be4
        # it passes literally.
641be4
        KEYWORDS=$(\
641be4
           for KEY in $KEYWORDS;do
641be4
              echo "            <rdf:li>$KEY</rdf:li>\\"
641be4
           done)
641be4
641be4
        # Create metadata template instance.
641be4
        sed -r \
641be4
            -e "s!=TITLE=!$TITLE!" \
641be4
            -e "s!=DATE=!$DATE!" \
641be4
            -e "s!=CREATOR=!$CREATOR!" \
641be4
            -e "s!=RIGHTS=!$RIGHTS!" \
641be4
            -e "s!=PUBLISHER=!$PUBLISHER!" \
641be4
            -e "s!=COVERAGE=!$COVERAGE!" \
641be4
            -e "/=KEYWORDS=/c\\${KEYWORDS}" \
641be4
            $TEMPLATE > $INSTANCE
641be4
        sed -i -r -e 's/>$/>\\/g' $INSTANCE
641be4
641be4
        # Apply metadata template instance to scalable vector graphic
641be4
        # file.
641be4
        sed -i -f $INSTANCE $FILE
641be4
641be4
        # Remove metadata template instance.
b76c02
        cli_checkFiles $INSTANCE 'f'
b76c02
        rm $INSTANCE
641be4
641be4
    done \
641be4
        | awk -f /home/centos/artwork/trunk/Scripts/Bash/Styles/output_forTwoColumns.awk
641be4
641be4
    # Check repository changes and ask you to commit them up to
641be4
    # central repository.
641be4
    cli_commitRepoChanges
641be4
641be4
}