Blame Manuals/en/Html/Repository/repository_43.html

4c79b5
4c79b5
<html>
09d4f2
09d4f2
09d4f2
The CentOS Artwork Repository exists to organize and automate The
09d4f2
CentOS Project corporate visual identity (, to
09d4f2
start on).
4c79b5
6c4982
Copyright C 2009, 2010 Alain Reguera Delgado. All rights
4c79b5
reserved.
4c79b5
4c79b5
Permission is granted to copy, distribute and/or modify this document
4c79b5
under the terms of the GNU Free Documentation License, Version 1.2 or
4c79b5
any later version published by the Free Software Foundation; with no
4c79b5
Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A
4c79b5
copy of the license is included in the section entitled GNU Free
4c79b5
Documentation License.  
4c79b5
-->
008ee0
4c79b5
4c79b5
Written by: Lionel Cons <Lionel.Cons@cern.ch> (original author)
4c79b5
            Karl Berry  <karl@freefriends.org>
4c79b5
            Olaf Bachmann <obachman@mathematik.uni-kl.de>
4c79b5
            and many others.
4c79b5
Maintained by: Many creative people <dev@texi2html.cvshome.org>
4c79b5
Send bugs and suggestions to <users@texi2html.cvshome.org>
4c79b5
4c79b5
-->
4c79b5
<head>
008ee0
<title>CentOS Artwork Repository: 3.40 trunk/Scripts/Bash/Functions</title>
4c79b5
008ee0
<meta name="description" content="CentOS Artwork Repository: 3.40 trunk/Scripts/Bash/Functions">
008ee0
<meta name="keywords" content="CentOS Artwork Repository: 3.40 trunk/Scripts/Bash/Functions">
4c79b5
<meta name="resource-type" content="document">
4c79b5
<meta name="distribution" content="global">
4c79b5
<meta name="Generator" content="texi2html 1.76">
4c79b5
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
4c79b5
<style type="text/css">
4c79b5
1e9202
@import "/home/centos/artwork/trunk/Identity/Models/Css/Texi2html/common.css";
4c79b5
4c79b5
a.summary-letter {text-decoration: none}
4c79b5
pre.display {font-family: serif}
4c79b5
pre.format {font-family: serif}
4c79b5
pre.menu-comment {font-family: serif}
4c79b5
pre.menu-preformatted {font-family: serif}
4c79b5
pre.smalldisplay {font-family: serif; font-size: smaller}
4c79b5
pre.smallexample {font-size: smaller}
4c79b5
pre.smallformat {font-family: serif; font-size: smaller}
4c79b5
pre.smalllisp {font-size: smaller}
4c79b5
span.sansserif {font-family:sans-serif; font-weight:normal;}
4c79b5
ul.toc {list-style: none}
4c79b5
-->
4c79b5
</style>
4c79b5
4c79b5
4c79b5
</head>
4c79b5
4c79b5
<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
4c79b5
4c79b5
008ee0
[ < ]
008ee0
[ > ]
4c79b5
   
4c79b5
[ << ]
4c79b5
[ Up ]
008ee0
[ >> ]
4c79b5
   
4c79b5
   
4c79b5
   
4c79b5
   
4c79b5
[Top]
4c79b5
[Contents]
008ee0
[Index]
4c79b5
[ ? ]
4c79b5
008ee0
008ee0
008ee0

3.40 trunk/Scripts/Bash/Functions

6aec21
54264c
008ee0
081970

3.40.1 Goals

081970
008ee0

The <tt>`trunk/Scripts/Bash/Functions'</tt> directory exists to organize

008ee0
<tt>`centos-art.sh'</tt> specific functionalities.
008ee0

6aec21
008ee0
081970

3.40.2 Description

6aec21
008ee0

The specific functions of <tt>`centos-art.sh'</tt> script are designed

008ee0
with "Software Toolbox" philosophy (see (coreutils.info)Toolbox introduction) in mind: each program "should do one
008ee0
thing well".  Inside <tt>`centos-art.sh'</tt> script, each specific
008ee0
functionality is considered a program that should do one thing well.
008ee0
Of course, if you find that they still don't do it, feel free to
008ee0
improve them in order for them to do so.
008ee0

008ee0

The specific functions of <tt>`centos-art.sh'</tt> script are organized

008ee0
inside specific directories under <tt>`trunk/Scripts/Bash/Functions'</tt>
008ee0
location. Each specific function directory should be named as the
008ee0
function it represents, with the first letter in uppercase. For
008ee0
example, if the function name is render, the specific function
008ee0
directory for it would be <samp>`trunk/Scripts/Bash/Functions/Render'</samp>.
008ee0

008ee0

To better understand how specific functions of <tt>`centos-art.sh'</tt>

008ee0
script are designed, lets create one function which only goal is to
008ee0
output different kind of greetings to your screen.
008ee0

008ee0

When we create specific functions for <tt>`centos-art.sh'</tt> script it

008ee0
is crucial to know what these functions will do exactly and if there
008ee0
is any function that already does what we intend to do. If there is no
008ee0
one, it is good time to create them then. Otherwise, if
008ee0
functionalities already available don't do what you exactly expect,
008ee0
contact their authors and work together to improve them.
008ee0

008ee0
Info

Tip

Join CentOS developers mailing list

008ee0
centos-art@centos.org to share your ideas.
008ee0

008ee0
008ee0

It is also worth to know what global functions and variables do we

008ee0
have available inside <tt>`centos-art.sh'</tt> script, so advantage can be
008ee0
taken from them. Global variables are defined inside global function
008ee0
scripts. Global functions scripts are stored immediatly under
008ee0
<tt>`trunk/Scripts/Bash/Functions'</tt> directory, in files begining with
008ee0
<samp>`cli'</samp> prefix.
008ee0

008ee0

OK, let's begin with our functionality example.

008ee0

008ee0

What function name do we use? Well, lets use greet. Note that

008ee0
<samp>`hello'</samp> word is not a verb; but an expression, a kind of
008ee0
greeting, an interjection specifically. In contrast, <samp>`greet'</samp> is a
008ee0
verb and describes what we do when we say <samp>`Hello!'</samp>, <samp>`Hi!'</samp>,
008ee0
and similar expressions.
008ee0

