source: PSPA/madxPSPA/testing/MadWorkBetweenReleases.pl @ 463

Last change on this file since 463 was 430, checked in by touze, 11 years ago

import madx-5.01.00

File size: 8.1 KB
Line 
1#!/usr/bin/perl
2
3$firstRelease = $ARGV[0];
4$secondRelease = $ARGV[1];
5
6use File::Path; # to remove directory trees
7
8$website = "/afs/cern.ch/user/n/nougaret/www/mad/";
9
10@extractedPackages = ('madX');
11
12$pwd = `pwd`;
13chop $pwd;
14$extractDir = $pwd . "/MadCvsExtract_releaseWorkReport" ;
15rmtree($extractDir);
16mkdir($extractDir, 0777);
17chdir($extractDir);
18
19
20$cvsDir = ":gserver:isscvs.cern.ch:/local/reps/madx" ;
21
22my $startTime = localtime;
23
24
25foreach(@extractedPackages) {
26    my $pack = $_;
27    `cvs -d $cvsDir checkout $pack`;
28}
29
30chdir('./madX');
31
32# now find-out all the work from the contributors
33# that went into the CVS in between the two last releases
34
35@authors = (); # global variable modified by recordWork
36recordWork($firstRelease, $secondRelease);
37
38
39chdir($pwd); # back to the top menu
40rmtree($extractDir);
41
42exit 0;
43
44
45sub recordWork { # should also pass the output file name
46    $rel1 = $_[0]; # first release
47    $rel2 = $_[1]; # second release
48
49    $rootDir = "$website"; 
50    chop $rootDir; # don't need the final "/"
51    $workReportFile = "workReport.html";
52    open WORKFILE, ">$rootDir/$workReportFile";
53    $workReportContent = "";
54
55    @files = `ls *.*`;
56    @makefiles = `ls Make*`;
57    @files = (@files, @makefiles);
58    # print "rel1 is $rel1, rel2 is $rel2\n";
59    FILE_LOOP: foreach $file (@files){
60        chop $file;
61        my @logs = `cvs log $file`;
62        # first look for the revisions associated to the first and second releases
63        foreach $log (@logs){
64           
65            my $pattern1 = "^[\\s\\t]*$rel1\[\\s\\t]*:[\\s\\t]*([\\d\\.]+)[\\s\\t]*\$";
66            # print "pattern is $pattern\n";
67            if ($log =~/$pattern1/){
68                $rev1 = $1;
69                # print "$file: $rel1 -> revision 1 is $rev1\n";
70            }
71            my $pattern2 = "^[\\s\\t]*$rel2\[\\s\\t]*:[\\s\\t]*([\\d\\.]+)[\\s\\t]*\$";
72            if ($log =~ /$pattern2/){
73                $rev2 = $1;
74                # print "$file: $rel2 -> revision 2 is $rev2\n";
75            }
76        }
77       
78        if ($rev1 eq $rev2){
79            # no work went into latest release, may skip
80            next FILE_LOOP;
81        }
82
83        # now look for the authors having modified the code between release 1 and 2
84        # (including the latter).
85        # to this end, check all revisions located between $rev1 and $rev2 for given file
86       
87        # re-scan log for this file in order to find-out revision work
88        # in a CVS log info looks like the following:
89        # revision: 1.2.3
90        # date: ... author: ...
91        my $parserState = "skipHeader" ; # some state-variable
92        my $nextParserState = ""; # default             
93        my @logsOfInterest = `cvs log -r$rev1:$rev2 $file`;
94
95#       print "cvs log -r$rev1:$rev2 $file\n";
96
97        foreach $log (@logsOfInterest){
98 
99#           print "Current Parser State = $parserState\n";
100   
101            if ($parserState eq "skipHeader"){
102                if ($log =~ /^description:[\s\t]*/){
103                    $nextParserState = "skipLine";
104                } else {
105                    $nextParserState = "skipHeader";
106                }
107            }
108
109            if ($parserState eq "skipLine"){
110                if ($log =~ /^\-\-\-(\-)+[\s\t]*/){
111                    $nextParserState = "readRev";
112                } else {
113                    if ($log =~ /^\=\=\=(\=)+[\s\t]*/){
114                        $nextParserState = "EOF";
115                    } else {
116                        print "line '-----' expected, but not found!\n";
117                        return; # leave function
118                        # should clean-up the HTML file containing the work-report first
119                    }
120                }
121            }
122           
123           
124            if ($parserState eq "readRevisionInfo"){
125                #print "Mode: retreive detailed work info\n";
126                #print "Process line $log\n";
127                if ($log =~ /author[\s\t]*:[\s\t]*(\w+);/){
128                    $author = $1;
129                    # print "found work-unit carried-out by $candidate\n";
130                    # make sure author is not already in the list
131                    my $alreadyRecorded = 0;
132                    foreach $auth (@authors){
133                        if ($auth eq $author) {
134                            $alreadyRecorded = 1;
135                        }
136                    }
137                   
138                    $log =~ /;[\s\t]+lines:[\s\t]+\+(\d+)[\s\t]+\-(\d+)[\s\t]*;/;
139                    # print "work is +$1 -$2 LOC\n";
140                    if ($alreadyRecorded == 0 ) {
141                        @authors = ( @authors, $author );
142                        $workByAuthor{$author}="";
143                        $linesAdded{$author} = $1;
144                        $linesDeleted{$author} = $2; 
145                    } else {
146                        $linesAdded{$author} += $1;
147                        $linesDeleted{$author} += $2;
148                       
149                    }
150                }
151                $nextParserState = "readComment" ;
152            }
153
154
155
156            if ($parserState eq "skipRevisionInfo"){
157                # in case the work has been registered for the previous release, we want to discard it here
158                # (a parallel sequential machine dedicated to rejecting work from previous release)
159                $nextParserState = "skipComment";
160            }
161            if ($parserState eq "skipComment"){ # also, just in case the work relates to the previous release
162                # (a parallel sequential machine dedicated to rejecting work from previous release)
163                if ($log =~ /\-\-\-\-(\-)+/){
164                    # actually we find-out we should actually be in "skipLine" state
165                    $nextParserState = "readRev";
166                } else {
167                    if ($log =~ /(========)+/){
168                        $nextParserState = "EOF";
169                    } else {
170                        $nextParserState = "skipComment"; # until encounter a '---' or '===' marker
171                    }
172                }
173            }
174
175
176           
177            if ($parserState eq "readComment"){
178               
179
180                if ($log =~ /\-\-\-\-(\-)+/){
181                    # actually we find-out we should actually be in "skipLine" state
182                    # mark the end of the comment with a specific beacon "EndOfComment"
183                    $workByAuthor{$author} .= "EndOfComment\n";
184                    $nextParserState = "readRev";
185                } else {
186                    if ($log =~ /(========)+/){
187                        # same as above
188                        $workByAuthor{$author} .= "EndOfComment\n";
189                        $nextParserState = "EOF";
190                    } else {
191                        # should concatenate the comment's string here...
192                        $workByAuthor{$author} .= "$log";
193                        $nextParserState = "readComment"; # until encounter a '---' or '===' marker
194                    }
195                }
196
197#               $nextParserState = "skipLine"; # unless the comment spreads over successive lines!
198               
199
200            }
201
202            if ($parserState eq "readRev"){
203                if ($log =~ /^[\s\t]*revision[\s\t]+([\d\.]+)[\s\t]*$/){
204                    # same number of dots?
205                    my $rev = $1;
206                   
207                    if ($rev eq $rev1){
208                        # print "revision $rev of $file belongs to last release => skip!\n";
209                        # don't want to register work that went in to the previous release: skip
210                        $nextParserState = "skipRevisionInfo";
211                    } else {
212                       
213                        # if we reach this point, the comparison was succesful
214                        # =>advance to the next log line contains the author
215                       
216                        $nextParserState = "readRevisionInfo";
217                        # print "$file: contribution found $rev1 < $rev <= $rev2\n";
218
219                    }
220                   
221                       
222                } else {
223                    print "Encountered error while parsing file\n";
224                    exit;
225                } # if ($log
226            } # if (parserState
227
228
229            $parserState = $nextParserState;
230           
231        } # foreach $log  line
232       
233
234    } # for each file
235
236    # sort list of authors in alphabetical order
237    @authors = sort (@authors);
238
239    foreach $author (@authors){
240        $workReportContent .= "<tr class=\"work-author\"><td>$author</td></tr>\n";
241        @workComments = split /EndOfComment\n/, $workByAuthor{$author}; # "EndOfComment" is our specific beacon
242
243        @cleanedWorkComments =();
244        # remove multiple entries, e.g. occuring when several files are commited at the same time
245        SCAN_COMMENTS: foreach $comment (@workComments){
246            foreach $registeredComment (@cleanedWorkComments){
247                if ($comment eq $registeredComment){
248                    next SCAN_COMMENTS;
249                }
250            }
251            @cleanedWorkComments = ( @cleanedWorkComments, $comment);
252        }
253
254       
255        # new HTML table line for each comment
256        $oddOrEven = "even";
257        foreach $comment (@cleanedWorkComments){
258
259            $workReportContent .= "<tr class=\"work-log-$oddOrEven\"><td>$comment</td></tr>\n";
260
261            if ($oddOrEven eq "even"){
262                $oddOrEven = "odd";
263            } else {
264                $oddOrEven = "even";
265            }
266
267        }
268    }
269
270    my $endTime = localtime; # note that startTime defined outside this subroutine
271
272    # create web page
273    my $html = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">';
274    $html .= "<html>\n";
275    $html .= "<head>\n";
276    $html .= "<title>Work log between releases $rel1 and $rel2 </title>\n";
277    $html .= "<link rel=stylesheet href=\"./MadTestWebStyle.css\" type=\"text/css\">"; # CSS stylesheet at same level
278    $html .= "</head>\n";
279    $html .= "<!-- automatically generated by the MAD test script -->\n";
280    $html .= "<body>\n";
281    $html .= "<p>Work log between releases $rel1 and $rel2 </p>\n";   
282    $html .= "<p>Log report started $startTime, ended $endTime</p>\n";
283    $html .= "<table width=\"75%\" border=\"0\">\n";
284    $html .= $workReportContent;
285    $html .= "</table>\n";
286    $html .= "</body>\n";
287    $html .= "</html>\n";
288
289
290    print "closing $workReportFile\n";
291
292    print WORKFILE $html;
293    close WORKFILE;
294
295} # sub
Note: See TracBrowser for help on using the repository browser.