source: palm/trunk/SCRIPTS/document_changes @ 3748

Last change on this file since 3748 was 3665, checked in by raasch, 6 years ago

dummy statements added to avoid compiler warnings about unused variables, unused variables removed, ssh-call for submitting batch jobs on remote systems modified again to avoid output of login messages on specific systems

  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 9.8 KB
RevLine 
[1326]1#!/bin/ksh
2#------------------------------------------------------------------------------#
[2696]3# This file is part of the PALM model system.
[1326]4#
5# PALM is free software: you can redistribute it and/or modify it under the
6# terms of the GNU General Public License as published by the Free Software
7# Foundation, either version 3 of the License, or (at your option) any later
8# version.
9#
10# PALM is distributed in the hope that it will be useful, but WITHOUT ANY
11# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License along with
15# PALM. If not, see <http://www.gnu.org/licenses/>.
16#
[3665]17# Copyright 1997-2019 Leibniz Universitaet Hannover
[1326]18#------------------------------------------------------------------------------#
19#
20# Current revisions:
21# -----------------
22#
[1828]23#
[1326]24# Former revisions:
25# -----------------
26# $Id: document_changes 3665 2019-01-10 08:28:24Z suehring $
[2716]27# Corrected "Former revisions" section
28#
29# 2696 2017-12-14 17:12:51Z kanani
30# Change in file header (GPL part)
31#
32# 2235 2017-05-31 08:03:49Z maronga
[2235]33# Changed the submission procedure in order to reduce the number of required
34# commits to one per change.
[1813]35#
[2235]36# 2117 2017-01-16 16:28:44Z maronga
37#
[1828]38# 1827 2016-04-07 12:12:23Z maronga
39# Added note that the script does not work on MAC OS
40#
[1814]41# 1813 2016-04-06 09:38:56Z maronga
42# Added update of the copyright statements in the file headers.
43#
[1811]44# 1810 2016-04-05 20:25:29Z maronga
45# document_changes now checks all subdirectories. Modified printing to screen.
46#
[1805]47# 1804 2016-04-05 16:30:18Z maronga
48# Removed printing of "this is an alpha version"
49#
[1328]50# 1326 2014-03-21 10:44:31Z maronga
51# Initial revision
52#
[1326]53# Description:
54# ------------
55# This tool moves text from "Current Revisions:" to "Former Revisions:" and
56# adds the svn timestamp. It works with the folders SOURCE and SCRIPTS
57#
58# Usage:
[1810]59# a) go to the source directory (e.g. current_version/trunk and perform:
60#    "document_changes",
[1326]61# b) or call "document_changes" directly and add the path to the source code as
62#    argument
[1810]63#    (e.g. document_changes trunk)
[1326]64#
65# Note:
66# The script will only work properly if the two following conditions are met:
67# 1) the 2nd line after "Current Revisions:" must contain text,
68# 2) the last line before "Former Revisions:" must not contain text.
69#------------------------------------------------------------------------------#
70
71#
72#-- define variables
73    comments=""         #: variable contains the CR text
74    comment_char=="!"   #: comment character
75    count_changes=0     #: count the number of files with CR text
[1813]76    count_updates=0     #: count the number of files with copyright update
[1326]77    count_files=0       #: count the number of files
[1810]78    fn=""               #: current file name to be scanned
[1326]79    file_firstchar=""   #: first character of filename
80    file_lastchar=""    #: last character of filename
81    file_extension=""   #: filename extension
82    found_comment=false #: true/false if a CR text was found
83    IFS=''              #: set standard delimiter to empty string
84    input_dir=""        #: directory of the source code
85    line=""             #: containts the current line of filename
86    line_count=0        #: counter to the line no. of the file
87    line_start=9999999  #: line no. where CR text starts
[1810]88    line_stop=0         #: line no. where CR text ends
[1326]89    line_tmp=""         #: first 19 characters of line
90    list_delete=""      #: contains the line no. that must be deleted from CR
91    timestamp=""        #: the svn timestamp of the file
[1813]92    current_year=$(date +"%Y")
[1326]93
94#
95#-- get input directory
96    input_dir=$1
97    if  [[ "$input_dir" == "" ]]
98    then
99       input_dir=`pwd`
100    fi
[1810]101   
102    printf "\n"
103    printf "#------------------------------------------------------------------------# \n"
104    printf "| \e[1mdocument_changes\e[0m                                                       | \n"
105    printf "|                                                                        | \n"
106    printf "| This tool moves the change comments in the all PALM file headers from  | \n"
107    printf "| 'Current revisions' to 'Former revisions' and saves the time stamp.    | \n" 
108    printf "#------------------------------------------------------------------------# \n"
109   
110    printf "\n  *** Checking files in $input_dir and all recursive subdirectories...\n"
[1326]111
[1813]112   
113#
114#-- scan all (sub-)directories for files.
[1810]115    IFS=$'\n';
[1813]116    for fn in $(find $input_dir -not -name '*.pdf'  -and -not -name '*.x'      \
117                           -and -not -name '*.eps'  -and -not -name '*.png'    \
118                           -and -not -name '*.svn*' -and -not -name '*~'       \
119                           -and -not -name '*.tar'); do
[1326]120
121#
[1813]122#--    exclude invisible files
[1810]123       file_firstchar=${fn:0:1}
124       file_lastchar=`echo -n $fn| tail -c -1`
125       file_extension=${fn##*.}
[1813]126       if [[ "$file_firstchar" == "." ]]
[1326]127       then
128          continue
129       fi
[1810]130       
[1326]131       (( count_files = count_files + 1 ))
132
133       line_count=0
134       found_comment=false
135       list_delete=""
136       line_start=9999999
137       line_stop=0
138       comments=""
139
140#
[1813]141#--    read one line at a time and move revision comments
[1326]142       while read line
143       do
144
145          (( line_count = line_count + 1 ))
146          line_tmp=""
147          line_tmp=${line:2:17}
148
149#
150#--       check if stopping point is reached
151          if [[ $line_stop -eq 0 && "$line_tmp" == "Former revisions:" ]]
152          then
153             line_stop=$line_count
154          fi
155
156#
157#--       check if starting point is reached
158          if [[ $line_start -eq 9999999 && "$line_tmp" == "Current revisions" ]]
159          then
160             (( line_start = line_count + 2 ))
161             comment_char=${line:0:1}
162          fi
163
164#
165#--       read comment line
166          if [[ $line_count -ge $line_start && $line_stop -eq 0 ]]
167          then
168
169#
170#--          check for empty comments
[1328]171             line_no_space=`echo ${line:2:10} | sed -e 's/^[ \t]*//'`
172             if [[ $line_count -eq $line_start && "$line_no_space" != "" ]]
[1326]173             then
[1810]174
175             
176                printf "\r%$(tput cols)s" " "   
177                printf "\r  \e[1;92m*** Comments found in $fn\e[0m\n"
178             
[1326]179                found_comment=true
[1810]180                cp $fn $fn~
[1326]181             fi
182
183#
184#--          when comments are found, save comment lines to $comments
185             if [[ "$found_comment" == true ]]
186             then
187                comments="$comments\n$line"
188                list_delete="$list_delete;${line_count}d"
189             fi
190          fi
[1810]191         
[1326]192#
193#--       get the timestamp from the current revision
194          if [[ "$comments" != "" && $line_count -eq $line_stop+2 ]]
195          then
[2235]196            comments="$comment_char $line$comments"
[1326]197            timestamp=`echo $line | cut -d" " -s -f4-7`
[2235]198            timestamp_string="$comment_char $timestamp"
[1326]199          fi
200
[2235]201         
202         
203         
[1810]204       done <"$fn"
[1326]205
[1813]206       
207       
208#
209#--    check for updates of the copyright statement
210       found_update_year=false
211
212       while read line
213       do
214
215          line_tmp=""
216          line_tmp2=""     
217          line_tmp=${line:22:29}
218          line_tmp2=${line:2:15}
219         
220#           echo "$line_tmp $line_tmp2"
221         
222          if  [[ "$line_tmp" == "Leibniz Universitaet Hannover" && "$line_tmp2" == "Copyright 1997-" ]]
223          then
224         
225             year_in_file=${line:17:4}
226             if  [[ "$year_in_file" != "$current_year" ]]
227             then
228     
229                printf "\r%$(tput cols)s" " "   
230                printf "\r  \e[1;33m*** Copyright update required in $fn\e[0m\n"
231
232                comment_char=${line:0:1}
233                found_update_year=true             
234                cp $fn $fn~
235               
236             fi
237          fi
238       
239       done <"$fn"
240         
[1810]241       printf "\r%$(tput cols)s" " "   
[1813]242       printf "\r\e[1m  *** Searched files: $count_files. Comments found: $count_changes. Copyright updates found: $count_updates\e[0m"
[1810]243       
[1326]244#
245#--    move comments from current revisions to former revisions
246       if [[ "$found_comment" == true ]]
247       then
248
249          (( count_changes = count_changes + 1 ))
250
251#
[2235]252#--       remove leading \n characters in string
253          comments=${comments:2}
254 
255 
256         
257#
258#--       fix old time stamp
259          (( line_time = line_stop + 2 ))
260          sed -i "${line_time}d" $fn     
261          sed -i "${line_time}i$timestamp_string" $fn
262
263
264
265#
[1326]266#--       insert comments to Former Revisions
[2235]267          (( line_stop = line_stop + 2 ))
[1810]268          sed -i "${line_stop}i$comments" $fn
[2235]269         
[1326]270
[2235]271
[1326]272#
273#--       delete comments from current revisions and insert two blank lines
274          list_delete=${list_delete#?}
[1810]275          sed -i "$list_delete" $fn
276          sed -i "${line_start}i${comment_char} " $fn
277          sed -i "${line_start}i${comment_char} " $fn
[1326]278
279       fi
280
[1813]281#
282#--    move comments from current revisions to former revisions
283       if [[ "$found_update_year" == true ]]
284       then
285
286          (( count_updates = count_updates + 1 )) 
287         
288           sed -i "s/$comment_char Copyright 1997-.*Leibniz Universitaet Hannover/$comment_char Copyright 1997-$current_year Leibniz Universitaet Hannover/" $fn
289     
290       fi
291       
[1326]292    done
293
294#
295#-- inform the user about the changes
[1810]296    printf "\r%$(tput cols)s" " "
[1813]297    printf "\r\e[1m  *** Searched files: $count_files. Comments found: $count_changes. Copyright updates found: $count_updates\e[0m. - \e[1;32mfinished.\e[0m\n\n"
[1810]298
[1326]299    if  [[ $count_changes -gt 0 ]]
300    then
[2235]301       printf "  *** You can now proceed with\n      \e[0;91msvn commit -m 'your commit message' trunk\e[0m\n"
[1810]302       printf "  *** Please do not forget to commit your changes in the changelog at\n      \e[0;91mhttps://palm.muk.uni-hannover.de/trac/wiki/doc/tec/changelog\e[0m!\n"   
[1326]303    else
[1810]304        printf "  *** No comments found in files!\n"   
305   
[1326]306    fi
Note: See TracBrowser for help on using the repository browser.