source: modipsl/trunk/util/script_diff_model @ 1610

Last change on this file since 1610 was 1596, checked in by mmaipsl, 13 years ago

Add SUBMIT_DIR differencies save in source tar.

  • Property svn:executable set to *
  • Property svn:keywords set to Date,Author,Revision
File size: 12.7 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
41# env must know MODIPSL path variable !
42MODIPSL=${MODIPSL:=$(pwd)}
43SUBMIT_DIR=$1
44
45DEBUG_mode=false
46
47function printDebugArray {
48    if ( ${DEBUG_mode} ); then
49        typeset nb_line i
50        eval nb_line=\${#$1[@]}
51        eval echo "$1 : " ${nb_line}
52        (( i = 0 ))
53        while [ $i -lt $nb_line ] ; do
54            eval echo \${$1[$i]}
55            (( i = i + 1 ))
56        done
57    fi
58}
59
60typeset tag thedate save_diff_file pathComp pathexist i filecomp filedate file SpathComp SUFFIXES NbNewFiles NbModifFiles Maxfiledate
61
62# Analyse log file: get last model command
63. ${MODIPSL}/util/script_log_analyse
64
65# Code source suffixe for new file detection
66SUFFIXES='\(f90\|F90\|f\|F\|h\|h90\|hh\|c\|cc\|inc\|fcm\|path\|cfg\|card\|driver\|def\|def_.*\|txt\|xml\|ksh\|tex\)'
67
68MODIPSL_SAVE_NAME=modipsl_save_diff_$( date +%F_%H%M%S )
69echo "out directory in " ${MODIPSL_SAVE_NAME}
70MODIPSL_SAVE=${MODIPSL}/${MODIPSL_SAVE_NAME}
71printDebugArray MODIPSL_SAVE
72
73set +A ListRep -- $( find ${MODIPSL} -mindepth 1 -type d \
74    \( -not -path '*.svn*' -a -not -path '*CVS*' -a -not -path "${MODIPSL}/modipsl_save*" \
75    -a -not -path "${MODIPSL}/bin" -a -not -path "${MODIPSL}/lib" -a -not -path "${MODIPSL}/util" \
76    -a -not -path "${MODIPSL}/tmp" \) \
77    -exec bash -c " echo "'{}'" | sed -e 's&"${MODIPSL}"/&&' | tee -a >( sed -e 's&\(.*\)&"${MODIPSL_SAVE}"/\1&' | xargs mkdir -p >> out_mkdir 2>&1 ) " \; )
78rm out_mkdir
79#echo ${ListRep[0]} | tee $(ls > toto) $(ls -la > tata)
80#mkdir -Rp ${MODIPSL_SAVE}/
81printDebugArray ListRep
82
83
84echo "Last Model in log : " ${ListModelCommands[$ModelNul]} | sed -e 's&::& &g' > ${MODIPSL_SAVE}/Last_log
85echo "${NbComponents} components : " >> ${MODIPSL_SAVE}/Last_log
86echo ${ModelComponents[@]} >> ${MODIPSL_SAVE}/Last_log
87echo ${ModelTags[@]} >> ${MODIPSL_SAVE}/Last_log
88echo ${ModelSystems[@]} >> ${MODIPSL_SAVE}/Last_log
89echo ${ModelServers[@]} >> ${MODIPSL_SAVE}/Last_log
90echo ${ModelDirectories[@]} >> ${MODIPSL_SAVE}/Last_log
91echo ${ModelLocalDirs[@]} >> ${MODIPSL_SAVE}/Last_log
92
93thedate=$( echo ${ListModelDates[${ModelNum}]} | sed -e "s&_& &g" | sed -e "s&-&/&g")
94
95
96(( NbNewFiles = 0 ))
97(( NbModifFiles = 0 ))
98(( Maxfiledate = 0 ))
99(( i = 0 ))
100for comp in ${ModelComponents[@]}; do
101    tag=${ModelTags[$i]}
102    echo $i $comp " : " $tag
103
104    case ${ModelLocalDirs[$i]} in
105        [a-z]*)
106            if [ X${ModelDirectories[$i]} = X. ] ; then
107                pathComp=${ModelLocalDirs[i]}/${ModelComponents[$i]}
108                if [ -f ${pathComp} ] ; then
109                    filecomp=$( basename ${pathComp} )
110                    ListPathFile[$i]=${filecomp}
111                    pathComp=$( dirname ${pathComp} )
112                    pathexist=true
113                elif [ -d ${pathComp} ] ; then
114                    filecomp=""
115                    ListPathFile[$i]=_empty_
116                    pathexist=true
117                elif [ -d ${ModelLocalDirs[i]}/$( basename ${ModelComponents[$i]} ) ] ; then
118                    pathComp=${ModelLocalDirs[i]}/$( basename ${ModelComponents[$i]} )
119                    filecomp=""
120                    ListPathFile[$i]=_empty_
121                    pathexist=true
122                else
123                    echo "error for component : ${comp} !!"
124                    echo "  ${pathComp} does not exist."
125                    pathexist=false     
126                fi
127            else
128                pathComp=${ModelLocalDirs[i]}/${ModelDirectories[$i]}
129                if [ -f ${pathComp} ] ; then
130                    filecomp=$( basename ${pathComp} )
131                    ListPathFile[$i]=${filecomp}
132                    pathComp=$( dirname ${pathComp} )
133                    pathexist=true
134                elif [ -d ${pathComp} ] ; then
135                    filecomp=""
136                    ListPathFile[$i]=_empty_
137                    pathexist=true
138                else
139                    echo "error for component : ${comp} !!"
140                    echo "  ${pathComp} does not exist."
141                    pathexist=false     
142                fi
143            fi
144            ;;
145        \.)
146            pathComp=${ModelDirectories[$i]}
147            if [ -f ${pathComp} ] ; then
148                filecomp=$( basename ${pathComp} )
149                ListPathFile[$i]=${filecomp}
150                pathComp=$( dirname ${pathComp} )
151                pathexist=true
152            elif [ -d ${pathComp} ] ; then
153                filecomp=""
154                ListPathFile[$i]=_empty_
155                pathexist=true
156            else
157                echo "error for component : ${comp} !!"
158                echo "  ${pathComp} does not exist."
159                pathexist=false
160            fi
161            ;;
162        *)
163            echo "error ${ModelLocalDirs[$i]} is not recognized as a valid path in modipsl."
164            exit 1
165            ;;
166    esac
167
168    if ( ${pathexist} ) ; then
169        echo "real local path = " ${pathComp}
170        ListPathComp[$i]=${pathComp}
171
172
173        cd ${pathComp}
174        SpathComp=${MODIPSL_SAVE}/${pathComp}
175
176        save_diff_file=$( echo ${comp} | sed -e 's&/&:&g' )
177           
178        case ${ModelSystems[$i]} in
179            svn)
180                ListPathRev[$i]=$( svn info ${filecomp} | grep "R.vision_*:" | gawk -F  ' ' '{print $2}' )
181                ListPathBranch[$i]=${comp}
182               
183                svn diff ${filecomp} > ${MODIPSL}/svn_diff_${save_diff_file}
184                RET=$?
185                if [ $RET -gt 0 ] ; then
186                    ListPathComp[$i]="error"
187                    ListPathFile[$i]="error"
188                    ListPathRev[$i]="error"
189                    ListPathBranch[$i]="error"
190                else
191                    svn status ${filecomp} > ${MODIPSL}/svn_status_${save_diff_file}
192                    set -A NewFiles -- $( grep "^? *\(.*\.${SUFFIXES}\|AA_.*\|BB_.*\)$" ${MODIPSL}/svn_status_${save_diff_file} | sed -e "s&? *&&" )
193                    printDebugArray NewFiles
194                    for file in ${NewFiles[@]} ; do
195                        echo "New file : " $file
196                        cp -p $file ${SpathComp}/$( dirname $file )
197                        ListNewFiles[$NbNewFiles]=${pathComp}/${file}
198                        (( NbNewFiles = NbNewFiles + 1 ))
199                    done
200
201                    set -A ModifiedFiles -- $( grep "^M *" ${MODIPSL}/svn_status_${save_diff_file} | sed -e "s&M *&&" )
202                    printDebugArray ModifiedFiles
203                    for file in ${ModifiedFiles[@]} ; do
204                        echo "Modified file : " $file
205                        filedate=$( ls -l --full-time --time-style='+%Y%m%d%H%M%S' $file | gawk -F  ' ' '{print $6}' )
206                        Maxfiledate=$(( ( $Maxfiledate > $filedate ) ? $Maxfiledate : $filedate ))
207                        ListModifFiles[$NbModifFiles]=${pathComp}/${file}
208                        ListModifFilesDate[$NbModifFiles]=${filedate}
209                        (( NbModifFiles = NbModifFiles + 1 ))
210                    done
211
212                    if ( ${DEBUG_mode} ); then
213                        cp ${MODIPSL}/svn_diff_${save_diff_file} ${SpathComp}/svn_diff
214                    else
215                        rm ${MODIPSL}/svn_status_${save_diff_file}
216                        mv ${MODIPSL}/svn_diff_${save_diff_file} ${SpathComp}/svn_diff
217                    fi
218                    RET=$?
219                    if [ $RET -gt 0 ] ; then
220                        ListPathComp[$i]="error"
221                        ListPathFile[$i]="error"
222                        ListPathRev[$i]="error"
223                        ListPathBranch[$i]="error"
224                    fi
225                fi
226
227                ;;
228            cvs)
229                ListPathRev[$i]=${tag}:\"${thedate}\"
230                ListPathBranch[$i]=${tag}
231
232                cvs diff -U 2 ${filecomp} > ${MODIPSL}/cvs_diff_${save_diff_file}_00
233                #eval cvs diff -U 2 -r "${ListPathRev[$i]}" ${filecomp} > ${MODIPSL}/cvs_diff_${save_diff_file}_00
234                RET=$?
235                if [ $RET -gt 1 ] ; then
236                    ListPathComp[$i]="error"
237                    ListPathFile[$i]="error"
238                    ListPathRev[$i]="error"
239                    ListPathBranch[$i]="error"
240                else
241                    set -A NewFiles -- $( grep "^? .*\.${SUFFIXES}$" ${MODIPSL}/cvs_diff_${save_diff_file}_00 | sed -e "s&? *&&" )
242                    printDebugArray NewFiles
243                    for file in ${NewFiles[@]} ; do
244                        echo "New file : " $file
245                        cp -p $file ${SpathComp}/$( dirname $file )
246                        ListNewFiles[$NbNewFiles]=${pathComp}/${file}
247                        (( NbNewFiles = NbNewFiles + 1 ))
248                    done
249
250                    set -A ModifiedFiles -- $( grep "^M .*\.${SUFFIXES}$" ${MODIPSL}/cvs_diff_${save_diff_file}_00 | sed -e "s&M *&&" )
251                    printDebugArray ModifiedFiles
252                    for file in ${ModifiedFiles[@]} ; do
253                        echo "Modified file : " $file
254                        filedate=$( ls -l --full-time --time-style='+%Y%m%d%H%M%S' $file | gawk -F  ' ' '{print $6}' )
255                        Maxfiledate=$(( ( $Maxfiledate > $filedate ) ? $Maxfiledate : $filedate ))
256                        ListModifFiles[$NbModifFiles]=${pathComp}/${file}
257                        ListModifFilesDate[$NbModifFiles]=${filedate}
258                        (( NbModifFiles = NbModifFiles + 1 ))
259                    done
260
261                    ${MODIPSL}/util/correct-cvs-diff.awk ${MODIPSL}/cvs_diff_${save_diff_file}_00 > ${MODIPSL}/cvs_diff_${save_diff_file}_01
262                    RET=$?
263                    if ( ${DEBUG_mode} ); then
264                        cp ${MODIPSL}/cvs_diff_${save_diff_file}_01 ${SpathComp}/cvs_diff
265                    else
266                        mv ${MODIPSL}/cvs_diff_${save_diff_file}_01 ${SpathComp}/cvs_diff
267                        rm ${MODIPSL}/cvs_diff_${save_diff_file}_00
268                    fi
269                    RET1=$?
270                    (( RET = RET + RET1 ))
271                    if [ $RET -gt 0 ] ; then
272                        ListPathComp[$i]="error"
273                        ListPathFile[$i]="error"
274                        ListPathRev[$i]="error"
275                        ListPathBranch[$i]="error"
276                    fi
277                fi
278                ;;
279            *)
280                echo "error ${ModelSystems[$i]} is not recognized as a valid control version system for $0."
281                exit 1
282                ;;
283        esac
284    else
285        ListPathComp[$i]="error"
286        ListPathFile[$i]="error"
287        ListPathRev[$i]="error"
288        ListPathBranch[$i]="error"
289    fi
290    (( i = i + 1 ))
291    echo
292    cd ${MODIPSL}
293
294done
295
296if [ -d ${SUBMIT_DIR} ] ; then
297    echo "Save SUBMIT_DIR : " ${SUBMIT_DIR}
298    echo
299    pathComp=$( basename ${SUBMIT_DIR} )
300    LocalDirectories[$i]=$( find . -mindepth 1 -type d \
301        \( -not -path "*${MODIPSL_SAVE_NAME}*" -a -name "${pathComp}" \) | head -1 )
302    ModelDirectories[$i]=.
303
304    ListPathComp[$i]=${pathComp}
305
306    cd ${SUBMIT_DIR}
307    SpathComp=${MODIPSL_SAVE}/${LocalDirectories[$i]}
308
309    save_diff_file=${pathComp}
310           
311    ListPathRev[$i]=$( svn info | grep "R.vision_*:" | gawk -F  ' ' '{print $2}' )
312   
313    svn diff > ${MODIPSL}/svn_diff_${save_diff_file}
314    RET=$?
315    if [ $RET -gt 0 ] ; then
316        ListPathComp[$i]="error"
317        ListPathFile[$i]="error"
318        ListPathRev[$i]="error"
319        ListPathBranch[$i]="error"
320    else
321        svn status > ${MODIPSL}/svn_status_${save_diff_file}
322        set -A NewFiles -- $( grep "^? *\(.*\.${SUFFIXES}\|AA_.*\|BB_.*\)$" ${MODIPSL}/svn_status_${save_diff_file} | sed -e "s&? *&&" )
323        printDebugArray NewFiles
324        for file in ${NewFiles[@]} ; do
325            echo "New file : " $file
326            cp -p $file ${SpathComp}/$( dirname $file )
327            ListNewFiles[$NbNewFiles]=${LocalDirectories[$i]}/${file}
328            (( NbNewFiles = NbNewFiles + 1 ))
329        done
330
331        set -A ModifiedFiles -- $( grep "^M *" ${MODIPSL}/svn_status_${save_diff_file} | sed -e "s&M *&&" )
332        printDebugArray ModifiedFiles
333        for file in ${ModifiedFiles[@]} ; do
334            echo "Modified file : " $file
335#           filedate=$( ls -l --full-time --time-style='+%Y%m%d%H%M%S' $file | gawk -F  ' ' '{print $6}' )
336#           Maxfiledate=$(( ( $Maxfiledate > $filedate ) ? $Maxfiledate : $filedate ))
337            ListModifFiles[$NbModifFiles]=${LocalDirectories[$i]}/${file}
338            ListModifFilesDate[$NbModifFiles]=${filedate}
339            (( NbModifFiles = NbModifFiles + 1 ))
340        done
341
342        if ( ${DEBUG_mode} ); then
343            cp ${MODIPSL}/svn_diff_${save_diff_file} ${SpathComp}/svn_diff
344        else
345            rm ${MODIPSL}/svn_status_${save_diff_file}
346            mv ${MODIPSL}/svn_diff_${save_diff_file} ${SpathComp}/svn_diff
347        fi
348        RET=$?
349        if [ $RET -gt 0 ] ; then
350            ListPathComp[$i]="error"
351            ListPathFile[$i]="error"
352            ListPathRev[$i]="error"
353            ListPathBranch[$i]="error"
354        fi
355    fi
356   
357    echo
358    cd ${MODIPSL}
359fi
360
361printDebugArray ListPathComp
362printDebugArray ListPathFile
363printDebugArray ListPathRev
364printDebugArray ListPathBranch
365printDebugArray ListNewFiles
366
367echo ${ListPathComp[@]} >> ${MODIPSL_SAVE}/Last_log
368echo ${ListPathFile[@]} >> ${MODIPSL_SAVE}/Last_log
369echo ${ListPathRev[@]} >> ${MODIPSL_SAVE}/Last_log
370echo ${ListPathBranch[@]} >> ${MODIPSL_SAVE}/Last_log
371echo ${ListNewFiles[@]} >> ${MODIPSL_SAVE}/Last_log
372echo ${ListModifFiles[@]} >> ${MODIPSL_SAVE}/Last_log
373echo ${ListModifFilesDate[@]} >> ${MODIPSL_SAVE}/Last_log
374echo ${Maxfiledate} >> ${MODIPSL_SAVE}/Last_log
375
376
377echo "out directory in " ${MODIPSL_SAVE}
Note: See TracBrowser for help on using the repository browser.