source: trunk/mailtouser.sh @ 87

Last change on this file since 87 was 80, checked in by pinsard, 16 years ago

add journals and bug fixes in flat to docbook conversion tool

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