From ac547358fb9d48a88accfcf810ddd1f8bdd5520d Mon Sep 17 00:00:00 2001 From: Alain Reguera Delgado Date: Sep 11 2013 19:46:56 +0000 Subject: Update tuneup module inside centos-art.sh script. - Previously, tuneup module did not work as expected in the current modular design because function and variable names inside it had the wrong names. This commit uses correct function and variable names inside tuneup module. - Previously, when processing html page, there was not feature for transforming (probably malformed) HTML files to XHTML. This commit adds a cleanup feature to transform HTML into a valid XHTML page using sed and xmllint. - Previously, when processing sh files, there was not a feature to transform variable names from $varname to ${VARNAME}. The ${VARNAME} naming convention is being adopted inside centos-art.sh script as default naming convention for variables. This commits adds the sh_setVariableNames function to transform variable names from $varname form to ${VARNAME} form. - Previously, tuneup module tried to synchronize changes from local working copy to central repository using cli_synchronizeRepoChanges functions. This commit removes repository synchronization from tuneup module. - Previously, when reading command-line, tuneup module supported the help,quiet,filter:,answer-yes,synchronize as command-line options. From these options only help, version and filter were useful. This commit removes quiet, answer-yes and synchronize options from tuneup module's command-line and adds version to it. - Previously, when reading the module's help, tuneup module used the cli_runFnEnvironment function to read documentation in texinfo format. Texinfo format is no longer supported for documentation inside centos-art.sh script. It was replaced by asciidoc which is used to produce documentation in different formats, including manpages. This commit updates the way tuneup module reads its documentation by using tcar_printHelp function instead. - Previously, in tuneup_getOptions function, we were using the cli_parseArgumentsReDef function to redefine the ARGUMENTS environment variable. This commits renames the ARGUMENTS variable to TCAR_ARGUMENTS and performs its value redefinitions by modifying the TCAR_ARGUMETS variable directly, just after stripping out the options values from it. - Previously, the topcomment.sed file, used to update the top comment section of Bash scripts did not add the "Written by:" line. This commit adds the "Written by:" line and my full name along with contact information in the next line. - Previously, when reading tuneup modules' documentation there wasn't any to read about. This commit adds the tuneup.asciidoc with an initial documentation structure to fill up and the render.conf file, both inside tuneup module's Manuals directory. Manpages and xhtmlpages will be generated after running the render functionality over the tuneup module's Manuals directory. - Previously, when building the list of files to process, tuneup module looked up for svg, xhtml and sh file extensions only. With this commit, tuneup module looks for .svgz, .svg, .shtml, .xhtml, .html, and .sh file extensions. - Previously, inside the sh files, the top comment used the minus (-) character to draw top comment boundaries. This commit changes sh files to use the number sign (#) as top comment boundaries, instead. --- diff --git a/Automation/Modules/Tuneup/Manuals/render.conf b/Automation/Modules/Tuneup/Manuals/render.conf new file mode 100644 index 0000000..a064bdf --- /dev/null +++ b/Automation/Modules/Tuneup/Manuals/render.conf @@ -0,0 +1,15 @@ +# +# This files contains the configuration options the render module +# needs to generate both manpage and xhtml files from asciidoc files. +# +[tuneup] +render-type = "asciidoc" +render-flow = "manpage" +render-from = "tuneup.asciidoc" +tuneup-from = "${TCAR_SCRIPT_LANG_LC}/tuneup.asciidoc.po" +formats = "xhtml manpage" +mansect = "1" + +# +# Add configuration to module's sh files, as well. +# diff --git a/Automation/Modules/Tuneup/Manuals/tuneup.asciidoc b/Automation/Modules/Tuneup/Manuals/tuneup.asciidoc new file mode 100644 index 0000000..7914012 --- /dev/null +++ b/Automation/Modules/Tuneup/Manuals/tuneup.asciidoc @@ -0,0 +1,55 @@ +tuneup(1) +========= + +Name +---- + +tuneup - Standardizes file maintainance tasks inside the repository. + +Synopsis +-------- + +*centos-art.sh tuneup --help*:: + Print module's documentation for users. + +*centos-art.sh tuneup --help="FILE.sh"*:: + Print module's documentation for developers. Here, FILE.sh is the + name of the file you want to read documentation from. + +*centos-art.sh tuneup DIRECTORY [--filter="REGEX"]* + +Description +----------- + +... + +Author +------ + +Written by mailto:al@centos.org.cu[Alain Reguera Delgado] + +Copyright +--------- + +Copyright (C) 2009-2013 The CentOS Project + +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. + +See Also +-------- + +centos-art.sh(1) + +// vim: set syntax=asciidoc: diff --git a/Automation/Modules/Tuneup/Modules/Sh/Configs/topcomment.sed b/Automation/Modules/Tuneup/Modules/Sh/Configs/topcomment.sed new file mode 100755 index 0000000..d52a7f8 --- /dev/null +++ b/Automation/Modules/Tuneup/Modules/Sh/Configs/topcomment.sed @@ -0,0 +1,57 @@ +#!/bin/sed +###################################################################### +# +# topcomment.sed -- This file standardizes the top comment inside +# centos-art.sh scripts. +# +# Written by: +# * Alain Reguera Delgado +# +# Copyright (C) 2009-2013 The CentOS Project +# +# 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. +# +###################################################################### +/^#[[:space:]]*Written by:[[:space:]]*$/a\ +# Written by:\ +# * Alain Reguera Delgado , =COPYRIGHT_YEAR_FIRST=-=COPYRIGHT_YEAR_LAST=\ +#\ +# Copyright (C) =COPYRIGHT_YEAR_FIRST=-=COPYRIGHT_YEAR_LAST= =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. +/^#[[:space:]]*Written by:[[:space:]]*$/,/^#{70}$/{ +d +} + +# Define script first line. +1c\ +#!/bin/bash diff --git a/Automation/Modules/Tuneup/Modules/Sh/sh.conf.sh b/Automation/Modules/Tuneup/Modules/Sh/sh.conf.sh new file mode 100644 index 0000000..00da998 --- /dev/null +++ b/Automation/Modules/Tuneup/Modules/Sh/sh.conf.sh @@ -0,0 +1,27 @@ +#!/bin/bash +# +# sh.conf.sh -- This file defines environment variables for +# sh module's execution environment. +# +# Written by: +# * Alain Reguera Delgado , 2009-2013 +# +# Copyright (C) 2009-2013 The CentOS Project +# +# 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. +# +###################################################################### + +declare -x TCAR_SCRIPT_MODULES_BASEDIR=${MODULE_DIR_MODULES} diff --git a/Automation/Modules/Tuneup/Modules/Sh/sh.sh b/Automation/Modules/Tuneup/Modules/Sh/sh.sh new file mode 100755 index 0000000..261d51c --- /dev/null +++ b/Automation/Modules/Tuneup/Modules/Sh/sh.sh @@ -0,0 +1,32 @@ +#!/bin/bash +# +# sh.sh -- This module standardizes file Bash scripts maintenance +# tasks inside the repository. +# +# Written by: +# * Alain Reguera Delgado , 2009-2013 +# +# Copyright (C) 2009-2013 The CentOS Project +# +# 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. +# +###################################################################### + +function sh { + + sh_setTopComment + sh_setVariableNames + +} diff --git a/Automation/Modules/Tuneup/Modules/Sh/sh_setTopComment.sh b/Automation/Modules/Tuneup/Modules/Sh/sh_setTopComment.sh new file mode 100755 index 0000000..ef12c09 --- /dev/null +++ b/Automation/Modules/Tuneup/Modules/Sh/sh_setTopComment.sh @@ -0,0 +1,44 @@ +#!/bin/bash +###################################################################### +# +# sh_setTopComment.sh -- This function standardizes presentation for +# top comment section of shell scripts (*.sh) using a predefined +# template. +# +# Copyright (C) 2009-2013 The CentOS Project +# +# 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. +# +###################################################################### + +function sh_setTopComment { + + local COMMENT_TEMPLATE="${MODULE_DIR_CONFIGS}/topcomment.sed" + + tcar_checkFiles -ef ${COMMENT_TEMPLATE} + + local COMMENT_INSTANCE=$(tcar_getTemporalFile ${COMMENT_TEMPLATE}) + + cp ${COMMENT_TEMPLATE} ${COMMENT_INSTANCE} + + tcar_setTranslationMarkers ${COMMENT_INSTANCE} + + sed -r -i -f ${COMMENT_INSTANCE} ${FILE} + + if [[ -f ${COMMENT_INSTANCE} ]];then + rm ${COMMENT_INSTANCE} + fi + +} diff --git a/Automation/Modules/Tuneup/Modules/Sh/sh_setVariableNames.sh b/Automation/Modules/Tuneup/Modules/Sh/sh_setVariableNames.sh new file mode 100755 index 0000000..588f325 --- /dev/null +++ b/Automation/Modules/Tuneup/Modules/Sh/sh_setVariableNames.sh @@ -0,0 +1,37 @@ +#!/bin/bash +###################################################################### +# +# sh_setVariableNames.sh -- This function standardizes presentation +# of variable's names inside shell scripts. +# +# Copyright (C) 2009-2013 The CentOS Project +# +# 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. +# +###################################################################### + +function sh_setVariableNames { + + local -a COMMANDS + + # Write non-array variable names all in upper case and between + # brackets. For example: ${VARIABLE} -> ${VARIABLE} + COMMANDS[++((${#COMMANDS[*]}))]='s/\$(\w+\b|@)/${\U\1}/g' + + for COMMAND in ${COMMANDS[*]};do + sed -r -i ${COMMAND} ${FILE} + done + +} diff --git a/Automation/Modules/Tuneup/Modules/Svg/Configs/metadata.sed b/Automation/Modules/Tuneup/Modules/Svg/Configs/metadata.sed new file mode 100755 index 0000000..199c44d --- /dev/null +++ b/Automation/Modules/Tuneup/Modules/Svg/Configs/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/Automation/Modules/Tuneup/Modules/Svg/svg.conf.sh b/Automation/Modules/Tuneup/Modules/Svg/svg.conf.sh new file mode 100755 index 0000000..9a5ced0 --- /dev/null +++ b/Automation/Modules/Tuneup/Modules/Svg/svg.conf.sh @@ -0,0 +1,27 @@ +#!/bin/bash +# +# svg.conf.sh -- This file defines environment variables for svg +# module's execution environment. +# +# Written by: +# * Alain Reguera Delgado , 2009-2013 +# +# Copyright (C) 2009-2013 The CentOS Project +# +# 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. +# +###################################################################### + +declare -x TCAR_SCRIPT_MODULES_BASEDIR=${MODULE_DIR_MODULES} diff --git a/Automation/Modules/Tuneup/Modules/Svg/svg.sh b/Automation/Modules/Tuneup/Modules/Svg/svg.sh new file mode 100755 index 0000000..e32a7c8 --- /dev/null +++ b/Automation/Modules/Tuneup/Modules/Svg/svg.sh @@ -0,0 +1,34 @@ +#!/bin/bash +###################################################################### +# +# svg.sh -- This module standardizes source code maintainance of SVG +# files inside the repository. +# +# Written by: +# * Alain Reguera Delgado , 2009-2013 +# +# Copyright (C) 2009-2013 The CentOS Project +# +# 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. +# +###################################################################### + +function svg { + + svg_doMetadata + + svg_doVacuumDefs + +} diff --git a/Automation/Modules/Tuneup/Modules/Svg/svg_setMetadata.sh b/Automation/Modules/Tuneup/Modules/Svg/svg_setMetadata.sh new file mode 100755 index 0000000..7af256c --- /dev/null +++ b/Automation/Modules/Tuneup/Modules/Svg/svg_setMetadata.sh @@ -0,0 +1,92 @@ +#!/bin/bash +###################################################################### +# +# svg_setMetadata.sh -- This function updates metadata values inside +# scalable vector graphic (SVG) files using default values from The +# CentOS Project. +# +# Written by: +# * Alain Reguera Delgado , 2009-2013 +# +# Copyright (C) 2009-2013 The CentOS Project +# +# 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. +# +###################################################################### + +function svg_setMetadata { + + # Define template file name. + local TEMPLATE="${MODULE_DIR_CONFIGS}/metadata.sed" + + # Check template file existence. + tcar_checkFiles -ef ${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=$(tcar_getTemporalFile ${TEMPLATE}) + + # Create instance. + cp ${TEMPLATE} ${INSTANCE} + + # Check template instance. We cannot continue if the template + # instance couldn't be created. + tcar_checkFiles -e ${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} + + tcar_setTranslationMarkers ${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/Automation/Modules/Tuneup/Modules/Svg/svg_setVacuumDefs.sh b/Automation/Modules/Tuneup/Modules/Svg/svg_setVacuumDefs.sh new file mode 100755 index 0000000..f8c24ac --- /dev/null +++ b/Automation/Modules/Tuneup/Modules/Svg/svg_setVacuumDefs.sh @@ -0,0 +1,32 @@ +#!/bin/bash +###################################################################### +# +# svg_setVacuumDefs.sh -- This function removes all unused items from +# the defs section of the SVG file. +# +# Written by: +# * Alain Reguera Delgado , 2009-2013 +# +# Copyright (C) 2009-2013 The CentOS Project +# +# 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. +# +###################################################################### + +function svg_setVacuumDefs { + + inkscape --vacuum-defs ${FILE} 2&> /dev/null + +} diff --git a/Automation/Modules/Tuneup/Modules/Xhtml/Configs/cleanup-after.sed b/Automation/Modules/Tuneup/Modules/Xhtml/Configs/cleanup-after.sed new file mode 100644 index 0000000..a7f82b7 --- /dev/null +++ b/Automation/Modules/Tuneup/Modules/Xhtml/Configs/cleanup-after.sed @@ -0,0 +1,37 @@ +#!/bin/sed +###################################################################### +# +# cleanup-after.sed -- This file is read by xhtml_setCleanUp +# function to convert special tags into HTML comments after cleanup +# process. +# +# Written by: +# * Alain Reguera Delgado , 2009-2013 +# +# Copyright (C) 2013 The CentOS Project +# +# 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. +# +###################################################################### + +# Convert Mailman-specific tags back into their original form (see: +# cleanup-before.sed). +s//<\1>/g +s/%3C!--%20((mm|MM)-[[:alnum:]_-]+)%20--%3E/<\1>/g +s/<!-- ((mm|MM)[[:alnum:]_-]+) -->/<\1>/g + +s//\1/g +s/%3C!--%20(%\([[:alnum:]_-]+\)[[:alpha:]])%20--%3E/\1/g +s/<!-- (%\([[:alnum:]_-]+\)[[:alpha:]]) -->/\1/g diff --git a/Automation/Modules/Tuneup/Modules/Xhtml/Configs/cleanup-before.sed b/Automation/Modules/Tuneup/Modules/Xhtml/Configs/cleanup-before.sed new file mode 100644 index 0000000..3e8e27d --- /dev/null +++ b/Automation/Modules/Tuneup/Modules/Xhtml/Configs/cleanup-before.sed @@ -0,0 +1,34 @@ +#!/bin/sed +###################################################################### +# +# cleanup-before.sed -- This file is read by xhtml_setCleanUp +# function to convert special tags into HTML comments before cleanup +# process. Once the file has been cleaned up, the special tags are +# converted back to their original form (see: cleanup-after.sed). +# +# Written by: +# * Alain Reguera Delgado , 2009-2013 +# +# Copyright (C) 2013 The CentOS Project +# +# 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. +# +###################################################################### + +# Convert Mailman-specific tags into comments. These tags are found in +# Mailman's templates and should not be touched in any way because +# they are used to display dynamic content at Mailman's run time. +s/<((mm|MM)-[[:alnum:]_-]+)>//g +s/(%\([[:alnum:]_-]+\)[[:alpha:]])//g diff --git a/Automation/Modules/Tuneup/Modules/Xhtml/Configs/toc.awk b/Automation/Modules/Tuneup/Modules/Xhtml/Configs/toc.awk new file mode 100755 index 0000000..ad47670 --- /dev/null +++ b/Automation/Modules/Tuneup/Modules/Xhtml/Configs/toc.awk @@ -0,0 +1,80 @@ +#!/usr/bin/gawk +# +# toc.awk -- This file provides the output format required by +# `xhtml_setToc' function, inside centos-art.sh script, to produce +# the table of contents correctly. +# +# Written by: +# * Alain Reguera Delgado , 2009-2013 +# +# Copyright (C) 2009-2013 The CentOS Project +# +# 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. +# +###################################################################### + +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/Automation/Modules/Tuneup/Modules/Xhtml/xhtml.conf.sh b/Automation/Modules/Tuneup/Modules/Xhtml/xhtml.conf.sh new file mode 100755 index 0000000..98ab3dc --- /dev/null +++ b/Automation/Modules/Tuneup/Modules/Xhtml/xhtml.conf.sh @@ -0,0 +1,27 @@ +#!/bin/bash +# +# xhtml.conf.sh -- This file defines environment variables for xhtml +# module's execution environment. +# +# Written by: +# * Alain Reguera Delgado , 2009-2013 +# +# Copyright (C) 2009-2013 The CentOS Project +# +# 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. +# +###################################################################### + +declare -x TCAR_SCRIPT_MODULES_BASEDIR=${MODULE_DIR_MODULES} diff --git a/Automation/Modules/Tuneup/Modules/Xhtml/xhtml.sh b/Automation/Modules/Tuneup/Modules/Xhtml/xhtml.sh new file mode 100755 index 0000000..9f12ff9 --- /dev/null +++ b/Automation/Modules/Tuneup/Modules/Xhtml/xhtml.sh @@ -0,0 +1,32 @@ +#!/bin/bash +# +# xhtml.sh -- This function standardizes maintainance tasks for +# HTML-like files. +# +# Written by: +# * Alain Reguera Delgado , 2009-2013 +# +# Copyright (C) 2009-2013 The CentOS Project +# +# 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. +# +###################################################################### + +function xhtml { + + xhtml_setToc + xhtml_setCleanUp + +} diff --git a/Automation/Modules/Tuneup/Modules/Xhtml/xhtml_setCleanUp.sh b/Automation/Modules/Tuneup/Modules/Xhtml/xhtml_setCleanUp.sh new file mode 100755 index 0000000..4ff454a --- /dev/null +++ b/Automation/Modules/Tuneup/Modules/Xhtml/xhtml_setCleanUp.sh @@ -0,0 +1,38 @@ +#!/bin/bash +###################################################################### +# +# xhtml_setCleanUp.sh -- This function creates valid XHTML files +# from (probably malformed) HTML files. +# +# Written by: +# * Alain Reguera Delgado , 2009-2013 +# +# Copyright (C) 2009-2013 The CentOS Project +# +# 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. +# +###################################################################### + +function xhtml_setCleanUp { + + sed -i -r -f "${MODULE_DIR_CONFIGS}/cleanup-before.sed" "${FILE}" + + /usr/bin/xmllint --html --xmlout --format --noblanks \ + --nonet --nowarning \ + --output ${FILE} ${FILE} 2&> /dev/null + + sed -i -r -f "${MODULE_DIR_CONFIGS}/cleanup-after.sed" "${FILE}" + +} diff --git a/Automation/Modules/Tuneup/Modules/Xhtml/xhtml_setToc.sh b/Automation/Modules/Tuneup/Modules/Xhtml/xhtml_setToc.sh new file mode 100755 index 0000000..5b676d1 --- /dev/null +++ b/Automation/Modules/Tuneup/Modules/Xhtml/xhtml_setToc.sh @@ -0,0 +1,162 @@ +#!/bin/bash +###################################################################### +# +# xhtml_setToc.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. +# +# Written by: +# * Alain Reguera Delgado , 2009-2013 +# +# Copyright (C) 2009-2013 The CentOS Project +# +# 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. +# +###################################################################### + +function xhtml_setToc { + + # 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_CONFIG_DIR}/toc.awk + + # Verify table of content configuration file. + cli_checkFiles -e ${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/Automation/Modules/Tuneup/Sh/Config/topcomment.sed b/Automation/Modules/Tuneup/Sh/Config/topcomment.sed deleted file mode 100755 index 8b56461..0000000 --- a/Automation/Modules/Tuneup/Sh/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-2013 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) 2009-=COPYRIGHT_YEAR_LAST= =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/Automation/Modules/Tuneup/Sh/sh.sh b/Automation/Modules/Tuneup/Sh/sh.sh deleted file mode 100755 index cd59368..0000000 --- a/Automation/Modules/Tuneup/Sh/sh.sh +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/bash -# -# sh.sh -- This function standardizes maintainance tasks for Shell -# script files. -# -# Copyright (C) 2009-2013 The CentOS Project -# -# 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 sh { - - # Rebuild top comment inside shell scripts, mainly to update - # copyright information. - sh_doTopComment - -} diff --git a/Automation/Modules/Tuneup/Sh/sh_doTopComment.sh b/Automation/Modules/Tuneup/Sh/sh_doTopComment.sh deleted file mode 100755 index 808dafa..0000000 --- a/Automation/Modules/Tuneup/Sh/sh_doTopComment.sh +++ /dev/null @@ -1,55 +0,0 @@ -#!/bin/bash -# -# sh_doTopComment.sh -- This function standardizes the top comment -# section inside shell scripts (*.sh) using a predefined template. -# -# Copyright (C) 2009-2013 The CentOS Project -# -# 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 sh_doTopComment { - - # Define absolute path to template file. - local TEMPLATE="${TUNEUP_CONFIG_DIR}/topcomment.sed" - - # Check template file existence. - cli_checkFiles -e $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 -e $INSTANCE - - # Expand translation markers in template instance. - cli_expandTMarkers $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/Automation/Modules/Tuneup/Svg/Config/metadata.sed b/Automation/Modules/Tuneup/Svg/Config/metadata.sed deleted file mode 100755 index 199c44d..0000000 --- a/Automation/Modules/Tuneup/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/Automation/Modules/Tuneup/Svg/svg.sh b/Automation/Modules/Tuneup/Svg/svg.sh deleted file mode 100755 index ac7a22b..0000000 --- a/Automation/Modules/Tuneup/Svg/svg.sh +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/bash -# -# svg.sh -- This function standardizes maintainance of SVG files. -# -# Copyright (C) 2009-2013 The CentOS Project -# -# 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 { - - # Update metadata information. - svg_doMetadata - - # Remove all unused items. - svg_doVacuumDefs - -} diff --git a/Automation/Modules/Tuneup/Svg/svg_doMetadata.sh b/Automation/Modules/Tuneup/Svg/svg_doMetadata.sh deleted file mode 100755 index 32865e0..0000000 --- a/Automation/Modules/Tuneup/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-2013 The CentOS Project -# -# 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_CONFIG_DIR}/metadata.sed" - - # Check template file existence. - cli_checkFiles -e $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 -e $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_expandTMarkers $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/Automation/Modules/Tuneup/Svg/svg_doVacuumDefs.sh b/Automation/Modules/Tuneup/Svg/svg_doVacuumDefs.sh deleted file mode 100755 index 58d60fc..0000000 --- a/Automation/Modules/Tuneup/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-2013 The CentOS Project -# -# 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/Automation/Modules/Tuneup/Xhtml/Config/toc.awk b/Automation/Modules/Tuneup/Xhtml/Config/toc.awk deleted file mode 100755 index d4e9d75..0000000 --- a/Automation/Modules/Tuneup/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-2012 The CentOS Project -# -# 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/Automation/Modules/Tuneup/Xhtml/xhtml.sh b/Automation/Modules/Tuneup/Xhtml/xhtml.sh deleted file mode 100755 index f758f8f..0000000 --- a/Automation/Modules/Tuneup/Xhtml/xhtml.sh +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/bash -# -# xhtml.sh -- This function standardizes maintainance tasks of XHTML -# files. -# -# Copyright (C) 2009-2013 The CentOS Project -# -# 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 { - - # Transforms xhtml headings to make them accessible (e.g., through - # a table of contents). - xhtml_doToc - -} diff --git a/Automation/Modules/Tuneup/Xhtml/xhtml_doToc.sh b/Automation/Modules/Tuneup/Xhtml/xhtml_doToc.sh deleted file mode 100755 index e75698e..0000000 --- a/Automation/Modules/Tuneup/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-2013 The CentOS Project -# -# 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_CONFIG_DIR}/toc.awk - - # Verify table of content configuration file. - cli_checkFiles -e ${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/Automation/Modules/Tuneup/tuneup.conf.sh b/Automation/Modules/Tuneup/tuneup.conf.sh new file mode 100644 index 0000000..72005f2 --- /dev/null +++ b/Automation/Modules/Tuneup/tuneup.conf.sh @@ -0,0 +1,30 @@ +#!/bin/bash +# +# tuneup.conf.sh -- This file defines environment variables for +# tuneup module's execution environment. +# +# Written by: +# * Alain Reguera Delgado , 2009-2013 +# +# Copyright (C) 2009-2013 The CentOS Project +# +# 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. +# +###################################################################### + +declare -x TCAR_SCRIPT_MODULES_BASEDIR=${MODULE_DIR_MODULES} + +# Define file extensions tuneup module will look for processing. +declare -xr FILE_EXTENSION_REGEX='\.(svgz|svg|shtml|xhtml|html|sh)$' diff --git a/Automation/Modules/Tuneup/tuneup.sh b/Automation/Modules/Tuneup/tuneup.sh index 07f96fc..9da1527 100755 --- a/Automation/Modules/Tuneup/tuneup.sh +++ b/Automation/Modules/Tuneup/tuneup.sh @@ -1,8 +1,11 @@ #!/bin/bash +###################################################################### # -# tuneup.sh -- This function standardizes maintainance tasks for files -# inside the repository. Maintainance tasks are applied to files using -# file extension as reference. +# tuneup.sh -- This module standardizes file maintainance inside the +# repository. +# +# Written by: +# * Alain Reguera Delgado , 2009-2013 # # Copyright (C) 2009-2013 The CentOS Project # @@ -20,72 +23,50 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # -# ---------------------------------------------------------------------- -# $Id$ -# ---------------------------------------------------------------------- +###################################################################### function tuneup { - local ACTIONNAM='' - local ACTIONVAL='' - - # Initialize name of rendition format as an empty value. The name - # of rendition format is determined automatically based on - # template file extension, later, when files are processed. - local TUNEUP_FORMAT='' - - # Initialize absolute path to format's base directory, the place - # where format-specific directories are stored in. - local TUNEUP_BASEDIR="${CLI_FUNCDIR}/${CLI_FUNCDIRNAM}" - - # Initialize list of supported file extensions. This is, the file - # extensions we want to perform maintenance tasks for. - local TUNEUP_EXTENSIONS='svg xhtml sh' + tuneup_getOptions "${@}" - # Interpret arguments and options passed through command-line. - tuneup_getOptions + eval set -- "${TCAR_ARGUMENTS}" - # Redefine positional parameters using ARGUMENTS. At this point, - # option arguments have been removed from ARGUMENTS variable and - # only non-option arguments remain in it. - eval set -- "$ARGUMENTS" + for ARGUMENT in ${@};do - # Define action name. No matter what option be passed to - # centos-art, there is only one action to perform (i.e., build the - # list of files and interpretation of file extensions for further - # processing). - ACTIONNAM="tuneup_doBaseActions" - - # Define action value. We use non-option arguments to define the - # action value (ACTIONVAL) variable. - for ACTIONVAL in "$@";do - # Sanitate non-option arguments to be sure they match the # directory conventions established by centos-art.sh script # against source directory locations in the working copy. - ACTIONVAL=$(cli_checkRepoDirSource ${ACTIONVAL}) + local ARGUMENT=$(tcar_checkRepoDirSource ${ARGUMENT}) + + # Build list of files to process. + if [[ -f ${ARGUMENT} ]];then + local FILES=${ARGUMENT} + else + tcar_checkFiles -ed ${ARGUMENT} + local FILES=$(tcar_getFilesList ${ARGUMENT} \ + --pattern=".+${FILE_EXTENSION_REGEX}" \ + --type='f' | egrep ${TCAR_FLAG_FILTER}) + fi + + # Process list of files. + for FILE in ${FILES};do + + # Print action message. + tcar_printMessage "${FILE}" --as-tuningup-line - # Verify source location absolute path. It should point to - # existent directories under version control inside the - # working copy. Otherwise, if it doesn't point to an existent - # file under version control, finish the script execution with - # an error message. - cli_checkFiles ${ACTIONVAL} -d --is-versioned + # Retrieve module name to apply based on file extension . + local MODULE_NAME=$(echo ${FILE} \ + | sed -r "s/.+${FILE_EXTENSION_REGEX}/\1/") - # Synchronize changes between repository and working copy. At - # this point, changes in the repository are merged in the - # working copy and changes in the working copy committed up to - # repository. - cli_synchronizeRepoChanges "${ACTIONVAL}" + # Set module aliases. + if [[ ${MODULE_NAME} =~ '(shtml|html|htm)' ]];then + MODULE_NAME='xhtml' + fi - # Execute action name. - ${ACTIONNAM} + # Initiate module's environment for processing file. + tcar_setModuleEnvironment "${MODULE_NAME}" "${@}" - # Synchronize changes between repository and working copy. At - # this point, changes in the repository are merged in the - # working copy and changes in the working copy committed up to - # repository. - cli_synchronizeRepoChanges "${ACTIONVAL}" + done done diff --git a/Automation/Modules/Tuneup/tuneup_doBaseActions.sh b/Automation/Modules/Tuneup/tuneup_doBaseActions.sh deleted file mode 100755 index dc25fb8..0000000 --- a/Automation/Modules/Tuneup/tuneup_doBaseActions.sh +++ /dev/null @@ -1,98 +0,0 @@ -#!/bin/bash -# -# tuneup_doBaseActions.sh -- This function builds one list of files to -# process for each file extension supported and applies maintainance -# tasks file by file for each one of them. -# -# Copyright (C) 2009-2013 The CentOS Project -# -# 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 tuneup_doBaseActions { - - local TUNEUP_CONFIG_DIR='' - local TUNEUP_FORMAT_DIR='' - local TUNEUP_FORMAT_INIT='' - local TUNEUP_EXTENSION='' - local EXPORTID='' - local FILE='' - local FILES='' - - # Print separator line. - cli_printMessage '-' --as-separator-line - - # Loop through list of supported file extensions. - for TUNEUP_EXTENSION in ${TUNEUP_EXTENSIONS};do - - # Define format name based on supported file extensions. - TUNEUP_FORMAT="${TUNEUP_EXTENSION}" - - # Define specific functions export id. - EXPORTID="${CLI_FUNCDIRNAM}/$(cli_getRepoName ${TUNEUP_FORMAT} -d)/${TUNEUP_FORMAT}" - - # Define absolute path to directory where format-specific - # functionalities are stored in. - TUNEUP_FORMAT_DIR="${TUNEUP_BASEDIR}/$(cli_getRepoName \ - ${TUNEUP_FORMAT} -d)" - - # Define absolute path to format initialization script. - TUNEUP_FORMAT_INIT="${TUNEUP_FORMAT_DIR}/$(cli_getRepoName ${TUNEUP_FORMAT} -f).sh" - - # Verify absolute path to format initialization script. When - # a file extension is provided, but no format initialization - # script exists for it, continue with the next file extension - # in the list. - if [[ ! -f ${TUNEUP_FORMAT_INIT} ]];then - continue - fi - - # Define absolute path to directory where format-specific - # configurations are retrieved from. - TUNEUP_CONFIG_DIR="${TUNEUP_FORMAT_DIR}/Config" - - # Build list of files to process using action value as - # reference. - FILES=$(cli_getFilesList ${ACTIONVAL} --pattern="^.*${FLAG_FILTER}\.${TUNEUP_EXTENSION}$") - - # Verify list of files to process. Assuming no file is found, - # evaluate the next supported file extension. - if [[ $FILES == '' ]];then - continue - fi - - # Export format-specific functionalities up to the - # execution environment. - cli_exportFunctions "${EXPORTID}" - - # Execute format-specific maintenance tasks. - for FILE in $FILES;do - cli_printMessage "$FILE" --as-tuningup-line - ${TUNEUP_FORMAT} - done - - # Unset format-specific functionalities from execution - # environment. This is required to prevent end up with more - # than one format-specific function initialization, in those - # cases when different template files are rendered in just one - # execution of `centos-art.sh' script. - cli_unsetFunctions "${EXPORTID}" - - done - -} diff --git a/Automation/Modules/Tuneup/tuneup_getOptions.sh b/Automation/Modules/Tuneup/tuneup_getOptions.sh index 0cf8d33..c41d2c3 100755 --- a/Automation/Modules/Tuneup/tuneup_getOptions.sh +++ b/Automation/Modules/Tuneup/tuneup_getOptions.sh @@ -1,7 +1,11 @@ #!/bin/bash +###################################################################### # -# tuneup_getOptions.sh -- This function interprets option parameters -# passed to `tuneup' functionality and calls actions accordingly. +# tuneup_getOptions.sh -- This file initialize the command-line +# options used by tuneup module. +# +# Written by: +# * Alain Reguera Delgado , 2009-2013 # # Copyright (C) 2009-2013 The CentOS Project # @@ -19,72 +23,50 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # -# ---------------------------------------------------------------------- -# $Id$ -# ---------------------------------------------------------------------- +###################################################################### function tuneup_getOptions { # Define short options we want to support. - local ARGSS="h,q" + local ARGSS="h::,v" # Define long options we want to support. - local ARGSL="help,quiet,filter:,answer-yes,synchronize" + local ARGSL="help::,version,filter:" - # Redefine ARGUMENTS using getopt(1) command parser. - cli_parseArguments + # Redefine arguments using getopt(1) command parser. + tcar_setArguments "${@}" - # Redefine positional parameters using ARGUMENTS variable. - eval set -- "$ARGUMENTS" + # Reset positional parameters on this function, using output + # produced from (getopt) arguments parser. + eval set -- "${TCAR_ARGUMENTS}" # Look for options passed through command-line. while true; do - - case "$1" in + case "${1}" in -h | --help ) - cli_runFnEnvironment help --read --format="texinfo" "tcar-fs::scripts:bash-functions-tuneup" - shift 1 - exit + tcar_printHelp "${2}" + shift 2 ;; - -q | --quiet ) - FLAG_QUIET="true" - shift 1 + -v | --version ) + tcar_printVersion ;; --filter ) - FLAG_FILTER="$2" + TCAR_FLAG_FILTER="${2}" shift 2 ;; - --answer-yes ) - FLAG_ANSWER="true" - shift 1 - ;; - - --synchronize ) - FLAG_SYNCHRONIZE="true" - shift 1 - ;; - -- ) - # Remove the `--' argument from the list of arguments - # in order for processing non-option arguments - # correctly. At this point all option arguments have - # been processed already but the `--' argument still - # remains to mark ending of option arguments and - # begining of non-option arguments. The `--' argument - # needs to be removed here in order to avoid - # centos-art.sh script to process it as a path inside - # the repository, which obviously is not. shift 1 break ;; esac done - # Redefine ARGUMENTS variable using current positional parameters. - cli_parseArgumentsReDef "$@" + # Redefine arguments using current positional parameters. Only + # paths should remain as arguments, at this point. + TCAR_ARGUMENTS="${@}" }