008ee0

So far, we've gathered the following function information:

008ee0

008ee0
Name: greet
008ee0
Path: trunk/Scripts/Bash/Functions/Greet
008ee0
File: trunk/Scripts/Bash/Functions/Greet/greet.sh
008ee0
008ee0

The <tt>`greet.sh'</tt> function script is the first file

008ee0
<tt>`centos-art.sh'</tt> script loads when the <samp>`greet'</samp> functionality
008ee0
is called using commands like <samp>`centos-art greet --hello='World''</samp>.
008ee0
The <tt>`greet.sh'</tt> function script contains the greet function
008ee0
definition. 
008ee0

008ee0

Inside <tt>`centos-art.sh'</tt> script, as convenction, each function

008ee0
script has one top commentary, followed by one blank line, and then
008ee0
one function defintion below it only.
008ee0

008ee0

Inside <tt>`centos-art.sh'</tt> script functions, top commentaries have

008ee0
the following components: the functionality description, one-line for
008ee0
copyright note with your personal information,  the license under
008ee0
which the function source code is released --the <tt>`centos-art.sh'</tt>
008ee0
script is released as GPL, so do all its functions--, subversion's
008ee0
$Id$ keyword which is later expanded by svn propset
008ee0
command.
008ee0

008ee0

In our greet function example, top commentary for

008ee0
<tt>`greet.sh'</tt> function script would look like the following:
008ee0

008ee0
#!/bin/bash
008ee0
#
008ee0
# greet.sh -- This function outputs different kind of greetings to
008ee0
# your screen. Use this function to understand how centos-art.sh
008ee0
# script specific functionalities work.
008ee0
#
008ee0
# Copyright (C) YEAR YOURFULLNAME
008ee0
#
008ee0
# This program is free software; you can redistribute it and/or modify
008ee0
# it under the terms of the GNU General Public License as published by
008ee0
# the Free Software Foundation; either version 2 of the License, or
008ee0
# (at your option) any later version.
008ee0
# 
008ee0
# This program is distributed in the hope that it will be useful, but
008ee0
# WITHOUT ANY WARRANTY; without even the implied warranty of
008ee0
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
008ee0
# General Public License for more details.
008ee0
#
008ee0
# You should have received a copy of the GNU General Public License
008ee0
# along with this program; if not, write to the Free Software
008ee0
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
008ee0
# USA.
008ee0
# 
008ee0
# ----------------------------------------------------------------------
008ee0
# $Id$
008ee0
# ----------------------------------------------------------------------
008ee0
008ee0

After top commentary, separated by one blank line, the greet

008ee0
function definition would look like the following:
008ee0

008ee0
function greet {
008ee0
008ee0
    # Define global variables.
008ee0
008ee0
    # Define command-line interface.
008ee0
    greet_getActions
008ee0
008ee0
}
008ee0
008ee0

The first definition inside greet function, are global

008ee0
variables that will be available along greet function execution
008ee0
environment. This time we didn't use global variable definitions for
008ee0
greet function execution environment, so we left that section
008ee0
empty.
008ee0

008ee0

Later, we call greet_getActions function to define the

008ee0
command-line interface of greet functionality. The greet
008ee0
functionality command-line interface defines what and how actions are
008ee0
performed, based on arguments combination passed to
008ee0
<tt>`centos-art.sh'</tt> script.
008ee0

008ee0
function greet_getActions {
008ee0
008ee0
    case "$ACTIONNAM" in
008ee0
008ee0
        --hello )
008ee0
            greet_doHello
008ee0
            ;;
008ee0
008ee0
        --bye )
008ee0
            greet_doBye
008ee0
            ;;
008ee0
008ee0
        * )
008ee0
            cli_printMessage "`gettext "The option provided is not valid."`"
008ee0
            cli_printMessage "$(caller)" 'AsToKnowMoreLine'
008ee0
008ee0
    esac
008ee0
008ee0
}
008ee0
008ee0

The ACTIONNAM global variable is defined in <tt>`cli.sh'</tt>

