source: palm/trunk/SCRIPTS/document_changes @ 4509

Last change on this file since 4509 was 4481, checked in by maronga, 5 years ago

Bugfix for copyright updates in document_changes; copyright update applied to all files

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