source: trunk/mailtouser.sh @ 105

Last change on this file since 105 was 103, checked in by pinsard, 14 years ago

modif. of headers for manuals hyperlinks improvements

  • Property svn:keywords set to Id
File size: 9.3 KB
Line 
1#! /bin/sh
2#+
3#
4# .. _mailtouser.sh:
5#
6# =============
7# mailtouser.sh
8# =============
9#
10# -------------------------------------------------
11# convert email text in xml form following user.dtd
12# -------------------------------------------------
13#
14# SYNOPSIS
15# ========
16#
17# ::
18#
19#  $ mailtouser.sh -m mailbodyfile -x xmloutput
20#
21#
22#
23# DESCRIPTION
24# ===========
25#
26# convert email text in xml form following user.dtd
27#
28# SEE ALSO
29# ========
30#
31# :ref:`bibopa.sh`
32#
33# EXAMPLES
34# ========
35#
36# ::
37#
38#  $ ./mailtouser.sh -m data/mail2007-05-10T09:01:56Z -x ginette.xml
39#
40#
41# TODO
42# ====
43#
44# ++ gestion des comments
45#
46# ++ gestion de la signature
47#
48# EVOLUTIONS
49# ==========
50#
51# $Id$
52#
53# - fplod 2008-09-16T15:42:41Z aedon.locean-ipsl.upmc.fr (Darwin)
54#
55#  * comments in ReStructured Text
56#
57# - fplod 2007-06-06T09:27:55Z aedon.locean-ipsl.upmc.fr (Darwin)
58#
59#  * correction for Off-Line and PC Cluster
60#
61# - fplod 2007-05-18T08:31:48Z aedon.locean-ipsl.upmc.fr (Darwin)
62#
63#  * add off-line and agrif components
64#
65# - fplod 2007-05-09T15:03:15Z aedon.locean-ipsl.upmc.fr (Darwin)
66#
67#  * reprise + ajout middlename + ajout components_date
68#
69# - fplod 2007-04-25T09:15:38Z aedon.locean-ipsl.upmc.fr (Darwin)
70#
71#  * creation
72#
73#-
74system=$(uname)
75case "${system}" in
76   AIX|IRIX64)
77      echo " www : no specific posix checking"
78   ;;
79   *)
80      set -o posix
81   ;;
82esac
83unset system
84#
85command=$(basename ${0})
86log_date=$(date -u +"%Y%m%dT%H%M%SZ")
87log=/tmp/$(basename ${command} .sh).log.${log_date}
88#
89usage=" Usage : ${command} -m mailbodyfile -x xmloutput"
90#
91# test if xmllint is available
92tool=xmllint
93type ${tool} 1> /dev/null 2>&1
94status=${?}
95if [ ${status} -ne 0 ]
96then
97   echo " eee : ${tool} not found"
98   exit 1
99fi
100unset tool
101unset status
102#
103# check for user.dtd
104if [ ! -f user.dtd ]
105then
106   echo "eee : user.dtd not found"
107   exit 1
108fi
109#
110set +u
111while [ ! -z "${1}" ]
112do
113   case ${1} in
114      -m)
115         mailbodyfile=${2}
116         shift
117      ;;
118      -x)
119         xmloutput=${2}
120         shift
121      ;;
122      *)
123         # other choice
124         echo "eee : unknown option ${1}"
125         echo "${usage}"
126         exit 1
127      ;;
128   esac
129   # next flag
130   shift
131done
132unset usage
133#
134set -u
135#
136# check for mailbodyfile
137if [ ! -f ${mailbodyfile} ]
138then
139   echo "eee : ${mailbodyfile} not found"
140   exit 1
141fi
142#
143# check for xmloutput
144#++ err si exist
145#
146echo "<user>" > ${xmloutput}
147echo "<!-- mailbodyfile : ${mailbodyfile} " >> ${xmloutput}
148cat ${mailbodyfile} >> ${xmloutput}
149echo "-->" >> ${xmloutput}
150echo "<!-- ${log_date} -->" >> ${xmloutput}
151author_id=$(grep "author_id=" ${mailbodyfile} | awk -F"=" '{print $2}')
152surname=$(grep "personal_surname=" ${mailbodyfile} | awk -F"=" '{print $2}')
153firstname=$(grep "personal_firstname=" ${mailbodyfile} | awk -F"=" '{print $2}')
154middlename=$(grep "personal_middlename=" ${mailbodyfile} | awk -F"=" '{print $2}')
155if [ "${author_id}" = "template" ]
156then
157  author_id=$( echo ${surname} | \
158     tr "[:lower:]" "[:upper:]" | \
159     tr " " "_"  | \
160     recode -d -f UTF-8..flat)
161  author_id=${author_id}_$( echo ${firstname:0:1} | \
162     tr "[:upper:]" "[:lower:]" | \
163     recode -d -f UTF-8..flat)
164fi
165echo "<userid>${author_id}</userid>" >> ${xmloutput}
166#
167echo "<personname>" >> ${xmloutput}
168#
169echo "<surname>$surname</surname>" >> ${xmloutput}
170#
171echo "<firstname>$firstname</firstname>" >> ${xmloutput}
172echo "<othername role='mi'>$middlename</othername>" >> ${xmloutput}
173#
174echo "</personname>" >> ${xmloutput}
175#
176email=$(grep "personal_email=" ${mailbodyfile} | awk -F"=" '{print $2}')
177echo "<email>$email</email>" >> ${xmloutput}
178#
179elements=components
180element=component
181#++ récupérer les users/user[child::userid='template']/components/component/name
182unset jlist
183unset jlist_name
184j=1
185jlist[${j}]="OPA"
186jlist_name[${j}]="OPA"
187j=$((${j} + 1))
188jlist[${j}]="LIM"
189jlist_name[${j}]="LIM"
190j=$((${j} + 1))
191jlist[${j}]="TOP"
192jlist_name[${j}]="TOP"
193j=$((${j} + 1))
194jlist[${j}]="TAM"
195jlist_name[${j}]="TAM"
196j=$((${j} + 1))
197jlist[${j}]="SAXO"
198jlist_name[${j}]="SAXO"
199j=$((${j} + 1))
200jlist[${j}]="offline"
201jlist_name[${j}]="Off-line"
202j=$((${j} + 1))
203jlist[${j}]="AGRIF"
204jlist_name[${j}]="AGRIF"
205echo "<${elements}>" >> ${xmloutput}
206components_date=$(grep "components_date=" ${mailbodyfile} | awk -F"=" '{print $2}')
207echo "<components_date>$components_date</components_date>" >> ${xmloutput}
208## find the element
209j=1
210jlistsize=${#jlist[@]}
211while [ ${j} -le ${jlistsize} ]
212do
213   jlist_min=$(echo ${jlist[j]} | tr [:upper:] [:lower:])
214   # recherche de ${jlist[j]}
215   grep -q "${element}_${jlist_min}" ${mailbodyfile}
216   ok=${?}
217   if [ ${ok} -eq 0 ]
218   then
219      echo "<${element} code='${jlist_min}'>" >> ${xmloutput}
220      echo "<name>${jlist_name[j]}</name>" >> ${xmloutput}
221      echo "<value>yes</value>" >> ${xmloutput}
222      echo "</${element}>"  >> ${xmloutput}
223   else
224      echo "<${element} code='${jlist_min}'>" >> ${xmloutput}
225      echo "<name>${jlist_name[j]}</name>" >> ${xmloutput}
226      echo "<value>no</value>" >> ${xmloutput}
227      echo "</${element}>"  >> ${xmloutput}
228   fi
229   j=$(( $j + 1 ))
230done
231echo "</${elements}>" >> ${xmloutput}
232#
233element=platform
234elements=platforms
235#++ récupérer les users/user[child::userid='template']/platforms/platform/name
236unset jlist
237unset jlist_name
238j=1
239jlist[${j}]="CRAY"
240jlist_name[${j}]="CRAY"
241j=$((${j} + 1))
242jlist[${j}]="IBM"
243jlist_name[${j}]="IBM"
244j=$((${j} + 1))
245jlist[${j}]="FUJITSU"
246jlist_name[${j}]="FUJITSU"
247j=$((${j} + 1))
248jlist[${j}]="MAC"
249jlist_name[${j}]="MAC"
250j=$((${j} + 1))
251jlist[${j}]="NEC"
252jlist_name[${j}]="NEC"
253j=$((${j} + 1))
254jlist[${j}]="SGI"
255jlist_name[${j}]="SGI"
256j=$((${j} + 1))
257jlist[${j}]="SUN"
258jlist_name[${j}]="SUN"
259j=$((${j} + 1))
260jlist[${j}]='pccluster'
261jlist_name[${j}]="PC Cluster"
262echo "<${elements}>" >> ${xmloutput}
263## find the element
264j=1
265jlistsize=${#jlist[@]}
266while [ ${j} -le ${jlistsize} ]
267do
268   # recherche de ${jlist[j]}
269   jlist_min=$(echo ${jlist[j]} | tr [:upper:] [:lower:])
270   grep -q "${element}_${jlist_min}" ${mailbodyfile}
271   ok=${?}
272   if [ ${ok} -eq 0 ]
273   then
274      echo "<${element} code='${jlist_min}'>" >> ${xmloutput}
275      echo "<name>${jlist_name[j]}</name>" >> ${xmloutput}
276      echo "<value>yes</value>" >> ${xmloutput}
277      echo "</${element}>"  >> ${xmloutput}
278   else
279      echo "<${element} code='${jlist_min}'>" >> ${xmloutput}
280      echo "<name>${jlist_name[j]}</name>" >> ${xmloutput}
281      echo "<value>no</value>" >> ${xmloutput}
282      echo "</${element}>"  >> ${xmloutput}
283   fi
284   j=$(( $j + 1 ))
285done
286#
287# gestion des "others"
288j=1
289jlistsize=${#jlist[@]}
290grep_cmd="grep ${element}_zzz_other ${mailbodyfile} "
291while [ ${j} -le ${jlistsize} ]
292do
293   grep_cmd="${grep_cmd} | grep -v ${element}=${jlist[j]}" #++ -v inutile
294   j=$(( $j + 1 ))
295done
296other=$(eval ${grep_cmd} | awk -F "=" '{print$2}')
297echo "<${element} code='zzz_other'>" >> ${xmloutput}
298echo "<name>Other</name>" >> ${xmloutput}
299echo "<value>${other}</value>" >> ${xmloutput}
300echo "</${element}>"  >> ${xmloutput}
301echo "</${elements}>" >> ${xmloutput}
302#
303processors=$(grep "processors=" ${mailbodyfile} | awk -F"=" '{print $2}')
304echo "<processors>$processors</processors>" >> ${xmloutput}
305#
306element=compiler
307elements=compilers
308unset jlist
309unset jlist_name
310j=1
311jlist[${j}]="g95"
312jlist_name[${j}]="g95"
313j=$((${j} + 1))
314jlist[${j}]="ifort"
315jlist_name[${j}]="ifort"
316j=$((${j} + 1))
317jlist[${j}]="pgf"
318jlist_name[${j}]="pgf"
319j=$((${j} + 1))
320jlist[${j}]="sxf90"
321jlist_name[${j}]="sxf90"
322j=$((${j} + 1))
323jlist[${j}]="xlf"
324jlist_name[${j}]="xlf"
325echo "<${elements}>" >> ${xmloutput}
326## find the element
327j=1
328jlistsize=${#jlist[@]}
329while [ ${j} -le ${jlistsize} ]
330do
331   # recherche de ${jlist[j]}
332   jlist_min=$(echo ${jlist[j]} | tr [:upper:] [:lower:])
333   grep -q "${element}_${jlist_min}" ${mailbodyfile}
334   ok=${?}
335   if [ ${ok} -eq 0 ]
336   then
337      echo "<${element} code='${jlist_min}'>" >> ${xmloutput}
338      echo "<name>${jlist_name[j]}</name>" >> ${xmloutput}
339      echo "<value>yes</value>" >> ${xmloutput}
340      echo "</${element}>"  >> ${xmloutput}
341   else
342      echo "<${element} code='${jlist_min}'>" >> ${xmloutput}
343      echo "<name>${jlist_name[j]}</name>" >> ${xmloutput}
344      echo "<value>no</value>" >> ${xmloutput}
345      echo "</${element}>"  >> ${xmloutput}
346   fi
347   j=$(( $j + 1 ))
348done
349#
350# gestion des "others"
351j=1
352jlistsize=${#jlist[@]}
353grep_cmd="grep ${element}_zzz_other= ${mailbodyfile} "
354while [ ${j} -le ${jlistsize} ]
355do
356   grep_cmd="${grep_cmd} | grep -v ${element}=${jlist[j]}" #++ -v inutile
357   j=$(( $j + 1 ))
358done
359other=$(eval ${grep_cmd} | awk -F "=" '{print$2}')
360echo "<${element} code='zzz_other'>" >> ${xmloutput}
361echo "<name>Other</name>" >> ${xmloutput}
362echo "<value>${other}</value>" >> ${xmloutput}
363echo "</${element}>"  >> ${xmloutput}
364echo "</${elements}>" >> ${xmloutput}
365#
366echo "</user>" >> ${xmloutput}
367#
368xmloutputfull=/tmp/${xmloutput} # ++
369echo '<?xml version="1.0" encoding="iso-8859-1"?>' > ${xmloutputfull}
370echo '<!DOCTYPE users SYSTEM "user.dtd">' >> ${xmloutputfull}
371echo '<users>' >> ${xmloutputfull}
372echo '<date>bidon</date>' >> ${xmloutputfull}
373cat ${xmloutput} >> ${xmloutputfull}
374echo '</users>' >> ${xmloutputfull}
375#
376# ++ parce que je ne sais pas dire où est la dtd dans la commande xmllint
377cp user.dtd /tmp/
378xmllint --noout --valid ${xmloutputfull} 1>> ${log} 2>> ${log}
379status=${?}
380if [ ${status} -ne 0 ]
381then
382   echo " eee : pb DTD conformance of ${xmloutputfull}"
383   echo " eee : see ${log}"
384   exit 1
385else
386   echo " iii : you can include ${xmloutput} in user.xml" #++ filename path
387   echo " iii : modify date in user.xml" #++ filename path
388fi
389#
390exit 0
Note: See TracBrowser for help on using the repository browser.