From 30f920b707d3b80391d4f335445d4119d5f3040b Mon Sep 17 00:00:00 2001 From: Alain Reguera Delgado Date: Jul 06 2011 15:34:57 +0000 Subject: Update `tuneup' functionality: - Move Svg, Shell and Xhtml directories from `tuneup/Backends' directory to `tuneup/' directory and remove `tuneup/Backends' directory from the structure. --- diff --git a/Scripts/Functions/Tuneup/Backends/Shell/Config/topcomment.sed b/Scripts/Functions/Tuneup/Backends/Shell/Config/topcomment.sed deleted file mode 100644 index 0b3077f..0000000 --- a/Scripts/Functions/Tuneup/Backends/Shell/Config/topcomment.sed +++ /dev/null @@ -1,55 +0,0 @@ -#!/bin/sed -# -# topcomment.sed -- This file standardizes the top comment inside -# centos-art.sh scripts. -# -# Copyright (C) 2009, 2010, 2011 The CentOS Artwork SIG -# -# 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., 675 Mass Ave, Cambridge, MA 02139, USA. -# -# ---------------------------------------------------------------------- -# $Id$ -# ---------------------------------------------------------------------- -/^# +Copyright .*$/a\ -# Copyright (C) =COPYRIGHT_YEAR_LIST= =COPYRIGHT_HOLDER=\ -#\ -# 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., 675 Mass Ave, Cambridge, MA 02139, USA.\ -#\ -# ---------------------------------------------------------------------- - -# Remove previous copyright notice, just to be sure the one above be -# used always. -/^# +Copyright .*$/,/^# -{70}$/{ -d -} - -# Remove more than one space after comments. -s/^# +/# / - -# Define script first line. -1c\ -#!/bin/bash diff --git a/Scripts/Functions/Tuneup/Backends/Shell/shell.sh b/Scripts/Functions/Tuneup/Backends/Shell/shell.sh deleted file mode 100755 index 884ad8f..0000000 --- a/Scripts/Functions/Tuneup/Backends/Shell/shell.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/bash -# -# shell.sh -- This function standardizes maintainance tasks for Shell -# script files. -# -# Copyright (C) 2009, 2010, 2011 The CentOS Artwork SIG -# -# 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., 675 Mass Ave, Cambridge, MA 02139, USA. -# -# ---------------------------------------------------------------------- -# $Id$ -# ---------------------------------------------------------------------- - -function shell { - - # Define backend-specific configuration directory. - TUNEUP_BACKEND_CONFIG="${TUNEUP_BACKEND_DIR}/$(cli_getRepoName ${TUNEUP_BACKEND} -d)/Config" - - # Rebuild top comment inside shell scripts, mainly to update - # copyright information. - ${TUNEUP_BACKEND}_doTopComment - -} diff --git a/Scripts/Functions/Tuneup/Backends/Shell/shell_doTopComment.sh b/Scripts/Functions/Tuneup/Backends/Shell/shell_doTopComment.sh deleted file mode 100755 index bcf74fa..0000000 --- a/Scripts/Functions/Tuneup/Backends/Shell/shell_doTopComment.sh +++ /dev/null @@ -1,55 +0,0 @@ -#!/bin/bash -# -# shell_doTopComment.sh -- This function standardizes the top comment -# section inside shell scripts (*.sh) using a predefined template. -# -# Copyright (C) 2009, 2010, 2011 The CentOS Artwork SIG -# -# 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., 675 Mass Ave, Cambridge, MA 02139, USA. -# -# ---------------------------------------------------------------------- -# $Id$ -# ---------------------------------------------------------------------- - -function shell_doTopComment { - - # Define absolute path to template file. - local TEMPLATE="${TUNEUP_BACKEND_CONFIG}/topcomment.sed" - - # Check template file existence. - cli_checkFiles $TEMPLATE - - # Define file name to template instance. - local INSTANCE=$(cli_getTemporalFile $TEMPLATE) - - # Create template instance. - cp $TEMPLATE $INSTANCE - - # Check template instance. We cannot continue if template instance - # couldn't be created. - cli_checkFiles $INSTANCE - - # Expand translation markers in template instance. - cli_replaceTMarkers $INSTANCE - - # Apply template instance to file. - sed -r -i -f $INSTANCE $FILE - - # Remove template instance. - if [[ -f ${INSTANCE} ]];then - rm ${INSTANCE} - fi - -} diff --git a/Scripts/Functions/Tuneup/Backends/Svg/Config/metadata.sed b/Scripts/Functions/Tuneup/Backends/Svg/Config/metadata.sed deleted file mode 100644 index 199c44d..0000000 --- a/Scripts/Functions/Tuneup/Backends/Svg/Config/metadata.sed +++ /dev/null @@ -1,64 +0,0 @@ -# This file is the metadata information used by CentOS Artwork SIG on -# its scalable vector graphics (SVG) files. This files is used with -# the regular expression '.*\.svg$' only. -# --------------------------------------------------- -# $Id$ -# --------------------------------------------------- -/\ - \ - \ - image/svg+xml\ - \ - \ - =TITLE=\ - =DATE=\ - \ - \ - =COPYRIGHT_HOLDER=\ - \ - \ - \ - \ - =COPYRIGHT_HOLDER=\ - \ - \ - \ - \ - =COPYRIGHT_HOLDER=\ - \ - \ - =URL=\ - =URL=\ - =URL=\ - =LOCALE=\ - \ - \ -=KEYWORDS=\ - \ - \ - =COPYRIGHT_HOLDER=\ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - diff --git a/Scripts/Functions/Tuneup/Backends/Svg/svg.sh b/Scripts/Functions/Tuneup/Backends/Svg/svg.sh deleted file mode 100755 index d3bb352..0000000 --- a/Scripts/Functions/Tuneup/Backends/Svg/svg.sh +++ /dev/null @@ -1,36 +0,0 @@ -#!/bin/bash -# -# svg.sh -- This function standardizes maintainance of SVG files. -# -# Copyright (C) 2009, 2010, 2011 The CentOS Artwork SIG -# -# 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., 675 Mass Ave, Cambridge, MA 02139, USA. -# -# ---------------------------------------------------------------------- -# $Id$ -# ---------------------------------------------------------------------- - -function svg { - - # Define backend-specific configuration directory. - TUNEUP_BACKEND_CONFIG="${TUNEUP_BACKEND_DIR}/$(cli_getRepoName ${TUNEUP_BACKEND} -d)/Config" - - # Update metadata information. - ${TUNEUP_BACKEND}_doMetadata - - # Remove all unused items. - ${TUNEUP_BACKEND}_doVacuumDefs - -} diff --git a/Scripts/Functions/Tuneup/Backends/Svg/svg_doMetadata.sh b/Scripts/Functions/Tuneup/Backends/Svg/svg_doMetadata.sh deleted file mode 100755 index 61832dd..0000000 --- a/Scripts/Functions/Tuneup/Backends/Svg/svg_doMetadata.sh +++ /dev/null @@ -1,88 +0,0 @@ -#!/bin/bash -# -# svg_doMetadata.sh -- This function updates metadata values inside -# scalable vector graphic (SVG) files using default values from The -# CentOS Project. -# -# Copyright (C) 2009, 2010, 2011 The CentOS Artwork SIG -# -# 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., 675 Mass Ave, Cambridge, MA 02139, USA. -# -# ---------------------------------------------------------------------- -# $Id$ -# ---------------------------------------------------------------------- - -function svg_doMetadata { - - # Define template file name. - local TEMPLATE="${TUNEUP_BACKEND_CONFIG}/metadata.sed" - - # Check template file existence. - cli_checkFiles $TEMPLATE - - # Build title from file path. - local TITLE=$(basename "$FILE") - - # Build url from file path. - local URL=$(echo $FILE | sed 's!/home/centos!https://projects.centos.org/svn!') - - # Build keywords from file path. Do not include filename, it is - # already on title. - local KEY='' - local KEYS=$(dirname "$FILE" | cut -d/ -f6- | tr '/' '\n') - - # Build keywords using SVG standard format. Note that this - # information is inserted inside template file. The 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 one of them passes literally to template - # file. - KEYS=$(\ - for KEY in $KEYS;do - echo " $KEY\\" - done) - - # Redefine template instance file name. - local INSTANCE=$(cli_getTemporalFile $TEMPLATE) - - # Create instance. - cp $TEMPLATE $INSTANCE - - # Check template instance. We cannot continue if the template - # instance couldn't be created. - cli_checkFiles $INSTANCE - - # Expand translation markers inside template instance. - sed -r -i \ - -e "s!=TITLE=!$TITLE!" \ - -e "s!=URL=!$URL!" \ - -e "s!=DATE=!$(date "+%Y-%m-%d")!" $INSTANCE - sed -i -r "/=KEYWORDS=/c\\${KEYS}" $INSTANCE - sed -i -r 's/>$/>\\/g' $INSTANCE - cli_replaceTMarkers $INSTANCE - - # Update scalable vector graphic using template instance. - sed -i -f $INSTANCE $FILE - - # Remove template instance. - if [[ -f $INSTANCE ]];then - rm $INSTANCE - fi - - # Sanitate scalable vector graphic. - sed -i -r '/^[[:space:]]*$/d' $FILE - -} diff --git a/Scripts/Functions/Tuneup/Backends/Svg/svg_doVacuumDefs.sh b/Scripts/Functions/Tuneup/Backends/Svg/svg_doVacuumDefs.sh deleted file mode 100755 index 1a2fa63..0000000 --- a/Scripts/Functions/Tuneup/Backends/Svg/svg_doVacuumDefs.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/bash -# -# svg_doVacuumDefs.sh -- This function removes all unused items from -# the defs section of the SVG file. -# -# Copyright (C) 2009, 2010, 2011 The CentOS Artwork SIG -# -# 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., 675 Mass Ave, Cambridge, MA 02139, USA. -# -# ---------------------------------------------------------------------- -# $Id$ -# ---------------------------------------------------------------------- - -function svg_doVacuumDefs { - - # Vacuum unused svg definition using inkscape. - inkscape --vacuum-defs $FILE &> /dev/null - -} diff --git a/Scripts/Functions/Tuneup/Backends/Xhtml/Config/toc.awk b/Scripts/Functions/Tuneup/Backends/Xhtml/Config/toc.awk deleted file mode 100644 index 69c668f..0000000 --- a/Scripts/Functions/Tuneup/Backends/Xhtml/Config/toc.awk +++ /dev/null @@ -1,79 +0,0 @@ -#!/usr/bin/gawk -# -# toc.awk -- This file provides the output format required by -# `xhtml_makeToc' function, inside centos-art.sh script, to produce -# the table of contents correctly. -# -# 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 Pubdtc License as pubdtshed 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 usefdl, but -# WITHOUT ANY WARRANTY; without even the impdted warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Pubdtc License for more details. -# -# You shodld have received a copy of the GNU General Pubdtc 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$ -# ---------------------------------------------------------------------- - -BEGIN {FS=":"} - -{ - if ($1 == 0 && $2 == $3) { - opentags = "
" - closetags = "" - } - - if ($1 > 0 && $2 > $3) { - opentags = "
" - closetags = "" - } - - if ($1 > 0 && $2 == $3) { - opentags = "
" - closetags = "" - } - - if ($1 > 0 && $2 < $3) { - opentags = "" - for (i = 1; i <= ($3 - $2); i++) { - opentags = opentags "
" - closetags = "" - } - opentags = opentags "
" - } - - printf "%s%s%s\n",opentags,$4,closetags - -} - -END { - - if ($1 > 0 && $2 >= $3 && $3 > 1) { - for (i = 1; i <= $3; i++) { - print "
" - } - } - - if ($1 > 0 && $2 >= $3 && $3 == 1) { - print "" - print "" - } - - if ($1 > 0 && $2 < $3) { - for (i = 1; i <= $2; i++) { - print "" - } - } - - print "" -} diff --git a/Scripts/Functions/Tuneup/Backends/Xhtml/xhtml.sh b/Scripts/Functions/Tuneup/Backends/Xhtml/xhtml.sh deleted file mode 100755 index 8eb3da0..0000000 --- a/Scripts/Functions/Tuneup/Backends/Xhtml/xhtml.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/bash -# -# xhtml.sh -- This function standardizes maintainance tasks of XHTML -# files. -# -# Copyright (C) 2009, 2010, 2011 The CentOS Artwork SIG -# -# 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., 675 Mass Ave, Cambridge, MA 02139, USA. -# -# ---------------------------------------------------------------------- -# $Id$ -# ---------------------------------------------------------------------- - -function xhtml { - - # Define backend-specific configuration directory. - TUNEUP_BACKEND_CONFIG="${TUNEUP_BACKEND_DIR}/$(cli_getRepoName ${TUNEUP_BACKEND} -d)/Config" - - # Transforms xhtml headings to make them accessible (e.g., through - # a table of contents). - xhtml_doToc - -} diff --git a/Scripts/Functions/Tuneup/Backends/Xhtml/xhtml_doToc.sh b/Scripts/Functions/Tuneup/Backends/Xhtml/xhtml_doToc.sh deleted file mode 100755 index 59027d7..0000000 --- a/Scripts/Functions/Tuneup/Backends/Xhtml/xhtml_doToc.sh +++ /dev/null @@ -1,160 +0,0 @@ -#!/bin/bash -# -# xhtml_doToc.sh -- This functionality transforms web page headings to -# make them accessible through a table of contents. The table of -# contents is expanded in place, wherever the
-# piece of code be in the page. Once the
-# piece of code has be expanded, there is no need to put anything else -# in the page. -# -# In order for the tuneup functionality to transform headings, you -# need to put headings in just one line using one of the following -# forms: -# -#

