source: modipsl/trunk/util/script_diff_model @ 1582

Last change on this file since 1582 was 1580, checked in by mmaipsl, 13 years ago

This script may be used to create a tree of last configuration downloaded by modipsl/util/model command.

It checks the control version used for each components of the configuration and saves the diff
between the revision downloaded (or updated) and the modifications of the developper.
It saves those diff in the component directory in the copy tree.
It saves also new source files. See SUFFIXES definition below for the list of extension to detect source files.

It also gives a Last_log file in the root of the save tree with all informations needed to download the same
configuration precisely. It has the list of new and modified files and give the date (in an non human format)
of each modifications.

It may be used in modipsl directory :

modipsl_path> util/script_diff_model modipsl_name_of_the_save

After this use, you will have a modipsl_path/modipsl_name_of_the_save.tar file that you can save with the
executable you have build with this modified configuration.

Note :

Be aware to modify AA_make files in your model source code tree (and not only Makefiles) if you use modipsl
ins_make script and portable Makefile build. In this case, Makefiles won't be versionning and modifications
won't be saves.

You can use script_recup_model script to download the same configuration and make change
with new files and modified source files.

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