Blame tcar-scripts-tuneup/tuneup.sh

Alain Reguera Delgado b29c5b
#!/bin/bash
Alain Reguera Delgado b29c5b
######################################################################
Alain Reguera Delgado b29c5b
#
Alain Reguera Delgado b29c5b
#   tuneup.sh -- This module standardizes source code file
Alain Reguera Delgado b29c5b
#   maintainance inside the repository.
Alain Reguera Delgado b29c5b
#
Alain Reguera Delgado b29c5b
#   Written by:
Alain Reguera Delgado b29c5b
#   * Alain Reguera Delgado <al@centos.org.cu>, 2009-2013
Alain Reguera Delgado b29c5b
#
Alain Reguera Delgado b29c5b
# Copyright (C) 2009-2013 The CentOS Artwork SIG
Alain Reguera Delgado b29c5b
#
Alain Reguera Delgado b29c5b
# This program is free software; you can redistribute it and/or modify
Alain Reguera Delgado b29c5b
# it under the terms of the GNU General Public License as published by
Alain Reguera Delgado b29c5b
# the Free Software Foundation; either version 2 of the License, or (at
Alain Reguera Delgado b29c5b
# your option) any later version.
Alain Reguera Delgado b29c5b
#
Alain Reguera Delgado b29c5b
# This program is distributed in the hope that it will be useful, but
Alain Reguera Delgado b29c5b
# WITHOUT ANY WARRANTY; without even the implied warranty of
Alain Reguera Delgado b29c5b
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Alain Reguera Delgado b29c5b
# General Public License for more details.
Alain Reguera Delgado b29c5b
#
Alain Reguera Delgado b29c5b
# You should have received a copy of the GNU General Public License
Alain Reguera Delgado b29c5b
# along with this program; if not, write to the Free Software
Alain Reguera Delgado b29c5b
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Alain Reguera Delgado b29c5b
#
Alain Reguera Delgado b29c5b
######################################################################
Alain Reguera Delgado b29c5b
Alain Reguera Delgado b29c5b
function tuneup {
Alain Reguera Delgado b29c5b
Alain Reguera Delgado b29c5b
    # Define file extensions tuneup module will look for processing.
Alain Reguera Delgado b29c5b
    local FILE_EXTENSION_REGEX='\.(svgz|svg|shtml|xhtml|html|sh)$'
Alain Reguera Delgado b29c5b
Alain Reguera Delgado b29c5b
    tuneup_getOptions
Alain Reguera Delgado b29c5b
Alain Reguera Delgado b29c5b
    for ARGUMENT in ${TCAR_MODULE_ARGUMENT};do
Alain Reguera Delgado b29c5b
Alain Reguera Delgado b29c5b
        # Sanitate non-option arguments to be sure they match the
Alain Reguera Delgado b29c5b
        # directory conventions established by centos-art.sh script
Alain Reguera Delgado b29c5b
        # against source directory locations in the working copy.
Alain Reguera Delgado b29c5b
        local ARGUMENT=$(tcar_checkRepoDirSource ${ARGUMENT})
Alain Reguera Delgado b29c5b
Alain Reguera Delgado b29c5b
        # Build list of files to process.
Alain Reguera Delgado b29c5b
        if [[ -f ${ARGUMENT} ]];then
Alain Reguera Delgado b29c5b
            local FILES=${ARGUMENT}
Alain Reguera Delgado b29c5b
        elif [[ -d ${ARGUMENT} ]];then
Alain Reguera Delgado b29c5b
            local FILES=$(tcar_getFilesList ${ARGUMENT} \
Alain Reguera Delgado b29c5b
                --pattern=".+${FILE_EXTENSION_REGEX}" \
Alain Reguera Delgado b29c5b
                --type='f' | egrep ${TCAR_FLAG_FILTER})
Alain Reguera Delgado b29c5b
        else
Alain Reguera Delgado b29c5b
            tcar_printMessage "`gettext "The argument provided isn't valid."`" --as-error-line
Alain Reguera Delgado b29c5b
        fi
Alain Reguera Delgado b29c5b
Alain Reguera Delgado b29c5b
        # Process list of files.
Alain Reguera Delgado b29c5b
        for FILE in ${FILES};do
Alain Reguera Delgado b29c5b
Alain Reguera Delgado b29c5b
            # Print action message.
Alain Reguera Delgado b29c5b
            tcar_printMessage "${FILE}" --as-tuningup-line
Alain Reguera Delgado b29c5b
Alain Reguera Delgado b29c5b
            # Retrieve module name to apply based on file extension .
Alain Reguera Delgado b29c5b
            local FILE_EXTENSION=$(echo ${FILE} \
Alain Reguera Delgado b29c5b
                | sed -r "s/.+${FILE_EXTENSION_REGEX}/\1/")
Alain Reguera Delgado b29c5b
Alain Reguera Delgado b29c5b
            # Set module aliases. 
Alain Reguera Delgado b29c5b
            if [[ ${FILE_EXTENSION} =~ '(shtml|html|htm)' ]];then
Alain Reguera Delgado b29c5b
                FILE_EXTENSION='xhtml'
Alain Reguera Delgado b29c5b
            fi
Alain Reguera Delgado b29c5b
Alain Reguera Delgado b29c5b
            # Initiate module's environment for processing file.
Alain Reguera Delgado b29c5b
            tcar_setModuleEnvironment -m "${FILE_EXTENSION}" -t "child" "${FILE}"
Alain Reguera Delgado b29c5b
Alain Reguera Delgado b29c5b
        done
Alain Reguera Delgado b29c5b
Alain Reguera Delgado b29c5b
    done
Alain Reguera Delgado b29c5b
Alain Reguera Delgado b29c5b
}