source: modipsl/trunk/util/script_diff_model @ 2296

Last change on this file since 2296 was 1623, checked in by mmaipsl, 12 years ago

Work only in modipsl/tmp. Try something on vargas, but not finished yet.

  • Property svn:executable set to *
  • Property svn:keywords set to Date,Author,Revision
File size: 13.0 KB
Line 
1#!/bin/ksh
2
3#**************************************************************
4# Author: Martial Mancip
5# Contact: Martial.Mancip__at__ipsl.jussieu.fr
6# $Revision::                                          $ Revision of last commit
7# $Author::                                            $ Author of last commit
8# $Date::                                              $ Date of last commit
9# IPSL (2006)
10#  This software is governed by the CeCILL licence see libIGCM/libIGCM_CeCILL.LIC
11#
12#**************************************************************
13
14# Documentation :
15# This script may be used to create a tree of last configuration downloaded by modipsl/util/model command.
16#
17# It checks the control version used for each components of the configuration and saves the diff
18# between the revision downloaded (or updated) and the modifications of the developper.
19# It saves those diff in the component directory in the copy tree.
20# It saves also new source files. See SUFFIXES definition below for the list of extension to detect source files.
21#
22# It also gives a Last_log file in the root of the save tree with all informations needed to download the same
23# configuration precisely. It has the list of new and modified files and give the date (in an non human format)
24# of each modifications.
25#
26# It may be used in modipsl directory :
27# modipsl_path> util/script_diff_model
28#
29# After this use, you will have a modipsl_path/modipsl_save_diff_$( date +%F_%H%M%S ) tree that
30# you can tar and save with the executable you have build with this modified configuration.
31#
32# Note :
33#  Be aware to modify AA_make files in your model source code tree (and not only Makefiles) if you use modipsl
34#  ins_make script and portable Makefile build. In this case, Makefiles won't be versionning and modifications
35#  won't be saves.
36#
37# You can use ___ script_recup_model ___ script to download the same configuration and make change
38# with new files and modified source files.
39
40
41case $( hostname -s ) in
42    vargas*)
43#       alias ls=/opt/freeware/bin/ls
44#       alias wc=/opt/freeware/bin/wc
45#       alias tail=/opt/freeware/bin/tail
46#       alias tee=/opt/freeware/bin/tee
47#       module load svn
48        return 1
49        ;;
50esac
51
52# env must know MODIPSL path variable !
53MODIPSL=${MODIPSL:=$(pwd)}
54tmpMODIPSL=${MODIPSL}/tmp
55
56SUBMIT_DIR=$1
57
58DEBUG_mode=false
59
60function printDebugArray {
61    if ( ${DEBUG_mode} ); then
62        typeset nb_line i
63        eval nb_line=\${#$1[@]}
64        eval echo "$1 : " ${nb_line}
65        (( i = 0 ))
66        while [ $i -lt $nb_line ] ; do
67            eval echo \${$1[$i]}
68            (( i = i + 1 ))
69        done
70    fi
71}
72
73typeset tag thedate save_diff_file pathComp pathexist i filecomp filedate file SpathComp SUFFIXES NbNewFiles NbModifFiles Maxfiledate
74
75# Analyse log file: get last model command
76. ${MODIPSL}/util/script_log_analyse
77
78# Code source suffixe for new file detection
79SUFFIXES='\(f90\|F90\|f\|F\|h\|h90\|hh\|c\|cc\|inc\|fcm\|path\|cfg\|card\|driver\|def\|def_.*\|txt\|xml\|ksh\|tex\)'
80
81MODIPSL_SAVE_NAME=modipsl_save_diff_$( date +%F_%H%M%S )
82echo "SAVE directory in " ${MODIPSL_SAVE_NAME}
83MODIPSL_SAVE=${tmpMODIPSL}/${MODIPSL_SAVE_NAME}
84printDebugArray MODIPSL_SAVE
85
86set +A ListRep -- $( find ${MODIPSL} -mindepth 1 -type d \
87    \( -not -path '*.svn*' -a -not -path '*CVS*' -a -not -path "${MODIPSL}" \
88    -a -not -path "${MODIPSL}/bin" -a -not -path "${MODIPSL}/lib" -a -not -path "${MODIPSL}/util" \
89    -a -not -path "${tmpMODIPSL}*" \) \
90    -exec bash -c " echo "'{}'" | sed -e 's&"${MODIPSL}"/&&' | tee -a >( sed -e 's&\(.*\)&"${MODIPSL_SAVE}"/\1&' | xargs mkdir -p >> out_mkdir 2>&1 ) " \; )
91rm out_mkdir
92#echo ${ListRep[0]} | tee $(ls > toto) $(ls -la > tata)
93#mkdir -Rp ${MODIPSL_SAVE}/
94printDebugArray ListRep
95
96
97echo "Last Model in log : " ${ListModelCommands[$ModelNul]} | sed -e 's&::& &g' > ${MODIPSL_SAVE}/Last_log
98echo "${NbComponents} components : " >> ${MODIPSL_SAVE}/Last_log
99echo ${ModelComponents[@]} >> ${MODIPSL_SAVE}/Last_log
100echo ${ModelTags[@]} >> ${MODIPSL_SAVE}/Last_log
101echo ${ModelSystems[@]} >> ${MODIPSL_SAVE}/Last_log
102echo ${ModelServers[@]} >> ${MODIPSL_SAVE}/Last_log
103echo ${ModelDirectories[@]} >> ${MODIPSL_SAVE}/Last_log
104echo ${ModelLocalDirs[@]} >> ${MODIPSL_SAVE}/Last_log
105
106thedate=$( echo ${ListModelDates[${ModelNum}]} | sed -e "s&_& &g" | sed -e "s&-&/&g")
107
108
109(( NbNewFiles = 0 ))
110(( NbModifFiles = 0 ))
111(( Maxfiledate = 0 ))
112(( i = 0 ))
113for comp in ${ModelComponents[@]}; do
114    tag=${ModelTags[$i]}
115    echo $i $comp " : " $tag
116
117    case ${ModelLocalDirs[$i]} in
118        [a-z]*)
119            if [ X${ModelDirectories[$i]} = X. ] ; then
120                pathComp=${ModelLocalDirs[i]}/${ModelComponents[$i]}
121                if [ -f ${pathComp} ] ; then
122                    filecomp=$( basename ${pathComp} )
123                    ListPathFile[$i]=${filecomp}
124                    pathComp=$( dirname ${pathComp} )
125                    pathexist=true
126                elif [ -d ${pathComp} ] ; then
127                    filecomp=""
128                    ListPathFile[$i]=_empty_
129                    pathexist=true
130                elif [ -d ${ModelLocalDirs[i]}/$( basename ${ModelComponents[$i]} ) ] ; then
131                    pathComp=${ModelLocalDirs[i]}/$( basename ${ModelComponents[$i]} )
132                    filecomp=""
133                    ListPathFile[$i]=_empty_
134                    pathexist=true
135                else
136                    echo "error for component : ${comp} !!"
137                    echo "  ${pathComp} does not exist."
138                    pathexist=false     
139                fi
140            else
141                pathComp=${ModelLocalDirs[i]}/${ModelDirectories[$i]}
142                if [ -f ${pathComp} ] ; then
143                    filecomp=$( basename ${pathComp} )
144                    ListPathFile[$i]=${filecomp}
145                    pathComp=$( dirname ${pathComp} )
146                    pathexist=true
147                elif [ -d ${pathComp} ] ; then
148                    filecomp=""
149                    ListPathFile[$i]=_empty_
150                    pathexist=true
151                else
152                    echo "error for component : ${comp} !!"
153                    echo "  ${pathComp} does not exist."
154                    pathexist=false     
155                fi
156            fi
157            ;;
158        \.)
159            pathComp=${ModelDirectories[$i]}
160            if [ -f ${pathComp} ] ; then
161                filecomp=$( basename ${pathComp} )
162                ListPathFile[$i]=${filecomp}
163                pathComp=$( dirname ${pathComp} )
164                pathexist=true
165            elif [ -d ${pathComp} ] ; then
166                filecomp=""
167                ListPathFile[$i]=_empty_
168                pathexist=true
169            else
170                echo "error for component : ${comp} !!"
171                echo "  ${pathComp} does not exist."
172                pathexist=false
173            fi
174            ;;
175        *)
176            echo "error ${ModelLocalDirs[$i]} is not recognized as a valid path in modipsl."
177            exit 1
178            ;;
179    esac
180
181    if ( ${pathexist} ) ; then
182        echo "real local path = " ${pathComp}
183        ListPathComp[$i]=${pathComp}
184
185
186        cd ${pathComp}
187        SpathComp=${MODIPSL_SAVE}/${pathComp}
188
189        save_diff_file=$( echo ${comp} | sed -e 's&/&:&g' )
190           
191        case ${ModelSystems[$i]} in
192            svn)
193                ListPathRev[$i]=$( svn info ${filecomp} | grep "R.vision_*:" | gawk -F  ' ' '{print $2}' )
194                ListPathBranch[$i]=${comp}
195               
196                svn diff -r ${ListPathRev[$i]} ${filecomp} > ${tmpMODIPSL}/svn_diff_${save_diff_file}
197                RET=$?
198                if [ $RET -gt 0 ] ; then
199                    ListPathComp[$i]="error"
200                    ListPathFile[$i]="error"
201                    ListPathRev[$i]="error"
202                    ListPathBranch[$i]="error"
203                else
204                    svn status ${filecomp} > ${tmpMODIPSL}/svn_status_${save_diff_file}
205                    set -A NewFiles -- $( grep "^? *\(.*\.${SUFFIXES}\|AA_.*\|BB_.*\)$" ${tmpMODIPSL}/svn_status_${save_diff_file} | sed -e "s&? *&&" )
206                    printDebugArray NewFiles
207                    for file in ${NewFiles[@]} ; do
208                        echo "New file : " $file
209                        cp -p $file ${SpathComp}/$( dirname $file )
210                        ListNewFiles[$NbNewFiles]=${pathComp}/${file}
211                        (( NbNewFiles = NbNewFiles + 1 ))
212                    done
213
214                    set -A ModifiedFiles -- $( grep "^M *" ${tmpMODIPSL}/svn_status_${save_diff_file} | sed -e "s&M *&&" )
215                    printDebugArray ModifiedFiles
216                    for file in ${ModifiedFiles[@]} ; do
217                        echo "Modified file : " $file
218                        filedate=$( ls -l --full-time --time-style='+%Y%m%d%H%M%S' $file | gawk -F  ' ' '{print $6}' )
219                        Maxfiledate=$(( ( $Maxfiledate > $filedate ) ? $Maxfiledate : $filedate ))
220                        ListModifFiles[$NbModifFiles]=${pathComp}/${file}
221                        ListModifFilesDate[$NbModifFiles]=${filedate}
222                        (( NbModifFiles = NbModifFiles + 1 ))
223                    done
224
225                    if ( ${DEBUG_mode} ); then
226                        cp ${tmpMODIPSL}/svn_diff_${save_diff_file} ${SpathComp}/svn_diff
227                    else
228                        rm ${tmpMODIPSL}/svn_status_${save_diff_file}
229                        mv ${tmpMODIPSL}/svn_diff_${save_diff_file} ${SpathComp}/svn_diff
230                    fi
231                    RET=$?
232                    if [ $RET -gt 0 ] ; then
233                        ListPathComp[$i]="error"
234                        ListPathFile[$i]="error"
235                        ListPathRev[$i]="error"
236                        ListPathBranch[$i]="error"
237                    fi
238                fi
239
240                ;;
241            cvs)
242                ListPathRev[$i]=${tag}:\"${thedate}\"
243                ListPathBranch[$i]=${tag}
244
245                cvs diff -U 2 ${filecomp} > ${tmpMODIPSL}/cvs_diff_${save_diff_file}_00
246                #eval cvs diff -U 2 -r "${ListPathRev[$i]}" ${filecomp} > ${tmpMODIPSL}/cvs_diff_${save_diff_file}_00
247                RET=$?
248                if [ $RET -gt 1 ] ; then
249                    ListPathComp[$i]="error"
250                    ListPathFile[$i]="error"
251                    ListPathRev[$i]="error"
252                    ListPathBranch[$i]="error"
253                else
254                    set -A NewFiles -- $( grep "^? .*\.${SUFFIXES}$" ${tmpMODIPSL}/cvs_diff_${save_diff_file}_00 | sed -e "s&? *&&" )
255                    printDebugArray NewFiles
256                    for file in ${NewFiles[@]} ; do
257                        echo "New file : " $file
258                        cp -p $file ${SpathComp}/$( dirname $file )
259                        ListNewFiles[$NbNewFiles]=${pathComp}/${file}
260                        (( NbNewFiles = NbNewFiles + 1 ))
261                    done
262
263                    set -A ModifiedFiles -- $( grep "^M .*\.${SUFFIXES}$" ${tmpMODIPSL}/cvs_diff_${save_diff_file}_00 | sed -e "s&M *&&" )
264                    printDebugArray ModifiedFiles
265                    for file in ${ModifiedFiles[@]} ; do
266                        echo "Modified file : " $file
267                        filedate=$( ls -l --full-time --time-style='+%Y%m%d%H%M%S' $file | gawk -F  ' ' '{print $6}' )
268                        Maxfiledate=$(( ( $Maxfiledate > $filedate ) ? $Maxfiledate : $filedate ))
269                        ListModifFiles[$NbModifFiles]=${pathComp}/${file}
270                        ListModifFilesDate[$NbModifFiles]=${filedate}
271                        (( NbModifFiles = NbModifFiles + 1 ))
272                    done
273
274                    ${MODIPSL}/util/correct-cvs-diff.awk ${tmpMODIPSL}/cvs_diff_${save_diff_file}_00 > ${tmpMODIPSL}/cvs_diff_${save_diff_file}_01
275                    RET=$?
276                    if ( ${DEBUG_mode} ); then
277                        cp ${tmpMODIPSL}/cvs_diff_${save_diff_file}_01 ${SpathComp}/cvs_diff
278                    else
279                        mv ${tmpMODIPSL}/cvs_diff_${save_diff_file}_01 ${SpathComp}/cvs_diff
280                        rm ${tmpMODIPSL}/cvs_diff_${save_diff_file}_00
281                    fi
282                    RET1=$?
283                    (( RET = RET + RET1 ))
284                    if [ $RET -gt 0 ] ; then
285                        ListPathComp[$i]="error"
286                        ListPathFile[$i]="error"
287                        ListPathRev[$i]="error"
288                        ListPathBranch[$i]="error"
289                    fi
290                fi
291                ;;
292            *)
293                echo "error ${ModelSystems[$i]} is not recognized as a valid control version system for $0."
294                exit 1
295                ;;
296        esac
297    else
298        ListPathComp[$i]="error"
299        ListPathFile[$i]="error"
300        ListPathRev[$i]="error"
301        ListPathBranch[$i]="error"
302    fi
303    (( i = i + 1 ))
304    echo
305    cd ${MODIPSL}
306
307done
308
309if [ -d ${SUBMIT_DIR} ] ; then
310    echo "Save SUBMIT_DIR : " ${SUBMIT_DIR}
311    echo
312    pathComp=$( basename ${SUBMIT_DIR} )
313    LocalDirectories[$i]=$( find . -mindepth 1 -type d \
314        \( -not -path "*${MODIPSL_SAVE_NAME}*" -a -name "${pathComp}" \) | head -1 )
315    ModelDirectories[$i]=.
316
317    ListPathComp[$i]=${pathComp}
318
319    cd ${SUBMIT_DIR}
320    SpathComp=${MODIPSL_SAVE}/${LocalDirectories[$i]}
321
322    save_diff_file=${pathComp}
323           
324    ListPathRev[$i]=$( svn info | grep "R.vision_*:" | gawk -F  ' ' '{print $2}' )
325   
326    svn diff -r ${ListPathRev[$i]} > ${tmpMODIPSL}/svn_diff_${save_diff_file}
327    RET=$?
328    if [ $RET -gt 0 ] ; then
329        ListPathComp[$i]="error"
330        ListPathFile[$i]="error"
331        ListPathRev[$i]="error"
332        ListPathBranch[$i]="error"
333    else
334        svn status > ${tmpMODIPSL}/svn_status_${save_diff_file}
335        set -A NewFiles -- $( grep "^? *\(.*\.${SUFFIXES}\|AA_.*\|BB_.*\)$" ${tmpMODIPSL}/svn_status_${save_diff_file} | sed -e "s&? *&&" )
336        printDebugArray NewFiles
337        for file in ${NewFiles[@]} ; do
338            echo "New file : " $file
339            cp -p $file ${SpathComp}/$( dirname $file )
340            ListNewFiles[$NbNewFiles]=${LocalDirectories[$i]}/${file}
341            (( NbNewFiles = NbNewFiles + 1 ))
342        done
343
344        set -A ModifiedFiles -- $( grep "^M *" ${tmpMODIPSL}/svn_status_${save_diff_file} | sed -e "s&M *&&" )
345        printDebugArray ModifiedFiles
346        for file in ${ModifiedFiles[@]} ; do
347            echo "Modified file : " $file
348#           filedate=$( ls -l --full-time --time-style='+%Y%m%d%H%M%S' $file | gawk -F  ' ' '{print $6}' )
349#           Maxfiledate=$(( ( $Maxfiledate > $filedate ) ? $Maxfiledate : $filedate ))
350            ListModifFiles[$NbModifFiles]=${LocalDirectories[$i]}/${file}
351            ListModifFilesDate[$NbModifFiles]=${filedate}
352            (( NbModifFiles = NbModifFiles + 1 ))
353        done
354
355        if ( ${DEBUG_mode} ); then
356            cp ${tmpMODIPSL}/svn_diff_${save_diff_file} ${SpathComp}/svn_diff
357        else
358            rm ${tmpMODIPSL}/svn_status_${save_diff_file}
359            mv ${tmpMODIPSL}/svn_diff_${save_diff_file} ${SpathComp}/svn_diff
360        fi
361        RET=$?
362        if [ $RET -gt 0 ] ; then
363            ListPathComp[$i]="error"
364            ListPathFile[$i]="error"
365            ListPathRev[$i]="error"
366            ListPathBranch[$i]="error"
367        fi
368    fi
369   
370    echo
371    cd ${MODIPSL}
372fi
373
374printDebugArray ListPathComp
375printDebugArray ListPathFile
376printDebugArray ListPathRev
377printDebugArray ListPathBranch
378printDebugArray ListNewFiles
379
380echo ${ListPathComp[@]} >> ${MODIPSL_SAVE}/Last_log
381echo ${ListPathFile[@]} >> ${MODIPSL_SAVE}/Last_log
382echo ${ListPathRev[@]} >> ${MODIPSL_SAVE}/Last_log
383echo ${ListPathBranch[@]} >> ${MODIPSL_SAVE}/Last_log
384echo ${ListNewFiles[@]} >> ${MODIPSL_SAVE}/Last_log
385echo ${ListModifFiles[@]} >> ${MODIPSL_SAVE}/Last_log
386echo ${ListModifFilesDate[@]} >> ${MODIPSL_SAVE}/Last_log
387echo ${Maxfiledate} >> ${MODIPSL_SAVE}/Last_log
388
389
390echo "out directory in " ${MODIPSL_SAVE}
Note: See TracBrowser for help on using the repository browser.