source: palm/trunk/SCRIPTS/document_changes @ 2359

Last change on this file since 2359 was 2235, checked in by maronga, 7 years ago

revised document_changes to allow to submit changes via a single svn commit

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