Blame Identity/Manual/repository-latex/centos-art.sh-latex/Concepts/scripts.tex

39a1ed
% Part   : Concepts
39a1ed
% Chapter: Scripts
39a1ed
% ------------------------------------------------------------
39a1ed
% $Id: scripts.tex 6207 2010-08-05 13:11:13Z al $
39a1ed
% ------------------------------------------------------------
39a1ed
39a1ed
\begin{description}
39a1ed
\item[framework:] trunk/Scripts/
39a1ed
\end{description}
39a1ed
39a1ed
\noindent Inside CentOS Artwork Repository, scripts are organized in
39a1ed
three groups: ``invocation scripts'', ``configuration scripts'' and
39a1ed
``function scripts''. Scripts are mainly used to help you automate and
39a1ed
standardize tasks. A graphical representation of how scripts are
39a1ed
organized inside CentOS Artwork Repository is illustrated in
39a1ed
\autoref{fig:Concepts:Scripts}.
39a1ed
39a1ed
\begin{figure}[!hbp]
39a1ed
\centering
39a1ed
\includegraphics[width=0.8\textwidth]{%
39a1ed
   ../Identity/Models/Img/en/Scripts/initFunctions.pdf}
39a1ed
\caption{The scripts organization model.%
39a1ed
   \label{fig:Concepts:Scripts}}
39a1ed
\end{figure}
39a1ed
39a1ed
\section{Invocation Scripts}
39a1ed
\hypertarget{sec:Concepts:Scripts:Invocation}{}
39a1ed
\label{sec:Concepts:Scripts:Invocation}
39a1ed
39a1ed
Invocation scripts are identified by the name \texttt{render.sh}. You
39a1ed
may find invocation scripts inside \texttt{trunk/Translations/} and
39a1ed
\texttt{trunk/Identity/} structures.  Invocation scripts' main purpose
39a1ed
is calling the appropriate configuration script.
39a1ed
39a1ed
\section{Configuration Scripts}
39a1ed
\hypertarget{sec:Concepts:Scripts:Configuration}{}
39a1ed
\label{sec:Concepts:Scripts:Configuration}
39a1ed
39a1ed
\begin{description}
39a1ed
\item[framework:] trunk/Scripts/Config/
39a1ed
\end{description}
39a1ed
39a1ed
\noindent Configuration scripts are identified by the name
39a1ed
\texttt{render.conf.sh}. In the script organization model
39a1ed
(\autoref{fig:Concepts:Scripts}), configuration scripts are the first
39a1ed
scripts executed by you after running the invocation script
39a1ed
(\texttt{render.sh}).  Generally, configuration scripts are short
39a1ed
files that initialize functions, set variable definitions, and call
39a1ed
the appropriate function to start rendering.
39a1ed
39a1ed
\subsection{Initialize Functions}
39a1ed
39a1ed
Function initialization is the first action you do inside
39a1ed
configuration scripts.  By default, functions are initialized using
39a1ed
the \texttt{initFunctions.sh} script, as illustrated in
39a1ed
\autoref{fig:Concepts:Scripts:Configuration:initFunctions}.  The
39a1ed
\texttt{initFunctions.sh} script looks for functions definitions in
39a1ed
files that match the expansion \texttt{*.sh} inside the
39a1ed
\texttt{trunk/Scripts/Functions/} path, and exports them to the
39a1ed
current shell environment, that created when you ran the invocation
39a1ed
script.
39a1ed
39a1ed
\begin{figure}[!hbp]
39a1ed
\hrulefill
39a1ed
\begin{verbatim}
39a1ed
# Initialize functions.
39a1ed
. /home/centos/artwork/trunk/Scripts/initFunctions.sh
39a1ed
\end{verbatim}
39a1ed
\hrulefill
39a1ed
\caption{Function initialization inside configuration scripts.%
39a1ed
   \label{fig:Concepts:Scripts:Configuration:initFunctions}}