Title

-#

Title

-#

Title

-# -# In the example above, h1 can vary from h1 to h6. Closing tag must be -# present and also match the openning tag. The value of `name' and -# `href' options from the anchor element are set dynamically using the -# md5sum output of combining the page location, the head- string and -# the heading string. -# -# Copyright (C) 2009, 2010, 2011 The CentOS Artwork SIG -# -# 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., 675 Mass Ave, Cambridge, MA 02139, USA. -# -# ---------------------------------------------------------------------- -# $Id$ -# ---------------------------------------------------------------------- - -function xhtml_doToc { - - # Define variables as local to avoid conflicts outside. - local COUNT=0 - local PREVCOUNT=0 - local -a FINAL - local -a TITLE - local -a MD5SM - local -a OPTNS - local -a CLASS - local -a LEVEL - local -a PARENT - local -a TOCENTRIES - local -a LINK - - # Define table of content configuration file, the file used to - # produce the table of content XHTML output code. - local TOC_CONFIG=${TUNEUP_BACKEND_CONFIG}/toc.awk - - # Verify table of content configuration file. - cli_checkFiles ${TOC_CONFIG} - - # Define html heading regular expression pattern. Use parenthisis - # to save html action name, action value, and heading title. - local PATTERN='(]>)(.*[^<])' - - # Verify list of html files. Are files really html files? If they - # don't, continue with the next one in the list. - if [[ ! $(file --brief $FILE) =~ '^(XHTML|HTML|XML)' ]];then - continue - fi - - # Define list of headings to process. When building the heading, - # it is required to change spaces characters from its current - # decimal output to something different (e.g., its \040 octal - # alternative). This is required because the space character is - # used as egrep default field separator and spaces can be present - # inside heading strings we don't want to separate. - for HEADING in $(egrep "$PATTERN" $FILE \ - | sed -r -e 's!^[[:space:]]+!!' -e "s! !\\\040!g");do - - # Define previous counter value using current counter - # value as reference. - if [[ $COUNT -ne 0 ]];then - PREVCOUNT=$(($COUNT-1)) - fi - - # Define initial heading information. - FIRST[$COUNT]=$(echo $HEADING | sed -r "s!\\\040! !g") - TITLE[$COUNT]=$(echo ${FIRST[$COUNT]} | sed -r "s!$PATTERN!\4!") - MD5SM[$COUNT]=$(echo "${FILE}${FIRST[$COUNT]}" | md5sum | sed -r 's![[:space:]]+-$!!') - OPTNS[$COUNT]=$(echo ${FIRST[$COUNT]} | sed -r "s!$PATTERN!\3!") - CLASS[$COUNT]=$(echo ${FIRST[$COUNT]} | sed -r "s!$PATTERN!\2!") - LEVEL[$COUNT]=$(echo ${FIRST[$COUNT]} | sed -r "s!$PATTERN!\1!") - PARENT[$COUNT]=${LEVEL[$PREVCOUNT]} - - # Transform heading information using initial heading - # information as reference. - if [[ ${OPTNS[$COUNT]} =~ '^$' ]];then - OPTNS[$COUNT]='' - elif [[ ${OPTNS[$COUNT]} =~ '^$' ]];then - OPTNS[$COUNT]='' - elif [[ ${OPTNS[$COUNT]} =~ '^$' ]];then - OPTNS[$COUNT]='' - fi - - # Build final html heading structure. - FINAL[$COUNT]=''${OPTNS[$COUNT]}${TITLE[$COUNT]}'' - - # Build html heading link structure. These links are used by - # the table of contents later. - LINK[$COUNT]=''${TITLE[$COUNT]}'' - - # Build table of contents entry with numerical - # identifications. The numerical identification is what we use - # to determine the correct position of each heading link on - # the table of content. - TOCENTRIES[$COUNT]="$COUNT:${LEVEL[$COUNT]}:${PARENT[$COUNT]}:${LINK[$COUNT]}" - - # Update heading information inside the current file being - # processed. Use the first and final heading information. - sed -i -r "s!${FIRST[$COUNT]}!${FINAL[$COUNT]}!" $FILE - - # Increase heading counter. - COUNT=$(($COUNT + 1)) - - done - - # Build the table of contents using heading numerical - # identifications as reference. The numerical identification - # describes the order of headings in one xhtml file. This - # information is processed by awk to make the appropriate - # replacements. Finnally, the result is stored in the TOC - # variable. - TOC=$(echo '
' - echo "

