#!/usr/bin/perl -w # # Perl script to create html snippets from activitymail output # # activity2snippet Copyright (C) Dorando 2003 # # WIP / / Initial release # # Permission is granted to redistribute this script under the terms of the # GNU General Public License http://www.gnu.org/copyleft/gpl.html use strict; my $version='WIP 27 May 2003'; # loading required modules use Getopt::Long qw(:config gnu_getopt); use Pod::Usage; use Date::Parse; use Date::Format; # defining global variables use vars qw( $opt_bugzilla $opt_config $opt_dummy %opt_dirs $opt_extendtime $opt_help $opt_module %opt_names $opt_prefix $opt_verbose ); # default values for options $opt_extendtime='%A %o %B, %Y at %T'; $opt_prefix="/home/cvs/"; # load an ArgvFile if this module is available, otherwise try a perl script if(eval 'require Getopt::ArgvFile qw(argvFile);') {argvFile(startupFilename => '.cvs2chrono', home=>1);} else{eval "require '$ENV{'HOME'}/.cvs2chrono'";} # parse command line options GetOptions('bugzilla|b=s' => \$opt_bugzilla, 'config|c=s' => \$opt_config, 'cvs|options=s' => \$opt_dummy, 'dir|directory=s' => \%opt_dirs, 'extendtime|e=s' => \$opt_extendtime, 'help|h|?' => \$opt_help, 'local|l' => \$opt_dummy, 'module|m=s' => \$opt_module, 'name=s' => \%opt_names, 'prefix|p' => \$opt_prefix, 'output|o' => \$opt_dummy, 'reverse|r' => \$opt_dummy, 'small|s' => \$opt_dummy, 'verbose|V:i' => \$opt_verbose, 'webcvs|w=s' => \$opt_dummy ) || pod2usage(1); # print usage if($opt_help){pod2usage(1)}; # load additional config file if($opt_config){eval "require '$opt_config'"}; # reading the message in my @lines=; # defining local variables my $length=@lines; my $i=0; my $logtext=""; my ($date,$author,$boundary); # go through the header until($lines[$i] eq "Log Message:\n" or $i >= $length) { if($lines[$i] =~ "Date: (.*)\n"){$date = str2time($1);} elsif($lines[$i] =~ "From: (.*)@") {$author = ($opt_names{$1} ? $opt_names{$1} : $1);} elsif($lines[$i] =~ "Content-Type: .*; boundary=\"(.*)\""){$boundary = $1;} $i++; } # if this is not a normal Log Messege, abort. Does happen on newdir if($lines[$i+1] ne "-----------\n"){exit;} $i=$i+2; # need to guess when the log message ends until($lines[$i+2] =~ "^------------{0,3}\n" or $lines[$i] eq "--$boundary\n" or $i >= $length) { # we don't want newlines at start so reset logtext if that happens if($logtext eq "\n"){$logtext="";} $logtext.=$lines[$i]; $i++; } # remove last newline chomp($logtext); # get module name my ($module) = $lines[$i+3] =~ "^ $opt_prefix(.+?)(/|:)"; # stop if we're in single module mode and this isn't the correct one if($opt_module and $module ne $opt_module){exit;}; # gather file list my %files; until($lines[$i] eq "--$boundary\n" or $i >= $length) { our ($dir, $state); if($lines[$i] =~ "^ $opt_prefix(.+?/|.*)(.*):\n"){$dir = $2} elsif($lines[$i] =~ "^ (.*)"){$files{"$dir\t$1"}=$state;} elsif($lines[$i] =~ "^(.*):\n"){$state = substr($1,0,1);} $i++; } # and lastly the revision info until($i >= $length) { if($lines[$i] =~ "^RCS file: $opt_prefix.+?/((.*)/|)(.*),v") { my $dir = $2; my $file = $3; my ($oldrev) = ( $lines[$i+1] =~ "retrieving revision (.*)\n"); my ($rev) = ( $lines[$i+2] =~ "retrieving revision (.*)\n"); $files{"$dir\t$file"}.="\t$oldrev\t$rev"; } $i++; } # convert date to nicer format and generate filename my $file = time2str("%Y%m%d%H%M%S%j%W", $date, "UTC"); $date = time2str($opt_extendtime, $date, "UTC"); # format the logtext $_=$logtext; s/&/&/g; s//>/g; s#\n#
#g; s#(http://.+?\.(jpg|jpeg|png|mng|gif))##g; if($opt_bugzilla){s{#([0-9]+)}{#$1}ig} $logtext=$_; my $currentdir="."; my $files; my $class=""; foreach (sort(keys %files)) { my ($dir, $file) = split ("\t",$_); if ($currentdir ne $dir) { if($files){$files.="\n"} $currentdir = $dir; $files.='['. ($opt_dirs{$dir} ? $opt_dirs{$dir} : $dir).']'; $class = ! $class; } my ($state,$rev1,$rev2) = split("\t",$files{$_}); if($state eq "A") { $files.="$file* "; } elsif($state eq "R") { $files.="$file "; } elsif($state eq "M") { $files.="$file "; } } $files.=''; use Fcntl; until(sysopen(SNIPPET,"snippets/$file", O_WRONLY | O_CREAT | O_EXCL)){$file.="0";} #FIXME Remove after test #print SNIPPET <<"HTMLHEADER"; # # # # #CVS Log # # # #
#HTMLHEADER #print SNIPPET "\n\n". # "\n". # "\n". # "\n". # "
$date by $author
$logtext Hello Hello Hello
Hello Hello Hello Hello HelloYO
\n"; # #print SNIPPET "". # "". # "$files\n". # "
$author
$date
$logtext
\n" #; # #FIXME print SNIPPET "\n\n". "\n". "\n". "$files\n". "
$date by $author
$logtext
\n"; close SNIPPET; __END__