39a1ed
\end{figure}
39a1ed
39a1ed
Once functions are initialized, they are ready to be used by you, in
39a1ed
any point after its initialization.  This initialization arms you with
39a1ed
a customizable set of functionalities that can be used on
39a1ed
configuration scripts and reused inside functions themselves.
39a1ed
39a1ed
\subsection{Define Artwork Component}
39a1ed
39a1ed
The \texttt{ARTCOMP} variable defines the artwork component you want
39a1ed
to render.  The \texttt{ARTCOMP}'s value defines the specific artwork
39a1ed
component's matching list and Themes' translation path.  The
39a1ed
\texttt{ARTCOMP}'s value is built using the translation path structure
39a1ed
as reference.  For example, if you want to render Anaconda progress
39a1ed
files, you need to know that artwork component's translation path
39a1ed
which is:\\
39a1ed
\\
39a1ed
\fbox{trunk/Translations/Identity/Themes/Distro/Anaconda/Progress}\\
39a1ed
\\
39a1ed
and then, go to its \texttt{render.conf.sh} file to define
39a1ed
\texttt{ARTCOMP} as the following:\\
39a1ed
\\
39a1ed
\fbox{ARTCOMP='Distro/Anaconda/Progress'}\\
39a1ed
\\
39a1ed
The \texttt{ARTCOMP}'s value is processed by \texttt{getMatchingList}
39a1ed
function to determine the specific artwork component's
39a1ed
translation-design matching list. The matching list function is
39a1ed
described in \autoref{sec:Concepts:Scripts:Function:getMatchingList}.
39a1ed
39a1ed
\subsection{Define Filtering Pattern}
39a1ed
39a1ed
The \texttt{REGEX} variable defines a regular expression as filtering
39a1ed
pattern.  If the filtering pattern is specified, the rendering process
39a1ed
is limited to the amount of files matching the filtering pattern.  By
39a1ed
default, this value is set to receive the shell's first argument
39a1ed
(\texttt{\$1}).  This let you pass the filtering pattern on the
39a1ed
command line, at rendering time.  If you need a fixed value for the
39a1ed
filtering pattern, you can change the \texttt{REGEX}'s value on your
39a1ed
working copy to whatever you need, but please do no commit that.
39a1ed
39a1ed
\begin{figure}[!hbp]
39a1ed
\hrulefill
39a1ed
\begin{verbatim}
39a1ed
# Define filtering pattern. This is a regular expression 
39a1ed
# matching the translation path.
39a1ed
REGEX="$1"
39a1ed
\end{verbatim}
39a1ed
\hrulefill
39a1ed
\caption{Define filtering pattern inside configuration scripts.%
39a1ed
   \label{fig:Concepts:Scripts:Configuration:REGEX}}
39a1ed
\end{figure}
39a1ed
39a1ed
\subsection{Define Post-rendering Actions}
39a1ed
\hypertarget{sec:Concepts:Scripts:Configuration:ACTIONS}{}
39a1ed
\label{sec:Concepts:Scripts:Configuration:ACTIONS}
39a1ed
39a1ed
Post-rendering actions are specific functionalities applied to the
39a1ed
final files produced by base rendering functions like
39a1ed
\texttt{renderImage} and \texttt{renderText}.  Post-rendering actions
39a1ed
are defined by the \texttt{ACTIONS} array variable.  By default, the
39a1ed
\texttt{ACTIONS}'s value is set to empty (\texttt{ACTIONS[0]=''})
39a1ed
which provokes no post-rendering action to be applied. A different
39a1ed
configuration is illustrated on
39a1ed
\autoref{fig:Concepts:Scripts:Configuration:ACTIONS}. 
39a1ed
39a1ed
When rendering images, using \texttt{renderImage}, the only result you
39a1ed
get is in PNG format. This is enough most of the time. But in some
39a1ed
other situations, you need to produce the same image in many different
39a1ed
formats (i.e. xpm, pdf, tiff, xbm, etc.). These tasks are very
39a1ed
specific and are not included inside \texttt{renderImage} function.
39a1ed
Instead, the \texttt{renderFormats} function was created and used as
39a1ed
post-rendering action in these situations.
39a1ed
39a1ed
When rendering texts, using \texttt{renderText}, the only result you
39a1ed
get is in plain text format. Again, this is enough most of the time.
39a1ed
But in some other situations, you need to modify the final result to
39a1ed
provide some standardizations like: maximum line width, indentation of
39a1ed
first line different from second, one space between words, two after
39a1ed
sentences, etc. These tasks are very specific and are not included
39a1ed
inside \texttt{renderText} function. Instead, the \texttt{formatText}
39a1ed
function was created and used as post-rendering action in these
39a1ed
situations.
39a1ed
39a1ed
\begin{figure}[!hbp]
39a1ed
\hrulefill
39a1ed
\begin{verbatim}
39a1ed
# Define post-rendering actions. An empty value means that no
39a1ed
# post-rendering action is applied.
39a1ed
ACTIONS[0]='renderFormats: tif xpm pdf ppm'
39a1ed
ACTIONS[1]='groupByFormat: png tif xpm pdf ppm'
39a1ed
\end{verbatim}
39a1ed
\hrulefill
39a1ed
\caption[Define post-rendering actions.]{Define post-rendering\
39a1ed
actions. In this figure, post-rendering actions are used to produce\
39a1ed
tif, xpm, pdf, ppm, image formats (from the base PNG image format)\
39a1ed
and group them (PNG format included) inside directories. This is, all\
39a1ed
png files are stored inside a png directory, all xpm files are\
39a1ed
stored inside a xpm directory, and so on.%
39a1ed
   \label{fig:Concepts:Scripts:Configuration:ACTIONS}}
