source: palm/trunk/SCRIPTS/document_changes @ 4901

Last change on this file since 4901 was 4843, checked in by raasch, 4 years ago

local namelist parameter added to switch off the module although the respective module namelist appears in the namelist file, further copyright updates

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