source: trunk/mailtouser.sh @ 323

Last change on this file since 323 was 177, checked in by pinsard, 12 years ago

consolidation of doc dev. (to be cont.)

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