39a1ed
\end{figure}
39a1ed
39a1ed
\subsection{Start Rendering}
39a1ed
39a1ed
The start rendering section defines the base action to do when the
39a1ed
current configuration script is called. In this section what you do is
39a1ed
calling one of the following functions: \texttt{renderImage}
39a1ed
(\autoref{sec:Concepts:Scripts:Function:renderImage}), or
39a1ed
\texttt{renderText}
39a1ed
(\autoref{sec:Concepts:Scripts:Function:renderText}).
39a1ed
39a1ed
\section{Function Scripts}
39a1ed
\hypertarget{sec:Concepts:Scripts:Function}{}
39a1ed
\label{sec:Concepts:Scripts:Function}
39a1ed
39a1ed
\begin{description}
39a1ed
\item[framework:] trunk/Scripts/Functions/
39a1ed
\end{description}
39a1ed
39a1ed
\noindent Function scripts are, in fact, shell functions.  A shell
39a1ed
function stores a series of commands for later execution.  When the
39a1ed
name of a shell function is used as a simple command name, the list of
39a1ed
commands associated with that function name is executed.  Functions
39a1ed
are executed in the context of the current shell; no new process is
39a1ed
created to interpret them (contrast this with the execution  of a
39a1ed
shell script).
39a1ed
39a1ed
\subsection{renderImage}
39a1ed
\hypertarget{sec:Concepts:Scripts:Function:renderImage}{}
39a1ed
\label{sec:Concepts:Scripts:Function:renderImage}
39a1ed
39a1ed
Inside CentOS Artwork Repository, the \texttt{renderImage} function is
39a1ed
the heart of image production. The \texttt{renderImage} function takes
39a1ed
translation files and apply them to design templates, as specified in
39a1ed
the artwork componet's matching list that is been rendered. The final
39a1ed
result are PNG images based on design templates and translation files.
39a1ed
39a1ed
Additionally, the \texttt{renderImage} function accepts the following
39a1ed
post-rendering actions:
39a1ed
39a1ed
\begin{description}
39a1ed
39a1ed
\item[renderFormats:] The \texttt{renderFormats} function let you
39a1ed
produce different image formats from the base PNG image format.  The
39a1ed
amount of image formats you can produce with \texttt{renderFormats} is
39a1ed
limited to the amount of image formats that ImageMagick command line
39a1ed
image manipulation tool can support.
39a1ed
39a1ed
\item[groupByFormat:] The \texttt{renderByFormat} function let you
39a1ed
group similar image formats inside common directories.
39a1ed
39a1ed
\item[renderGrub:] The \texttt{renderGrub} function let you produce 14
39a1ed
colors images from the base PNG image format. The \texttt{renderGrub}
39a1ed
function is used to automate GRUB artwork component image production.
39a1ed
For this function to work, it is required to define the
39a1ed
\texttt{grub.ppm} palette first.
39a1ed
39a1ed
\item[renderSyslinux:] The \texttt{renderSyslinux} function let you
39a1ed
produce LSS16 images from the base PNG image format. The
39a1ed
\texttt{renderSyslinux} function is used to automate Anaconda prompt
39a1ed
artwork component image production.  For this function to work, it is
39a1ed
required to define the \texttt{syslinux.ppm} and \texttt{syslinux.hex}
39a1ed
palettes first.
39a1ed
39a1ed
\item[renderBrands:] The \texttt{renderBrands} function let you
39a1ed
produce different image formats from the base PNG image format.
39a1ed
Basically, it is does the same of \texttt{renderFormats}, plus two
39a1ed
colors grayscale, and emboss effect convertions that are not included
39a1ed
inside \texttt{renderFormats}.
39a1ed
39a1ed
\end{description}
39a1ed
39a1ed
\subsection{renderText}
39a1ed
\hypertarget{sec:Concepts:Scripts:Function:renderText}{}
39a1ed
\label{sec:Concepts:Scripts:Function:renderText}
39a1ed
39a1ed
The \texttt{renderText} function produce plain text files from text
39a1ed
plain design tempaltes and translation files. The \texttt{renderText}
39a1ed
standardize the text rendering process inside CentOS Artwork
39a1ed
Repository. Additionally, the \texttt{renderText} function accepts the
39a1ed
following post-rendering actions:
39a1ed
39a1ed
\begin{description}
39a1ed
39a1ed
\item[formatText:] The \texttt{formatText} function, let you format
39a1ed
plain text files. This function uses the GNU's \texttt{fmt} tool as
39a1ed
base to do all modifications.
39a1ed
39a1ed
\end{description}
39a1ed
39a1ed
\subsection{getMatchingList}
39a1ed
\hypertarget{sec:Concepts:Scripts:Function:getMatchingList}{}
39a1ed
\label{sec:Concepts:Scripts:Function:getMatchingList}
39a1ed
39a1ed
The matching list specifies the relation between design templates and
39a1ed
translation files that artwork components have. The
39a1ed
\texttt{renderImage} and \texttt{renderText} functions require this
39a1ed
information in order to work properly. 
39a1ed
39a1ed
Initially, the matching list was defined explicitly and independently
39a1ed
inside each artwork component's configuration script. Later, as many
39a1ed
of these components had just the same configuration stuff, the code
39a1ed
was reduced and unified inside \texttt{getMatchingList} function.
39a1ed
Inside \texttt{getMatchingList}, there is a case selection statement
39a1ed
where specific matching lists cases are defined, and one default
39a1ed
behaivour that match in thoses cases where none else does.  
39a1ed
39a1ed
The matching list code reduction changed the way you customize artwork
39a1ed
component's matching list.  From now on, you look inside configuration
39a1ed
files to be sure that \texttt{ARTCOMP} variable refers to the
39a1ed
appropriate artwork component, and inside \texttt{getMatchingList}
39a1ed
function to define its matching list.  For example, when rendering
39a1ed
Anaconda progress, its matching list specifies which translation files
39a1ed
apply which design templates. So, to change the matching list of this
39a1ed
artwork component, you need to edit the function
39a1ed
\texttt{getMatchingList} and set the appropriate relation there, in
39a1ed
the Anaconda progress matching list specification.
39a1ed
39a1ed
When setting artwork components' matching list, you can use any of the
39a1ed
following configuration available:
39a1ed
39a1ed
\begin{description}
39a1ed
39a1ed
\item[Configuration 1:] Specific translation files are applied to
39a1ed
specific design templates. In this configuration you have detailed
39a1ed
control over which translation files are applied to which design
39a1ed
template.
39a1ed
39a1ed
\begin{verbatim}
39a1ed
MATCHINGLIST="\
39a1ed
design-template-A.svg: translation-file-1.sed translation-file-2.sed
39a1ed
design-template-B.svg: translation-file-3.sed translation-file-4.sed
39a1ed
"
39a1ed
\end{verbatim}
39a1ed
39a1ed
Another way to write the previous example is: 
39a1ed
39a1ed
\begin{verbatim}
39a1ed
MATCHINGLIST="\
39a1ed
design-template-A.svg:\
39a1ed
   translation-file-1.sed\
