Bonjour, quelques correction de bogues : - ajout d'un compteur pour générer les nom des descriptions inconnues, comme ça on peut en traiter plusieurs dans la même seconde, sinon les première étaient écrasées ; - utilisation du champ « Date: » du rapport pour générer les noms des descriptions incunnues, ce qui permet d'analyser plusieurs fois le rapport en obtenant les mêmes noms de fichiers ; - ajout du chemin complet lorsqu'on renomme Paquet.relu en Paquet.relu.old ; - ajout du chemin complet lorsqu'on supprime Paquet.mailSent ; - suppression du fichier Paquet.tmp après utilisation ; - utilisation du nom « Paquet » et non « Paquet.tmp » pour générer le diff ; - suppression des fichier *.tmp avec l'option « clean ».
fonction supplémentaire : - ajout d'un fichier $desc_ok pour stocker les noms des paquets où on n'a plus de correction à faire, ce fichier généré quand on utilise l'option « mail ». Nicolas --
#! /usr/bin/perl use strict; ### Config part # where to put all the files # Things you MUST change my $home="/home/nico/Mail/rel/ddts/"; my $mail_from='Nicolas Bertolissio <[EMAIL PROTECTED]>'; my $mail_begin="Bonjour,\n\n" ."Tu trouveras en attachement un fichier diff entre la version que tu as\n" ."soumise au ddts et une version corrigée par mes soins de la description\n" ."de ce paquet. Si tu es d'accord avec les corrections, merci de renvoyer\n" ."une version corrigée au ddts. Dans le cas contraire, n'hésite pas à me\n" ."contacter.\n"; my $mail_end="\na+\n\nNicolas\n"; # Things you can change my $debug=0; # level of verbosity 0..2 my $desc_ok="$home/DescOk.txt"; # filename for ok description list my $comment=">> "; # comment string my $linenumber="ligne %d :"; # new comment line my $sendnew="no"; # if set to "yes", send the new description, not only the diff file my $selfsend="yes"; # if set to "yes", you will be sent a copy of outgoing mails my $mail_title="[relecture] %s"; # must contain %s my $mail_enc="8bits"; my $mail_charset="iso-8859-1"; my $todoext="todo"; # extention of files waiting for a review (*) my $revext="relu"; # extention of files you already reviewed my $newmailext="newmail"; # extention of newly created mail files (*) my $mailext="mail"; # extention of ready to be sent mail files my $sentmailext="mailSent"; # extention of mails sent (*) # files in category marked with (*) are automatically generated. # Don't edit them, change there name before it. ### End of the config part =head1 NAME ddts-rev - a tool to ease the work of reviewer of ddts =head1 SYNOPSIS ddts-rev [parse|mail|clean] =head1 DESCRIPTION This program helps the reviewer of package description translation with the ddts. Here is the basical review process if you use this tool: =over 4 =item o You get a daily report from the ddts, containing changed translations. Pass this mail to the standard input of this script, providing the I<parse> option. It will create two files called I<pkg-name> and I<pkg-name.todo> for each translation in the mail. The first one is the unchanged translation, for internal use. The second is a template to ease your review. =item o You do your review For that, rename I<pkg-name.todo> to I<pkg-name.relu>. Then, change the description found there, and add any comments you want in line starting with: '>> ' =item o You're done with the review and want to send your work to translators back. Call the script with the I<mail> option. It will make a diff of your version and the translators one. If the two versions are equal, nothing will be done. Else, the script will send a mail in mime format with three parts: =over 4 =item - the comments you've put between the COMMENTS lines =item - the version resulting of your review Just in case the translator lost it's original work =item - the diff between your version and the translator one. =back Then, the script will show you the resulting mail, and prompt you if you want to send it or not. Be carfull with sending mails. Please make sure you are really done with the review before. Lastly, the script will save the sent mail to I<pkg-name.mailSent> to make sure the mail won't be sent several times if you run the script several times. =item o clean your workspace Calling the script with the I<clean> option removes all temp files like *~ ones, or the ones created internally. If I<pkg-name.todo> and I<pkg-name.relu> both exists, the script will remove the first. So, be carfull when using this option... =back =cut my $version="0.9.1"; if (! -d $home) { mkdir $home || die "Can't create $home. Is the script configured?\n"; } sub parse_report { my $package; # package name my $translator; # translator address my $desc; # english description my $trans; # translated description my $lang; # language translated into my $nonamecount=0; # extention number for noname files my $reportId; # Message-Id field my $reportDate; # Date of ddts report # Read the mail header # Get the 'Message-Id:' field so we can use 'In-Reply-To:' when sending email while (<>) { last if (m,^$,); if (m,^Message-Id: ,) { chomp($reportId = substr($_, 12)); $debug && print "Message-Id: $reportId\n"; } if (m,^Date: ,) { chomp($reportDate = substr($_, 6)); } } # Read all packages while (<>) { # Read the translator name chomp; $translator=$_; $debug && print "Translator: $translator\n"; last if $translator eq ""; # Read the package name $_=<>; chomp; $package=$_; $debug && print "Package: $package\n"; $_=<>; # Read the english description if (m,^Description: (.*)$,) { $desc="$1\n"; while (<>) { if (m,^ ,) { $desc .= $_; } else { last; } } } $debug>1 && print "Description: $desc\n"; # Read the translated description if (m,^Description-(..)(_..)?: (.*)$,) { $lang="$1$2"; $trans="$3\n"; while (<>) { if (m,^ ,) { $trans .= $_; } else { last; } } } if (m,^$,) { # Search for package name if not provided by ddts if ($package eq "") { my $shortdesc=$desc; $shortdesc =~ s/\n.*//mg; $debug && print "short descritpion: $shortdesc\n"; open APT, "apt-cache search '$shortdesc'|"; $package = <APT>; chomp($package); $package =~ s/^([^ ]*) .*$/$1/; if ($package eq "") { print "I guess '$shortdesc' referes to '$package'\n"; } else { $package="noname-$reportDate-".$nonamecount++; print "I can't guess '$shortdesc', output file named '$package'\n"; } } if ($package eq "" || $translator eq "" || $desc eq "" || $trans eq "" || $lang eq "") { die "Parse error: empty line before the package is well defined.\n" ."Are you sure I'm parsing a repport from the ddts ?\n" .undef($package).":$package"; } if (-e "$home/$package.$todoext") { warn "$home/$package.$todoext overwritten...\n"; } # Outputs the package open PKG, ">$home/$package" || die "Can't open $home/$package\n"; open TODO, ">$home/$package.$todoext" || die "Can't open $home/$package.$todoext\n"; my $str = "Translator: $translator\n"; $str .= "ddts Id: $reportId\n"; $str .= "Description:$desc"; $str .= "Description-$lang:$trans"; $debug>1 && print "$str\n"; print PKG "$str\n"; print TODO "$str\n"; close PKG || die "Can't write '$home/$package': $!\n"; close TODO || die "Can't write '$home/$package.$todoext': $!\n"; # Move revext to revext.old if (-e "$home/$package.$revext") { print "Moving $package.$revext -> $package.$revext.old\n"; system ("mv $home/$package.$revext $home/$package.$revext.old"); } # Remove the mailSent if (-e "$home/$package.$sentmailext") { print "removing $home/$package.$sentmailext\n"; unlink "$home/$package.$sentmailext"; } # clears the variables $package=$translator=$desc=$trans=$lang = ""; } # stop when encountering the signature last if m,^--$,; last if m,^-- $,; } } sub make_mails { my $boundary; my $BCount=0; die "Cannot read the content of $home: $! \n" unless opendir (PKGLIST,$home); chdir $home || die "Can't chdir to $home: $!\n"; open OK, ">$desc_ok"; foreach (readdir(PKGLIST)) { next if /\.$todoext$/; next if /\.$revext$/; next if /\.diff$/; next if /\.$newmailext$/; next if /\.$mailext$/; next if /\.$sentmailext$/; my $pkg = $_; if (-e "$pkg.$revext" && -e "$pkg") { if (-e "$pkg.$sentmailext") { print "$pkg.$sentmailext exists. I won't send the same mail twice\n"; next; } $boundary="----------=_".scalar(time)."-$$-".$BCount++; # get translator name open PKG, "$pkg" || die "Can't read $pkg\n"; open PKGTMP, ">$pkg.tmp"; chomp(my $translator=<PKG>); $translator =~ s/Translator: //; chomp(my $reportid=<PKG>); $reportid =~ s/ddts Id: //; while (<PKG>) { print PKGTMP $_; } close PKGTMP; close PKG; # build the mail my $mail = "From: $mail_from\n"; if ($debug) { $mail .= "To: $mail_from\n"; } else { $mail .= "To: $translator\n"; } if ($selfsend eq "yes") { $mail .= "Cc: $mail_from\n"; } $mail .= "Subject: "; $mail .= sprintf $mail_title,$pkg; $mail .= "\nIn-Reply-To: $reportid\n"; $mail .= "Mime-Version: 1.0\n" ."Content-Type: multipart/mixed; boundary=\"$boundary\"\n" ."Content-Disposition: inline\n" ."Content-Transfer-Encoding: $mail_enc\n" ."User-Agent: ddts review helper\n\n\n" ."--$boundary\n" ."Content-Type: text/plain; charset=$mail_charset\n" ."Content-Disposition: inline\n" ."Content-Transfer-Encoding: $mail_enc\n\n" .$mail_begin; open REV, "$pkg.$revext"; <REV>; <REV>; # Prepare the diff and add the new version to the mail open TMP,">$pkg.new"; my $linecount=0; my $lastline=0; while (<REV>) { if (substr($_, 0, length($comment)) eq $comment) { if ($linecount!=$lastline) { $lastline=$linecount; $mail .= "\n".sprintf($linenumber, $linecount)."\n"; } $mail .= substr($_, length($comment)); } else { print TMP $_; $linecount++; } } close REV; close TMP; $mail .= $mail_end; if ($sendnew eq "yes") { $mail .= "\n\n" ."--$boundary\n" ."Content-Type: text/plain; charset=$mail_charset\n" ."Content-Disposition: attachment; filename=\"$pkg.new\"\n\n"; open TMP, "$pkg.new"; while (<TMP>) { $mail .= "$_"; } close TMP; } $mail .= "\n\n" ."--$boundary\n" ."Content-Type: text/plain; charset=$mail_charset\n" ."Content-Disposition: attachment; filename=\"$pkg.diff\"\n\n"; system "mv $pkg" "$pkg.tmp1"; system "mv $pkg.tmp" "$pkg" ; if (!system "diff -u $pkg $pkg.new > $pkg.diff") { # empty diff system "mv $pkg $pkg.tmp"; system "mv $pkg.tmp1 $pkg.tmp"; unlink "$pkg.diff"; unlink "$pkg.new"; unlink "$pkg.tmp"; print OK $pkg."\n"; } else { # puts the diff open DIFF, "$pkg.diff"; while (<DIFF>) { $mail .= "$_"; } close DIFF; # Ends the mime stuff $mail .= "--$boundary--\n\n"; print "Here is the mail:\n$mail\nDo you want to send it [y/N] ?\n"; $_=<>; if (m/^[yY]/) { open SENT, ">$pkg.$sentmailext"; print SENT $mail; close SENT || die "Can't save the mail to $pkg.$sentmailext: $!\n"; open SENDMAIL,"| /usr/lib/sendmail -t -oi -oem"; print SENDMAIL $mail; close SENDMAIL || die "Can't run sendmail: $!\n"; print "Mail sent\n"; } else { print "As you want. Nothing sent\n"; } } system "mv $pkg $pkg.tmp"; system "mv $pkg.tmp1 $pkg.tmp"; unlink "$pkg.new" unless $debug>1; unlink "$pkg.diff" unless $debug>1; unlink "$pkg.tmp" unless $debug>1; } } } sub clean { die "Cannot read the content of $home: $! \n" unless opendir (PKGLIST,$home); foreach (readdir(PKGLIST)) { if (/~$/ || /\.new$/ || /\.diff$/ || /\.tmp$/) { print "Remove $_\n"; unlink "$home/$_"; } if (! /\./) { my $pkg = $_; if (-e "$home/$pkg.$revext" && -e "$home/$pkg.$todoext") { print "Remove $pkg.$todoext\n"; unlink "$home/$pkg.$todoext"; } } } } my $cmd=shift; if ($cmd eq "parse") { parse_report(); } elsif ($cmd eq "mail") { make_mails(); } elsif ($cmd eq "clean") { clean(); } else { my $me=$0; $me=~s,^.*?/([^/]*)$,$1,; die "Usage $me [parse|mail|clean]\n" ." parse: read a ddts from the standard input and change the files in $home\n" ." mail: create the pkg.newmail files which you should edit and send\n" ." clean: remove : \n" ." - *~\n" ." - the $todoext when a $revext exists\n" ." - all tmp files (.diff, .newi, .tmp)\n" ."\n$me version $version\n"; } =head1 AUTHORS until version 0.7: Martin Quinson <[EMAIL PROTECTED]> present maintainer: Nicolas Bertolissio <[EMAIL PROTECTED]> =cut