008ee0
function script and contains the value passed before the equal sign
008ee0
(i.e., <samp>`='</samp>) in the second command-line argument of
008ee0
<tt>`centos-art.sh'</tt> script. For example, if the second command-line
008ee0
argument is <samp>`--hello='World''</samp>, the value of ACTIONNAM
008ee0
variable would be <samp>`--hello'</samp>.  Using this configuration let us
008ee0
deside which action to perform based on the action name passed to
008ee0
<tt>`centos-art.sh'</tt> script as second argument. 
008ee0

008ee0

The greet function definition makes available two valid

008ee0
greetings through <samp>`--hello'</samp> and <samp>`--bye'</samp> options.  If no
008ee0
one of them is provided as second command-line argument, the <samp>`*'</samp>
008ee0
case is evaluated instead. 
008ee0

008ee0

The <samp>`*'</samp> case and its two further lines should always be present

008ee0
in <tt>`_getActions.sh'</tt> function scripts, no matter what specific
008ee0
functionality you are creating. This convenction helps the user to
008ee0
find out documentation about current functionality in use.  
008ee0

008ee0

The greet_doHello and greet_doBye function definitions

008ee0
are the core of greet specific functionality.  In such function
008ee0
definitions we set what our greet function really does: to
008ee0
output different kinds of greetings.
008ee0

008ee0
function greet_doHello {
008ee0
008ee0
    cli_printMessage "`gettext "Hello"` $ACTIONVAL"
008ee0
008ee0
}
008ee0
008ee0

The greet_doHello function definition is stored in

008ee0
<tt>`greet_doHello.sh'</tt> function script. 
008ee0

008ee0
function greet_doBye {
008ee0
008ee0
    cli_printMessage "`gettext "Goodbye"` $ACTIONVAL"
008ee0
008ee0
}
008ee0
008ee0

The greet_doBye function definition is stored in the

008ee0
<tt>`greet_doBye.sh'</tt> function script. 
008ee0

008ee0

Both <tt>`greet_doHello.sh'</tt> and <tt>`greet_doBye.sh'</tt> function

008ee0
scripts are stored inside greet's function directory path (i.e.
008ee0
<tt>`trunk/Scripts/Bash/Functions/Greet'</tt>).
008ee0

008ee0

The ACTIONVAL global variable is defined in <tt>`cli.sh'</tt>

008ee0
function script and contains the value passed after the equal sign
008ee0
(i.e., <samp>`='</samp>) in the second command-line argument of
008ee0
<tt>`centos-art.sh'</tt> script. For example, if the second command-line
008ee0
argument is <samp>`--hello='World''</samp>, the value of ACTIONVAL
008ee0
variable would be <samp>`World'</samp> without quotes.
008ee0

008ee0

Let's see how greet specific functionality files are organzied

008ee0
under greet's function directory. To see file organization we
008ee0
use the tree command:
008ee0

008ee0
trunk/Scripts/Bash/Functions/Greet
008ee0
|-- greet_doBye.sh
008ee0
|-- greet_doHello.sh
008ee0
|-- greet_getActions.sh
008ee0
`-- greet.sh
008ee0
008ee0

To try the greet specific functionality we've just created,

008ee0
pass the function name (i.e., <samp>`greet'</samp>) as first argument to
008ee0
<tt>`centos-art.sh'</tt> script, and any of the valid options as second
008ee0
argument. Some examples are illustrated below:
008ee0

008ee0
[centos@projects ~]$ centos-art greet --hello='World'
008ee0
Hello World
008ee0
[centos@projects ~]$ centos-art greet --bye='World'
008ee0
Goodbye World
008ee0
[centos@projects ~]$ 
008ee0
008ee0

The word <samp>`World'</samp> in the examples above can be anything. In fact,

008ee0
change it to have a little fun.
008ee0

008ee0

Now that we have a specific function that works as we expect, it is

008ee0
time to document it. To document greet specific functionality,
008ee0
we use its directory path and the help functionality
008ee0
(see section trunk/Scripts/Bash/Functions/Help) of <tt>`centos-art.sh'</tt>
008ee0
script, just as the following command illustrates: 
008ee0

008ee0
centos-art help --edit=trunk/Scripts/Bash/Functions/Greet
008ee0
008ee0

Now that we have documented our function, it is time to translate its

008ee0
output messages to different languages. To translate specific
008ee0
functionality output messages to different languages we use the
008ee0
locale functionality (see section trunk/Scripts/Bash/Functions/Locale) of <tt>`centos-art.sh'</tt> script, just as the following command
008ee0
illustrates:
008ee0

008ee0
centos-art locale --edit
008ee0
008ee0
Warning

Warning

To translate output messages in different languages,

008ee0
your system locale information --as in LANG environment
008ee0
variable-- must be set to that locale you want to produce translated
008ee0
messages for. For example, if you want to produce translated messages
008ee0
for Spanish language, your system locale information must be set to
008ee0
<samp>`es_ES.UTF-8'</samp> or similar.  
008ee0

6aec21
008ee0

Well, it seems that our example is rather complete by now.

008ee0

008ee0

In greet function example we've described so far, we only use

008ee0
cli_printMessage global function in action specific function
008ee0
definitions in order to print a message simply, but more interesting
008ee0
things can be achieved inside action specific function definitions.
008ee0
For example, if you pass a directory path as second argument option
008ee0
value, you could retrive a list of files from therein, and process
008ee0
them. If the list of files turns too long or you just want to control
008ee0
which files to process, you could add the third argument in the form
008ee0
<samp>`--filter='regex''</samp> and reduce the amount of files to process
008ee0
using a regular expression pattern.
008ee0

008ee0

The greet function described in this section may serve you as

008ee0
an introduction to understand how specific functionalities work inside
008ee0
<tt>`centos-art.sh'</tt> script. With some of luck this introduction will
008ee0
also serve you as motivation to create your own <tt>`centos-art.sh'</tt>
008ee0
script specific functionalities.
008ee0

008ee0

By the way, the greet functionality doesn't exist inside

008ee0
<tt>`centos-art.sh'</tt> script yet. Would you like to create it?
008ee0

6aec21
008ee0
6aec21

3.40.3 Usage

6aec21
008ee0
008ee0
008ee0

3.40.3.1 Global variables

008ee0
008ee0

The following global variables of <tt>`centos-art.sh'</tt> script, are

008ee0
available for you to use inside specific functions:
008ee0

008ee0
008ee0
<u>Variable:</u> TEXTDOMAIN
008ee0
008ee0
008ee0

Default domain used to retrieve translated messages. This value is set

008ee0
in <tt>`initFunctions.sh'</tt> and shouldn't be changed.
008ee0

008ee0
008ee0
008ee0
<u>Variable:</u> TEXTDOMAINDIR
008ee0
008ee0
008ee0

Default directory used to retrieve translated messages. This value is

008ee0
set in <tt>`initFunctions.sh'</tt> and shouldn't be changed.
008ee0

008ee0
008ee0
008ee0
<u>Variable:</u> FUNCNAM
008ee0
008ee0
008ee0

Define function name.

008ee0

008ee0

Function names associate sets of actions. There is one set of actions

008ee0
for each unique function name inside <tt>`centos-art.sh'</tt> script.
008ee0

008ee0

Dunction names are passed as first argument in <tt>`centos-art.sh'</tt>

008ee0
command-line interface. For example, in the command <samp>`centos-art
008ee0
render --entry=path/to/dir --filter=regex'</samp>, the ACTION passed to
008ee0
<tt>`centos-art.sh'</tt> script is <samp>`render'</samp>.
008ee0

008ee0

When first argument is not provided, the <tt>`centos-art.sh'</tt> script

008ee0
immediatly ends its execution.
008ee0

008ee0
008ee0
008ee0
<u>Variable:</u> ACTIONNAM
008ee0
008ee0
008ee0

Define action name.

008ee0

008ee0

Each action name identifies an specific action to perform, inside an

008ee0
specific function.
008ee0

008ee0

Action name names aare passed as second argument in

008ee0
<tt>`centos-art.sh'</tt> command-line interface. For example, in the
008ee0
command <samp>`centos-art render --entry=path/to/dir --filter=regex'</samp>,
008ee0
the ACTIONNAM passed to <tt>`centos-art.sh'</tt> script is
008ee0
<samp>`--entry'</samp>.
008ee0

008ee0

When second argument is not provided, the <tt>`centos-art.sh'</tt> script

008ee0
immediatly ends its execution.
008ee0

008ee0
008ee0
008ee0
<u>Variable:</u> ACTIONVAL
008ee0
008ee0
008ee0

Define action value.

008ee0

008ee0

Action values are associated to just one action name. Action values

008ee0
contain the repository entry over which its associated action will be
008ee0
performed in.  Repository entries can be directories, files, or URLs
008ee0
refering the repository structure.
008ee0

008ee0

When action value is not specified as repository entry, the

008ee0
<tt>`centos-art.sh'</tt> script evaluates the current directory it was
008ee0
executed from. If such directory is under the repository structure
008ee0
(i.e., <tt>`/home/centos/artwork/'</tt>), the <tt>`centos-art.sh'</tt> script
008ee0
uses that directory as value to ACTIONVAL variable. Otherwise,
008ee0
if outside the repository structure, the <tt>`centos-art.sh'</tt> script
008ee0
prints the message <samp>`The path provided can't be processed.'</samp> and,
008ee0
after it, immediatly ends script execution.
008ee0

008ee0

Default action value is passed as second argument in

008ee0
<tt>`centos-art.sh'</tt> command-line interface. For example, in the
008ee0
command <samp>`centos-art render --entry=path/to/dir --filter=regex'</samp>,
008ee0
the ACTIONVAL passed to <tt>`centos-art.sh'</tt> script is
008ee0
<samp>`path/to/dir'</samp>.
008ee0

008ee0
008ee0
008ee0
<u>Variable:</u> REGEX
008ee0
008ee0
008ee0

Define regular expression used as pattern to build the list of files

008ee0
to process.
008ee0

008ee0

By default, REGEX variable is set to .+ to match all

008ee0
files.
008ee0

008ee0

Functions that need to build a list of files to process use the option

008ee0
<samp>`--filter'</samp> to redefine REGEX variable default value, and
008ee0
so, control the amount of files to process.
008ee0

008ee0
008ee0
008ee0
<u>Variable:</u> ARGUMENTS
008ee0
008ee0
008ee0

Define optional arguments.

008ee0

008ee0

Optional arguments, inside <tt>`centos-art.sh'</tt> script, are considered

008ee0
as all command-line arguments passed to <tt>`centos-art.sh'</tt> script,
008ee0
from third argument position on. For example, in the command
008ee0
<samp>`centos-art render --entry=path/to/dir --filter=regex'</samp> , the
008ee0
optional arguments are from <samp>`--filter=regex'</samp> argument on.
008ee0

008ee0

Optional arguments are parsed using getopt command through

008ee0
the following base construction: 
008ee0

008ee0
# Define short options we want to support.
008ee0
local ARGSS=""
008ee0
008ee0
# Define long options we want to support.
008ee0
local ARGSL="filter:,to:"
008ee0
008ee0
# Parse arguments using getopt(1) command parser.
008ee0
cli_doParseArguments
008ee0
008ee0
# Reset positional parameters using output from (getopt) argument
008ee0
# parser.
008ee0
eval set -- "$ARGUMENTS"
008ee0
008ee0
# Define action to take for each option passed.
008ee0
while true; do
008ee0
    case "$1" in
008ee0
        --filter )
008ee0
            REGEX="$2" 
008ee0
            shift 2
008ee0
            ;;
008ee0
        --to )
008ee0
            TARGET="$2" 
008ee0
            shift 2
008ee0
            ;;
008ee0
        * )
008ee0
            break
008ee0
    esac
008ee0
done
008ee0
008ee0

Optional arguments provide support to command options inside

008ee0
<tt>`centos-art.sh'</tt> script. For instance, consider the Subversion
008ee0
(svn) command, where there are many options (e.g.,
008ee0
<samp>`copy'</samp>, <samp>`delete'</samp>, <samp>`move'</samp>, etc), and inside each
008ee0
option there are several modifiers (e.g., <samp>`--revision'</samp>,
008ee0
<samp>`--message'</samp>, <samp>`--username'</samp>, etc.) that can be combined one
008ee0
another in their short or long variants. 
008ee0

008ee0

The ARGUMENTS variable is used to store arguments passed from

008ee0
command-line for later use inside <tt>`centos-art.sh'</tt> script. Storing
008ee0
arguments is specially useful when we want to run a command with some
008ee0
specific options from them. Consider the following command:
008ee0

008ee0
centos-art path --copy=SOURCE --to=TARGET --message="The commit message goes here." --username='johndoe'
008ee0
008ee0

In the above command, the <samp>`--message'</samp>, and <samp>`--username'</samp>

008ee0
options are specific to svn copy command. In such cases,
008ee0
options are not interpreted by <tt>`centos-art.sh'</tt> script itself.
008ee0
Instead, the <tt>`centos-art.sh'</tt> script uses getopt to
008ee0
retrive them and stores them in the ARGUMENT variable for later
008ee0
use, as described in the following command:
008ee0

008ee0
# Build subversion command to duplicate locations inside the
008ee0
# workstation.
008ee0
eval svn copy $SOURCE $TARGET --quiet $ARGUMENTS
008ee0
008ee0

When getopt parses ARGUMENTS, we may use short options

008ee0
(e.g., <samp>`-m'</samp>) or long options (e.g., <samp>`--message'</samp>). When
008ee0
we use short options, arguments are separated by one space from the
008ee0
option (e.g., <samp>`-m 'This is a commit message.''</samp>).  When we use
008ee0
long options arguments are separated by an equal sign (<samp>`='</samp>)
008ee0
(e.g., <samp>`--message='This is a commit message''</samp>).
008ee0

008ee0

In order for getopt to parse ARGUMENTS correctly, it

008ee0
is required to provide the short and long definition of options that
008ee0
will be passed or at least supported by the command performing the
008ee0
final action the function script exists for.
008ee0

008ee0

As convenction, inside <tt>`centos-art.sh'</tt> script, short option

008ee0
definitions are set in the ARGSS variable; and long option
008ee0
definitions are set in the ARGSL variable.
008ee0

008ee0

When you define short and long options, it may be needed to define

008ee0
which of these option arguments are required and which not. To define
008ee0
an option argument as required, you need to set one colon <samp>`:'</samp>
008ee0
after the option definition (e.g., <samp>`-o m: -l message:'</samp>).  On
008ee0
the other hand, to define an option argument as not required, you need
008ee0
to set two colons <samp>`::'</samp> after the option definition (e.g.,
008ee0
<samp>`-o m:: -l message::'</samp>).
008ee0

008ee0
008ee0
008ee0
<u>Variable:</u> EDITOR
008ee0
008ee0
008ee0

Default text editor.

008ee0

008ee0

The <tt>`centos-art.sh'</tt> script uses default text EDITOR to edit

008ee0
pre-commit subversion messages, translation files, configuration
008ee0
files, script files, and similar text-based files.
008ee0

008ee0

If EDITOR environment variable is not set, <tt>`centos-art.sh'</tt>

008ee0
script uses <tt>`/usr/bin/vim'</tt> as default text editor. Otherwise, the
008ee0
following values are recognized by <tt>`centos-art.sh'</tt> script:
008ee0

081970
    008ee0
  • <tt>`/usr/bin/vim'</tt>
  • 008ee0
  • <tt>`/usr/bin/emacs'</tt>
  • 008ee0
  • <tt>`/usr/bin/nano'</tt>
  • 081970
    6aec21
    008ee0

    If no one of these values is set in EDITOR environment variable,

    008ee0
    <tt>`centos-art.sh'</tt> uses <tt>`/usr/bin/vim'</tt> text editor by default. 
    008ee0

    008ee0
    008ee0
    008ee0
    008ee0

    3.40.3.2 Global functions

    008ee0
    008ee0

    The following global functions of <tt>`centos-art.sh'</tt> script are

    008ee0
    available for you to use inside specific functions:
    008ee0

    008ee0
    008ee0
    <u>Function:</u> cli_commitRepoChanges [LOCATION]
    008ee0
    008ee0
    008ee0

    Syncronize changes between repository and working copy.

    008ee0

    008ee0

    The cli_commitRepoChanges function uses the value of

    008ee0
    LOCATION argument as reference to perform change verification
    008ee0
    inside the working copy using subversion commands. If LOCATION
    008ee0
    argument is not specified as cli_commitRepoChanges first
    008ee0
    argument, the ACTIONVAL variable is used as reference instead.
    008ee0

    008ee0

    The cli_commitRepoChanges function brings changes from the

    008ee0
    repository to the working copy--using svn update--, checks
    008ee0
    the working copy changes--using svn status command--,
    008ee0
    prints status report--using both svn update and
    008ee0
    svn status commands output, and finally, commits recent
    008ee0
    changes from the working copy up to the repository--using
    008ee0
    svn commit command--.
    008ee0

    008ee0

    Previous to commit the working copy changes up to the repository, the

    008ee0
    cli_commitRepoChanges function asks you to verify
    008ee0
    changes--using svn diff command--, and later, another
    008ee0
    confirmation question is shown to be sure you really want to commit
    008ee0
    changes up to central repository.
    008ee0

    008ee0
    008ee0
    ----------------------------------------------------------------------
    008ee0
    --> Bringing changes from the repository into the working copy
    008ee0
    --> Checking changes in the working copy
    008ee0
    ----------------------------------------------------------------------
    008ee0
    Added           0 file from the repository.
    008ee0
    Deleted         0 file from the repository.
    008ee0
    Updated         0 file from the repository.
    008ee0
    Conflicted      0 file from the repository.
    008ee0
    Merged          0 file from the repository.
    008ee0
    Modified        4 files from the working copy.
    008ee0
    Unversioned     0 file from the working copy.
    008ee0
    Deleted         0 file from the working copy.
    008ee0
    Added           0 file from the working copy.
    008ee0
    ----------------------------------------------------------------------
    008ee0
    008ee0

    Figure 3.9: The cli_commitRepoChanges function output.

    008ee0
    008ee0

    008ee0

    Call the cli_commitRepoChanges function before or/and after

    008ee0
    functions that modify files or directories inside the working copy as
    008ee0
    you may need to.  
    008ee0

    008ee0
    008ee0
    008ee0
    <u>Function:</u> cli_checkFiles FILE [TYPE]
    008ee0
    008ee0
    008ee0

    Verify files existence.

    008ee0

    008ee0

    cli_checkFiles receives a FILE absolute path and performs

    008ee0
    file verification as specified in TYPE.  When TYPE is not
    008ee0
    specified, cli_checkFiles verifies FILE existence, no
    008ee0
    matter what kind of file it be.  If TYPE is specified, use one
    008ee0
    of the following values:
    008ee0

    008ee0
    008ee0
    <samp>`d'</samp>
    008ee0
    <samp>`directory'</samp>
    008ee0

    Ends script execution if FILE is not a directory.

    008ee0

    008ee0

    When you verify directories with cli_checkFiles, if directory doesn't

    008ee0
    exist, <tt>`centos-art.sh'</tt> script asks you for confirmation in order
    008ee0
    to create that directory. If you answer positively,
    008ee0
    <tt>`centos-art.sh'</tt> script creates that directory and continues
    008ee0
    script flows normally. Otherwise, if you answer negatively,
    008ee0
    <tt>`centos-art.sh'</tt> ends script execution with an error and
    008ee0
    documentation message.
    008ee0

    008ee0
    008ee0
    <samp>`f'</samp>
    008ee0
    <samp>`regular-file'</samp>
    008ee0

    Ends script execution if FILE is not a regular file.

    008ee0

    008ee0
    <samp>`h'</samp>
    008ee0
    <samp>`symbolic-link'</samp>
    008ee0

    Ends script execution if FILE is not a symbolic link.

    008ee0

    008ee0
    <samp>`x'</samp>
    008ee0
    <samp>`execution'</samp>
    008ee0

    Ends script execution if FILE is not executable.

    008ee0

    008ee0
    <samp>`fh'</samp>
    008ee0

    Ends script execution if FILE is neither a regular file or a

    008ee0
    symbolic link.
    008ee0

    008ee0
    6aec21
    008ee0

    As default behaviour, if FILE passes all verifications,

    008ee0
    <tt>`centos-art.sh'</tt> script continues with its normal flow. 
    008ee0

    008ee0
    008ee0
    008ee0
    <u>Function:</u> cli_getCountryCodes [FILTER]
    008ee0
    008ee0
    008ee0

    Output country codes.

    008ee0

    008ee0

    The cli_getCountryCodes function outputs a list with country

    008ee0
    codes as defined in ISO3166 standard. When FILTER is provided,
    008ee0
    cli_getCountryCodes outputs country codes that match
    008ee0
    FILTER regular expression pattern.
    008ee0

    008ee0
    008ee0
    008ee0
    <u>Function:</u> cli_getCountryName [FILTER]
    008ee0
    008ee0
    008ee0

    Output country names.

    008ee0

    008ee0

    The cli_getCountryName function reads one language locale code

    008ee0
    in the format LL_CC and outputs the name of its related country as in
    008ee0
    ISO3166. If filter is specified, cli_getCountryName returns the
    008ee0
    country name that matches the locale code specified in FILTER,
    008ee0
    exactly.
    008ee0

    008ee0

    The cli_getCountryName function outputs country name supported

    008ee0
    by <tt>`centos-art.sh'</tt> script.
    008ee0

    008ee0
     
    008ee0
    008ee0
    <u>Function:</u> cli_getCurrentLocale
    008ee0
    008ee0
    008ee0

    Output current locale used by <tt>`centos-art.sh'</tt> script.

    008ee0

    008ee0

    The cli_getCurrentLocale function uses LANG environment

    008ee0
    variable to build a locale pattern that is later applied to
    008ee0
    cli_getLocales function output in order to return the current
    008ee0
    locale that <tt>`centos-art.sh'</tt> script works with. 
    008ee0

    008ee0

    The current locale information, returned by

    008ee0
    cli_getCurrentLocale, is output from more specific to less
    008ee0
    specific. For example, if <samp>`en_GB'</samp> locale exists in
    008ee0
    cli_getLocales function output, the <samp>`en_GB'</samp> locale would
    008ee0
    take precedence before <samp>`en'</samp> locale.
    008ee0

    008ee0

    Locale precedence selection is quite important in order to define the

    008ee0
    locale type we use for message translations. For example, if
    008ee0
    <samp>`en_GB'</samp> is used, we are also saying that no common language
    008ee0
    specification is used for English language (i.e., <samp>`en'</samp>). Instead,
    008ee0
    we are using English non-common country-specific language
    008ee0
    specifications like <samp>`en_AU'</samp>, <samp>`en_BW'</samp>, <samp>`en_GB'</samp>,
    008ee0
    <samp>`en_US'</samp>, etc., for message translations.  
    008ee0

    008ee0

    Use cli_getCurrentLocale function to know what current locale

    008ee0
    information to use inside <tt>`centos-art.sh'</tt> script.
    008ee0

    008ee0

    The cli_getCurrentLocale function outputs current locale used

    008ee0
    by <tt>`centos-art.sh'</tt> script.
    008ee0

    008ee0
    008ee0
    008ee0
    <u>Function:</u> cli_getLangCodes [FILTER]
    008ee0
    008ee0
    008ee0

    Output language codes.

    008ee0

    008ee0

    cli_getLangCodes function outputs a list of language codes as

    008ee0
    defined in ISO639 standard. When FILTER is provided,
    008ee0
    cli_getLangCodes outputs language codes that match FILTER
    008ee0
    regular expression pattern.
    008ee0

    008ee0

    The cli_getLangCodes function outputs language codes supported

    008ee0
    by <tt>`centos-art.sh'</tt> script.
    008ee0

    008ee0
    008ee0
    008ee0
    <u>Function:</u> cli_getLangName [FILTER]
    008ee0
    008ee0
    008ee0

    Output language names.

    008ee0

    008ee0

    cli_getLangName function reads one language locale code in the

    008ee0
    format LL_CC and outputs the language related name as in ISO639. If
    008ee0
    filter is specified, cli_getLangName returns the language name
    008ee0
    that matches the locale code specified in FILTER, exactly.
    008ee0

    008ee0

    The cli_getLangName function outputs language names supported

    008ee0
    by <tt>`centos-art.sh'</tt> script.
    008ee0

    008ee0
    008ee0
    008ee0
    <u>Function:</u> cli_getLocales
    008ee0
    008ee0
    008ee0

    Output locale codes supported by <tt>`centos-art.sh'</tt> script.

    008ee0

    008ee0

    Occasionally, you use cli_getLocales function to add locale

    008ee0
    information in non-common country-specific language (<samp>`LL_CC'</samp>)
    008ee0
    format for those languages (e.g., <samp>`bn_IN'</samp>, <samp>`pt_BR'</samp>, etc.)
    008ee0
    which locale differences cannot be solved using common language
    008ee0
    specifications (<samp>`LL'</samp>) into one unique common locale specification
    008ee0
    (e.g., <samp>`bn'</samp>, <samp>`pt'</samp>, etc.).  
    008ee0

    008ee0
    008ee0
    008ee0
    <u>Function:</u> cli_getRepoName NAME TYPE
    008ee0
    008ee0
    008ee0

    Sanitate file names.

    008ee0

    008ee0

    Inside <tt>`centos-art.sh'</tt> script, specific functionalities rely both

    008ee0
    in cli_getRepoName and repository file system organization to
    008ee0
    achieve their goals.  Consider cli_getRepoName function as
    008ee0
    central place to manage file name convenctions for other functions
    008ee0
    inside <tt>`centos-art.sh'</tt> script.
    008ee0

    008ee0
    Important

    Important

    cli_getRepoName function doesn't verify file

    008ee0
    or directory existence, for that purpose use cli_checkFiles
    008ee0
    function instead.
    008ee0

    008ee0
    008ee0

    The NAME variable contains the file name or directory name you

    008ee0
    want to sanitate.
    008ee0

    008ee0

    The TYPE variable can be one of the following values:

    008ee0

    008ee0
    <samp>`d'</samp>
    008ee0
    <samp>`directory'</samp>
    008ee0

    Sanitate directory NAMEs.

    008ee0

    008ee0
    <samp>`f'</samp>
    008ee0
    <samp>`regular-file'</samp>
    008ee0

    Sanitate regular file NAMEs.

    008ee0

    008ee0
    008ee0
    008ee0

    Use cli_getRepoName function to sanitate file names and

    008ee0
    directory names before their utilization. 
    008ee0

    008ee0

    Use cli_getRepoName when you need to change file name

    008ee0
    convenctions inside <tt>`centos-art.sh'</tt> script. 
    008ee0

    008ee0

    When changing file name convenctions inside cli_getRepoName

    008ee0
    what you are really changing is the way functions interpret repository
    008ee0
    file system organization. In order to a complete file name convenction
    008ee0
    change, you also need to change file names and directory names inside
    008ee0
    repository file system organization, just as you did in
    008ee0
    cli_getRepoName function. 
    008ee0

    008ee0
    info

    Note

    See section trunk/Scripts/Bash/Functions/Path, for more

    008ee0
    information on how to rename files and directories massively inside
    008ee0
    repository file system organization.
    008ee0

    008ee0
    008ee0
    008ee0
    008ee0
    <u>Function:</u> cli_getTemporalFile NAME
    008ee0
    008ee0
    008ee0

    Output absolute path to temporal file NAME.

    008ee0

    008ee0

    cli_getTemporalFile uses <tt>`/tmp'</tt> directory as source

    008ee0
    location to store temporal files, the <tt>`centos-art.sh'</tt> script
    008ee0
    name, and a random identification string to let you run more than one
    008ee0
    <tt>`centos-art.sh'</tt> script simultaneously on the same user session.
    008ee0
    For example, due the following temporal file defintion:
    008ee0

    008ee0
    cli_getTemporalFile $FILE
    008ee0
    008ee0

    If FILE name is <tt>`instance.svg'</tt> and unique random string is

    008ee0
    <samp>`f16f7b51-ac12-4b7f-9e66-72df847f12de'</samp>, the final temporal file,
    008ee0
    built from previous temporal file definition, would be:
    008ee0

    008ee0
    /tmp/centos-art.sh-f16f7b51-ac12-4b7f-9e66-72df847f12de-instance.svg
    008ee0
    008ee0

    When you use cli_getTemporalFile function to create temporal

    008ee0
    files, be sure to remove temporal files created once you've ended up
    008ee0
    with them.  For example, consider the following construction:
    008ee0

    008ee0
    for FILE in $FILES;do
    008ee0
    008ee0
        # Initialize temporal instance of file.
    008ee0
        INSTANCE=$(cli_getTemporalFile $FILE)
    008ee0
    008ee0
        # Do something ... 
    008ee0
    008ee0
        # Remove temporal instance of file.
    008ee0
        if [[ -f $INSTANCE ]];then
    008ee0
            rm $INSTANCE
    008ee0
        fi
    008ee0
    008ee0
    done
    008ee0
    008ee0

    Use cli_getTemporalFile function whenever you need to create

    008ee0
    temporal files inside <tt>`centos-art.sh'</tt> script.
    008ee0

    008ee0
    008ee0
    008ee0
    <u>Function:</u> cli_getThemeName
    008ee0
    008ee0
    008ee0

    Output theme name.

    008ee0

    008ee0

    In order for cli_getThemeName function to extract theme name

    008ee0
    correctly, the ACTIONVAL variable must contain a directory path
    008ee0
    under <tt>`trunk/Identity/Themes/Motifs/'</tt> directory structure.
    008ee0
    Otherwise, cli_getThemeName returns an empty string.  
    008ee0

    008ee0
    008ee0
    008ee0
    <u>Function:</u> cli_printMessage MESSAGE [FORMAT]
    008ee0
    008ee0
    008ee0

    Give format to output messages.

    008ee0

    008ee0

    When FORMAT is not specified, cli_printMessage outputs

    008ee0
    information just as it was passed in MESSAGE variable.
    008ee0
    Otherwise, FORMAT can take one of the following values:
    008ee0

    008ee0
    008ee0
    <samp>`AsHeadingLine'</samp>
    008ee0

    To print heading messages.

    008ee0

    ----------------------------------------------------------------------
    008ee0
    $MESSAGE
    008ee0
    ----------------------------------------------------------------------
    008ee0
    008ee0
    008ee0
    <samp>`AsWarningLine'</samp>
    008ee0

    To print warning messages.

    008ee0

    ----------------------------------------------------------------------
    008ee0
    WARNING: $MESSAGE
    008ee0
    ----------------------------------------------------------------------
    008ee0
    008ee0
    008ee0
    <samp>`AsNoteLine'</samp>
    008ee0

    To print note messages.

    008ee0

    ----------------------------------------------------------------------
    008ee0
    NOTE: $MESSAGE
    008ee0
    ----------------------------------------------------------------------
    008ee0
    008ee0
    008ee0
    <samp>`AsUpdatingLine'</samp>
    008ee0

    To print <samp>`Updating'</samp> messages using two-columns format.

    008ee0

    Updating        $MESSAGE
    008ee0
    008ee0
    008ee0
    <samp>`AsRemovingLine'</samp>
    008ee0

    To print <samp>`Removing'</samp> messages using two-columns format.

    008ee0

    Removing        $MESSAGE
    008ee0
    008ee0
    008ee0
    <samp>`AsCheckingLine'</samp>
    008ee0

    To print <samp>`Checking'</samp> messages using two-columns format.

    008ee0

    Checking        $MESSAGE
    008ee0
    008ee0
    008ee0
    <samp>`AsCreatingLine'</samp>
    008ee0

    To print <samp>`Creating'</samp> messages using two-columns format.

    008ee0

    Creating        $MESSAGE
    008ee0
    008ee0
    008ee0
    <samp>`AsSavedAsLine'</samp>
    008ee0

    To print <samp>`Saved as'</samp> messages using two-columns format.

    008ee0

    Saved as        $MESSAGE
    008ee0
    008ee0
    008ee0
    <samp>`AsLinkToLine'</samp>
    008ee0

    To print <samp>`Linked to'</samp> messages using two-columns format.

    008ee0

    Linked to       $MESSAGE
    008ee0
    008ee0
    008ee0
    <samp>`AsMovedToLine'</samp>
    008ee0

    To print <samp>`Moved to'</samp> messages using two-columns format.

    008ee0

    Moved to        $MESSAGE
    008ee0
    008ee0
    008ee0
    <samp>`AsTranslationLine'</samp>
    008ee0

    To print <samp>`Translation'</samp> messages using two-columns format.

    008ee0

    Translation     $MESSAGE
    008ee0
    008ee0
    008ee0
    <samp>`AsConfigurationLine'</samp>
    008ee0

    To print <samp>`Configuration'</samp> messages using two-columns format.

    008ee0

    Configuration   $MESSAGE
    008ee0
    008ee0
    008ee0
    <samp>`AsResponseLine'</samp>
    008ee0

    To print response messages using one-column format.

    008ee0

    --> $MESSAGE
    008ee0
    008ee0
    008ee0
    <samp>`AsRequestLine'</samp>
    008ee0

    To print request messages using one-column format. Request messages

    008ee0
    supress the trailing newline character from final output.
    008ee0

    $MESSAGE
    008ee0
    008ee0
    008ee0
    <samp>`AsYesOrNoRequestLine'</samp>
    008ee0

    To print <samp>`yes or no'</samp> request messages using one-column format. If

    008ee0
    something different from <samp>`y'</samp> is answered (when using
    008ee0
    en_US.UTF-8 locale), script execution ends immediatly.  
    008ee0

    008ee0
    $MESSAGE [y/N]:
    008ee0
    008ee0

    When you are using <tt>`centos-art.sh'</tt> script in a locale different

    008ee0
    from en_US.UTF-8, confirmation answer may be different from
    008ee0
    <samp>`y'</samp>. For example, if you are using es_ES.UTF-8 locale, the
    008ee0
    confirmation question would look like:
    008ee0

    008ee0
    $MESSAGE [s/N]:
    008ee0
    008ee0

    and the confirmation answer would be <samp>`s'</samp>, as it is on Spanish

    008ee0
    <samp>`sí'</samp> word.
    008ee0

    008ee0

    Definition of which confirmation word to use is set on translation

    008ee0
    messages for your specific locale information. See section trunk/Scripts/Bash/Functions/Locale, for more information about locale-specific
    008ee0
    translation messages.
    008ee0

    008ee0
    008ee0
    <samp>`AsToKnowMoreLine'</samp>
    008ee0

    To standardize <samp>`to know more, run the following command:'</samp>

    008ee0
    messages. When the <samp>`AsToKnowMoreLine'</samp> option is used, the
    008ee0
    MESSAGE value should be set to "$(caller)". caller
    008ee0
    is a Bash builtin that returns the context of the current subroutine
    008ee0
    call. <samp>`AsToKnowMoreLine'</samp> option uses caller builtin
    008ee0
    output to build documentation entries dynamically.
    008ee0

    008ee0
    ----------------------------------------------------------------------
    008ee0
    To know more, run the following command:
    008ee0
    centos-art help --read='path/to/dir'
    008ee0
    ----------------------------------------------------------------------
    008ee0
    008ee0

    Use <samp>`AsToKnowMoreLine'</samp> option after errors and for intentional

    008ee0
    script termination. 
    008ee0

    008ee0
    008ee0
    <samp>`AsRegularLine'</samp>
    008ee0

    To standardize regular messages using one-column format.

    008ee0

    008ee0

    When MESSAGE contains a colon inside (e.g., <samp>`description:

    008ee0
    message'</samp>), the cli_printMessage function outputs MESSAGE
    008ee0
    using two-columns format. 
    008ee0

    008ee0
    008ee0
    008ee0
    Info

    Tip

    To improve two-columns format, change the following file:

    008ee0

    trunk/Scripts/Bash/Styles/output_forTwoColumns.awk
    008ee0
    008ee0
    008ee0

    Use cli_printMessage function whenever you need to output

    008ee0
    information from <tt>`centos-art.sh'</tt> script.
    008ee0

    008ee0
    008ee0
    008ee0
    008ee0

    3.40.3.3 Specific functions

    008ee0
    008ee0

    The following specific functions of <tt>`centos-art.sh'</tt> script, are

    008ee0
    available for you to use:
    008ee0

    008ee0
    008ee0
    3.41 trunk/Scripts/Bash/Functions/Help  
    008ee0
    008ee0
    3.42 trunk/Scripts/Bash/Functions/Html  
    008ee0
    008ee0
    3.43 trunk/Scripts/Bash/Functions/Locale  
    008ee0
    008ee0
    3.44 trunk/Scripts/Bash/Functions/Path  
    008ee0
    008ee0
    3.45 trunk/Scripts/Bash/Functions/Render  
    008ee0
    008ee0
    3.46 trunk/Scripts/Bash/Functions/Render/Config  
    008ee0
    008ee0
    3.47 trunk/Scripts/Bash/Functions/Shell  
    008ee0
    008ee0
    3.48 trunk/Scripts/Bash/Functions/Svg  
    008ee0
    008ee0
    3.49 trunk/Scripts/Bash/Functions/Verify  
    008ee0
    008ee0
    008ee0
    008ee0
    008ee0
    54264c

    3.40.4 See also

    4c79b5
    b8013f
    008ee0
    3.39 trunk/Scripts/Bash  
    008ee0
    008ee0
    3.50 trunk/Scripts/Bash/Locale  
    b8013f
    b8013f
    4c79b5
    4c79b5
    4c79b5
    008ee0
    [ < ]
    008ee0
    [ > ]
    4c79b5
       
    4c79b5
    [ << ]
    008ee0
    [ Up ]
    008ee0
    [ >> ]
    4c79b5
    4c79b5

    4c79b5
     <font size="-1">
    008ee0
      This document was generated on December, 2 2010 using texi2html 1.76.
    4c79b5
     </font>
    4c79b5
     
    4c79b5
    4c79b5

    4c79b5
    </body>
    4c79b5
    </html>