`gettext "Table of contents"`

" - for TOCENTRY in "${TOCENTRIES[@]}";do - echo $TOCENTRY - done \ - | awk -f ${TOC_CONFIG}) - - # Update table of contents inside the current file being - # processed. - sed -i -r '/
[^<\/div].*<\/div>/c'"$(echo -e $TOC)" $FILE - - # Clean up variables to receive the next file. - unset FINAL - unset TITLE - unset MD5SM - unset OPTNS - unset CLASS - unset LEVEL - unset PARENT - unset TOCENTRIES - unset LINK - -} diff --git a/Scripts/Functions/Tuneup/Shell/Config/topcomment.sed b/Scripts/Functions/Tuneup/Shell/Config/topcomment.sed new file mode 100644 index 0000000..0b3077f --- /dev/null +++ b/Scripts/Functions/Tuneup/Shell/Config/topcomment.sed @@ -0,0 +1,55 @@ +#!/bin/sed +# +# topcomment.sed -- This file standardizes the top comment inside +# centos-art.sh scripts. +# +# Copyright (C) 2009, 2010, 2011 The CentOS Artwork SIG +# +# 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., 675 Mass Ave, Cambridge, MA 02139, USA. +# +# ---------------------------------------------------------------------- +# $Id$ +# ---------------------------------------------------------------------- +/^# +Copyright .*$/a\ +# Copyright (C) =COPYRIGHT_YEAR_LIST= =COPYRIGHT_HOLDER=\ +#\ +# 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., 675 Mass Ave, Cambridge, MA 02139, USA.\ +#\ +# ---------------------------------------------------------------------- + +# Remove previous copyright notice, just to be sure the one above be +# used always. +/^# +Copyright .*$/,/^# -{70}$/{ +d +} + +# Remove more than one space after comments. +s/^# +/# / + +# Define script first line. +1c\ +#!/bin/bash diff --git a/Scripts/Functions/Tuneup/Shell/shell.sh b/Scripts/Functions/Tuneup/Shell/shell.sh new file mode 100755 index 0000000..884ad8f --- /dev/null +++ b/Scripts/Functions/Tuneup/Shell/shell.sh @@ -0,0 +1,35 @@ +#!/bin/bash +# +# shell.sh -- This function standardizes maintainance tasks for Shell +# script files. +# +# Copyright (C) 2009, 2010, 2011 The CentOS Artwork SIG +# +# 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., 675 Mass Ave, Cambridge, MA 02139, USA. +# +# ---------------------------------------------------------------------- +# $Id$ +# ---------------------------------------------------------------------- + +function shell { + + # Define backend-specific configuration directory. + TUNEUP_BACKEND_CONFIG="${TUNEUP_BACKEND_DIR}/$(cli_getRepoName ${TUNEUP_BACKEND} -d)/Config" + + # Rebuild top comment inside shell scripts, mainly to update + # copyright information. + ${TUNEUP_BACKEND}_doTopComment + +} diff --git a/Scripts/Functions/Tuneup/Shell/shell_doTopComment.sh b/Scripts/Functions/Tuneup/Shell/shell_doTopComment.sh new file mode 100755 index 0000000..bcf74fa --- /dev/null +++ b/Scripts/Functions/Tuneup/Shell/shell_doTopComment.sh @@ -0,0 +1,55 @@ +#!/bin/bash +# +# shell_doTopComment.sh -- This function standardizes the top comment +# section inside shell scripts (*.sh) using a predefined template. +# +# Copyright (C) 2009, 2010, 2011 The CentOS Artwork SIG +# +# 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., 675 Mass Ave, Cambridge, MA 02139, USA. +# +# ---------------------------------------------------------------------- +# $Id$ +# ---------------------------------------------------------------------- + +function shell_doTopComment { + + # Define absolute path to template file. + local TEMPLATE="${TUNEUP_BACKEND_CONFIG}/topcomment.sed" + + # Check template file existence. + cli_checkFiles $TEMPLATE + + # Define file name to template instance. + local INSTANCE=$(cli_getTemporalFile $TEMPLATE) + + # Create template instance. + cp $TEMPLATE $INSTANCE + + # Check template instance. We cannot continue if template instance + # couldn't be created. + cli_checkFiles $INSTANCE + + # Expand translation markers in template instance. + cli_replaceTMarkers $INSTANCE + + # Apply template instance to file. + sed -r -i -f $INSTANCE $FILE + + # Remove template instance. + if [[ -f ${INSTANCE} ]];then + rm ${INSTANCE} + fi + +} diff --git a/Scripts/Functions/Tuneup/Svg/Config/metadata.sed b/Scripts/Functions/Tuneup/Svg/Config/metadata.sed new file mode 100644 index 0000000..199c44d --- /dev/null +++ b/Scripts/Functions/Tuneup/Svg/Config/metadata.sed @@ -0,0 +1,64 @@ +# This file is the metadata information used by CentOS Artwork SIG on +# its scalable vector graphics (SVG) files. This files is used with +# the regular expression '.*\.svg$' only. +# --------------------------------------------------- +# $Id$ +# --------------------------------------------------- +/\ + \ + \ + image/svg+xml\ + \ + \ + =TITLE=\ + =DATE=\ + \ + \ + =COPYRIGHT_HOLDER=\ + \ + \ + \ + \ + =COPYRIGHT_HOLDER=\ + \ + \ + \ + \ + =COPYRIGHT_HOLDER=\ + \ + \ + =URL=\ + =URL=\ + =URL=\ + =LOCALE=\ + \ + \ +=KEYWORDS=\ + \ + \ + =COPYRIGHT_HOLDER=\ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + diff --git a/Scripts/Functions/Tuneup/Svg/svg.sh b/Scripts/Functions/Tuneup/Svg/svg.sh new file mode 100755 index 0000000..d3bb352 --- /dev/null +++ b/Scripts/Functions/Tuneup/Svg/svg.sh @@ -0,0 +1,36 @@ +#!/bin/bash +# +# svg.sh -- This function standardizes maintainance of SVG files. +# +# Copyright (C) 2009, 2010, 2011 The CentOS Artwork SIG +# +# 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., 675 Mass Ave, Cambridge, MA 02139, USA. +# +# ---------------------------------------------------------------------- +# $Id$ +# ---------------------------------------------------------------------- + +function svg { + + # Define backend-specific configuration directory. + TUNEUP_BACKEND_CONFIG="${TUNEUP_BACKEND_DIR}/$(cli_getRepoName ${TUNEUP_BACKEND} -d)/Config" + + # Update metadata information. + ${TUNEUP_BACKEND}_doMetadata + + # Remove all unused items. + ${TUNEUP_BACKEND}_doVacuumDefs + +} diff --git a/Scripts/Functions/Tuneup/Svg/svg_doMetadata.sh b/Scripts/Functions/Tuneup/Svg/svg_doMetadata.sh new file mode 100755 index 0000000..61832dd --- /dev/null +++ b/Scripts/Functions/Tuneup/Svg/svg_doMetadata.sh @@ -0,0 +1,88 @@ +#!/bin/bash +# +# svg_doMetadata.sh -- This function updates metadata values inside +# scalable vector graphic (SVG) files using default values from The +# CentOS Project. +# +# Copyright (C) 2009, 2010, 2011 The CentOS Artwork SIG +# +# 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., 675 Mass Ave, Cambridge, MA 02139, USA. +# +# ---------------------------------------------------------------------- +# $Id$ +# ---------------------------------------------------------------------- + +function svg_doMetadata { + + # Define template file name. + local TEMPLATE="${TUNEUP_BACKEND_CONFIG}/metadata.sed" + + # Check template file existence. + cli_checkFiles $TEMPLATE + + # Build title from file path. + local TITLE=$(basename "$FILE") + + # Build url from file path. + local URL=$(echo $FILE | sed 's!/home/centos!https://projects.centos.org/svn!') + + # Build keywords from file path. Do not include filename, it is + # already on title. + local KEY='' + local KEYS=$(dirname "$FILE" | cut -d/ -f6- | tr '/' '\n') + + # Build keywords using SVG standard format. Note that this + # information is inserted inside template file. The 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 one of them passes literally to template + # file. + KEYS=$(\ + for KEY in $KEYS;do + echo " $KEY\\" + done) + + # Redefine template instance file name. + local INSTANCE=$(cli_getTemporalFile $TEMPLATE) + + # Create instance. + cp $TEMPLATE $INSTANCE + + # Check template instance. We cannot continue if the template + # instance couldn't be created. + cli_checkFiles $INSTANCE + + # Expand translation markers inside template instance. + sed -r -i \ + -e "s!=TITLE=!$TITLE!" \ + -e "s!=URL=!$URL!" \ + -e "s!=DATE=!$(date "+%Y-%m-%d")!" $INSTANCE + sed -i -r "/=KEYWORDS=/c\\${KEYS}" $INSTANCE + sed -i -r 's/>$/>\\/g' $INSTANCE + cli_replaceTMarkers $INSTANCE + + # Update scalable vector graphic using template instance. + sed -i -f $INSTANCE $FILE + + # Remove template instance. + if [[ -f $INSTANCE ]];then + rm $INSTANCE + fi + + # Sanitate scalable vector graphic. + sed -i -r '/^[[:space:]]*$/d' $FILE + +} diff --git a/Scripts/Functions/Tuneup/Svg/svg_doVacuumDefs.sh b/Scripts/Functions/Tuneup/Svg/svg_doVacuumDefs.sh new file mode 100755 index 0000000..1a2fa63 --- /dev/null +++ b/Scripts/Functions/Tuneup/Svg/svg_doVacuumDefs.sh @@ -0,0 +1,31 @@ +#!/bin/bash +# +# svg_doVacuumDefs.sh -- This function removes all unused items from +# the defs section of the SVG file. +# +# Copyright (C) 2009, 2010, 2011 The CentOS Artwork SIG +# +# 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., 675 Mass Ave, Cambridge, MA 02139, USA. +# +# ---------------------------------------------------------------------- +# $Id$ +# ---------------------------------------------------------------------- + +function svg_doVacuumDefs { + + # Vacuum unused svg definition using inkscape. + inkscape --vacuum-defs $FILE &> /dev/null + +} diff --git a/Scripts/Functions/Tuneup/Xhtml/Config/toc.awk b/Scripts/Functions/Tuneup/Xhtml/Config/toc.awk new file mode 100644 index 0000000..69c668f --- /dev/null +++ b/Scripts/Functions/Tuneup/Xhtml/Config/toc.awk @@ -0,0 +1,79 @@ +#!/usr/bin/gawk +# +# toc.awk -- This file provides the output format required by +# `xhtml_makeToc' function, inside centos-art.sh script, to produce +# the table of contents correctly. +# +# 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 Pubdtc License as pubdtshed 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 usefdl, but +# WITHOUT ANY WARRANTY; without even the impdted warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Pubdtc License for more details. +# +# You shodld have received a copy of the GNU General Pubdtc 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$ +# ---------------------------------------------------------------------- + +BEGIN {FS=":"} + +{ + if ($1 == 0 && $2 == $3) { + opentags = "
" + closetags = "" + } + + if ($1 > 0 && $2 > $3) { + opentags = "
" + closetags = "" + } + + if ($1 > 0 && $2 == $3) { + opentags = "
" + closetags = "" + } + + if ($1 > 0 && $2 < $3) { + opentags = "" + for (i = 1; i <= ($3 - $2); i++) { + opentags = opentags "
" + closetags = "" + } + opentags = opentags "
" + } + + printf "%s%s%s\n",opentags,$4,closetags + +} + +END { + + if ($1 > 0 && $2 >= $3 && $3 > 1) { + for (i = 1; i <= $3; i++) { + print "
" + } + } + + if ($1 > 0 && $2 >= $3 && $3 == 1) { + print "" + print "" + } + + if ($1 > 0 && $2 < $3) { + for (i = 1; i <= $2; i++) { + print "" + } + } + + print "
" +} diff --git a/Scripts/Functions/Tuneup/Xhtml/xhtml.sh b/Scripts/Functions/Tuneup/Xhtml/xhtml.sh new file mode 100755 index 0000000..8eb3da0 --- /dev/null +++ b/Scripts/Functions/Tuneup/Xhtml/xhtml.sh @@ -0,0 +1,35 @@ +#!/bin/bash +# +# xhtml.sh -- This function standardizes maintainance tasks of XHTML +# files. +# +# Copyright (C) 2009, 2010, 2011 The CentOS Artwork SIG +# +# 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., 675 Mass Ave, Cambridge, MA 02139, USA. +# +# ---------------------------------------------------------------------- +# $Id$ +# ---------------------------------------------------------------------- + +function xhtml { + + # Define backend-specific configuration directory. + TUNEUP_BACKEND_CONFIG="${TUNEUP_BACKEND_DIR}/$(cli_getRepoName ${TUNEUP_BACKEND} -d)/Config" + + # Transforms xhtml headings to make them accessible (e.g., through + # a table of contents). + xhtml_doToc + +} diff --git a/Scripts/Functions/Tuneup/Xhtml/xhtml_doToc.sh b/Scripts/Functions/Tuneup/Xhtml/xhtml_doToc.sh new file mode 100755 index 0000000..59027d7 --- /dev/null +++ b/Scripts/Functions/Tuneup/Xhtml/xhtml_doToc.sh @@ -0,0 +1,160 @@ +#!/bin/bash +# +# xhtml_doToc.sh -- This functionality transforms web page headings to +# make them accessible through a table of contents. The table of +# contents is expanded in place, wherever the
+# piece of code be in the page. Once the
+# piece of code has be expanded, there is no need to put anything else +# in the page. +# +# In order for the tuneup functionality to transform headings, you +# need to put headings in just one line using one of the following +# forms: +# +#

