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