39a1ed
   translation-file-2.sed
39a1ed
design-template-B.svg:\
39a1ed
   translation-file-3.sed\
39a1ed
   translation-file-4.sed
39a1ed
"
39a1ed
\end{verbatim}
39a1ed
39a1ed
In the above examples translation files 1 and 2 apply
39a1ed
design-template-A.svg. Likewise, translation files 3 and 4 apply
39a1ed
design-template-B.svg. That was a simple case, but what about if you
39a1ed
have hundreds of translation files to apply to specific design
39a1ed
templates? Lets say, translation files from 1 to 49 apply
39a1ed
design-template-A.svg and translation files from 50 to 99 apply
39a1ed
design-template-B.svg.  It would be tiresome to write down the name of
39a1ed
every single file in the above configuration. In these situations you
39a1ed
can ``generate'' the translation files as shown below: 
39a1ed
39a1ed
\begin{verbatim}
39a1ed
MATCHINGLIST="\
39a1ed
design-template-A.svg:\
39a1ed
   $(for NUMBER in $(sed 1 49);do
39a1ed
      echo -n translation-file-${NUMBER}.sed ' '
39a1ed
     done)
39a1ed
design-template-B.svg:\
39a1ed
   $(for NUMBER in $(sed 50 99);do
39a1ed
      echo -n translation-file-${NUMBER}.sed ' '
39a1ed
     done)