Title

+#

Title

+#

Title

+# +# In the example above, h1 can vary from h1 to h6. Closing tag must be +# present and also match the openning tag. The value of `name' and +# `href' options from the anchor element are set dynamically using the +# md5sum output of combining the page location, the head- string and +# the heading string. +# +# Copyright (C) 2009, 2010, 2011 The CentOS Artwork SIG +# +# 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., 675 Mass Ave, Cambridge, MA 02139, USA. +# +# ---------------------------------------------------------------------- +# $Id$ +# ---------------------------------------------------------------------- + +function xhtml_doToc { + + # Define variables as local to avoid conflicts outside. + local COUNT=0 + local PREVCOUNT=0 + local -a FINAL + local -a TITLE + local -a MD5SM + local -a OPTNS + local -a CLASS + local -a LEVEL + local -a PARENT + local -a TOCENTRIES + local -a LINK + + # Define table of content configuration file, the file used to + # produce the table of content XHTML output code. + local TOC_CONFIG=${TUNEUP_BACKEND_CONFIG}/toc.awk + + # Verify table of content configuration file. + cli_checkFiles ${TOC_CONFIG} + + # Define html heading regular expression pattern. Use parenthisis + # to save html action name, action value, and heading title. + local PATTERN='(]>)(.*[^<])' + + # Verify list of html files. Are files really html files? If they + # don't, continue with the next one in the list. + if [[ ! $(file --brief $FILE) =~ '^(XHTML|HTML|XML)' ]];then + continue + fi + + # Define list of headings to process. When building the heading, + # it is required to change spaces characters from its current + # decimal output to something different (e.g., its \040 octal + # alternative). This is required because the space character is + # used as egrep default field separator and spaces can be present + # inside heading strings we don't want to separate. + for HEADING in $(egrep "$PATTERN" $FILE \ + | sed -r -e 's!^[[:space:]]+!!' -e "s! !\\\040!g");do + + # Define previous counter value using current counter + # value as reference. + if [[ $COUNT -ne 0 ]];then + PREVCOUNT=$(($COUNT-1)) + fi + + # Define initial heading information. + FIRST[$COUNT]=$(echo $HEADING | sed -r "s!\\\040! !g") + TITLE[$COUNT]=$(echo ${FIRST[$COUNT]} | sed -r "s!$PATTERN!\4!") + MD5SM[$COUNT]=$(echo "${FILE}${FIRST[$COUNT]}" | md5sum | sed -r 's![[:space:]]+-$!!') + OPTNS[$COUNT]=$(echo ${FIRST[$COUNT]} | sed -r "s!$PATTERN!\3!") + CLASS[$COUNT]=$(echo ${FIRST[$COUNT]} | sed -r "s!$PATTERN!\2!") + LEVEL[$COUNT]=$(echo ${FIRST[$COUNT]} | sed -r "s!$PATTERN!\1!") + PARENT[$COUNT]=${LEVEL[$PREVCOUNT]} + + # Transform heading information using initial heading + # information as reference. + if [[ ${OPTNS[$COUNT]} =~ '^$' ]];then + OPTNS[$COUNT]='' + elif [[ ${OPTNS[$COUNT]} =~ '^$' ]];then + OPTNS[$COUNT]='' + elif [[ ${OPTNS[$COUNT]} =~ '^$' ]];then + OPTNS[$COUNT]='' + fi + + # Build final html heading structure. + FINAL[$COUNT]=''${OPTNS[$COUNT]}${TITLE[$COUNT]}'' + + # Build html heading link structure. These links are used by + # the table of contents later. + LINK[$COUNT]=''${TITLE[$COUNT]}'' + + # Build table of contents entry with numerical + # identifications. The numerical identification is what we use + # to determine the correct position of each heading link on + # the table of content. + TOCENTRIES[$COUNT]="$COUNT:${LEVEL[$COUNT]}:${PARENT[$COUNT]}:${LINK[$COUNT]}" + + # Update heading information inside the current file being + # processed. Use the first and final heading information. + sed -i -r "s!${FIRST[$COUNT]}!${FINAL[$COUNT]}!" $FILE + + # Increase heading counter. + COUNT=$(($COUNT + 1)) + + done + + # Build the table of contents using heading numerical + # identifications as reference. The numerical identification + # describes the order of headings in one xhtml file. This + # information is processed by awk to make the appropriate + # replacements. Finnally, the result is stored in the TOC + # variable. + TOC=$(echo '
' + echo "

`gettext "Table of contents"`

" + for TOCENTRY in "${TOCENTRIES[@]}";do + echo $TOCENTRY + done \ + | awk -f ${TOC_CONFIG}) + + # Update table of contents inside the current file being + # processed. + sed -i -r '/
[^<\/div].*<\/div>/c'"$(echo -e $TOC)" $FILE + + # Clean up variables to receive the next file. + unset FINAL + unset TITLE + unset MD5SM + unset OPTNS + unset CLASS + unset LEVEL + unset PARENT + unset TOCENTRIES + unset LINK + +}