39a1ed
"
39a1ed
\end{verbatim}
39a1ed
39a1ed
Another interesting case is when you need to apply hundreds of
39a1ed
translation files to hundreds of design templates, in a file structure
39a1ed
where they both share a common bond path.  That is the
39a1ed
\texttt{Identity/Brands} artwork component case.  Writing down such a
39a1ed
matching list consumes lot of time.  So you can ``generate'' the
39a1ed
entire matching list like the following:
39a1ed
39a1ed
\begin{verbatim}
39a1ed
MATCHINGLIST="\
39a1ed
$(for TEMPLATE in $(find $(getPath 'trunk/Identity/Brands')/tpl \
39a1ed
   -name '*.svg' | sed -r 's!.*/Brands/Tpl/(.*)$!\1!' | sort );do
39a1ed
39a1ed
   TRANSLATION=$(find $(getPath \
39a1ed
      'trunk/Translations/Identity/Brands')/$(echo $TEMPLATE \
39a1ed
      | sed 's!\.svg!!') -name '*.sed' \
39a1ed
      | sed -r 's!^.*/Brands/(.*)$!\1!' \
39a1ed
      | sort | tr '\n' ' ')
39a1ed
39a1ed
   echo $TEMPLATE: $TRANSLATION
39a1ed
   done)
39a1ed
"
39a1ed
\end{verbatim}
39a1ed
39a1ed
\item[Configuration 2:] All translation files are applied to a single
39a1ed
design template.  In this configuration all artwork component's
39a1ed
translation files are applied to one design template
39a1ed
(design-template-A.svg for the matter of this case).
39a1ed
39a1ed
\begin{verbatim}
39a1ed
MATCHINGLIST="design-template-A.svg"
39a1ed
\end{verbatim}
39a1ed
39a1ed
\item[Configuration 3:] Translation files are applied to design
39a1ed
templates that share a common name. In this configuration translation
39a1ed
files are applied to design templates taking the name part, without
39a1ed
extension, as reference.  This means that, if you have a translation
39a1ed
file named \texttt{File-1.sed} you need to have a \texttt{File-1.svg}
39a1ed
inside design templates. This way, \texttt{File-1.sed} can be applied
39a1ed
to \texttt{File-1.svg} and, as result, produce the \texttt{File-1.png}
39a1ed
file.  This is the default matching list behaivour.
39a1ed
39a1ed
\begin{verbatim}
39a1ed
MATCHINGLIST=""
39a1ed
\end{verbatim}
39a1ed
39a1ed
\end{description}
39a1ed
39a1ed
\subsection{getPath}
39a1ed
39a1ed
The \texttt{getPath} function creates the artwork component's absolute
39a1ed
path. Before output the absolute path, \texttt{getPath} removes any
39a1ed
``strange'' character from the final path. For \texttt{getPath} to
39a1ed
work, the relative path to the artwork component should be provided
39a1ed
from \texttt{trunk/}'s directory level on.