Salut, version 0.6. Changement: si le nom du paquet n'est pas donné par le ddts, appelle apt-cache pour le trouver. Comme ca, ca marche meme tant que le ddts est cassé si vous avez apt qui pointe sur le bon endroit...
Bye, Mt.
#! /usr/bin/perl use strict; ### Config part # where to put all the files # Things you MUST change my $home="/home/mquinson/ddts"; my $mail_from='PLEASE PUT YOU ADDRESS HERE'; my $mail_dflt="Hello,\n\n" ."Voici ma relecture de ta traduction de description de paquet.\n" ."N'hesite pas à me contacter si certaines corrections te paraissent discutables.\n" ."Sinon, merci de renvoyer la version corrigée au ddts.\n" ."\nBye, Mt.\n"; # Things you can change my $debug=0; my $mail_title="[Relecture] description du paquet %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 my $version="0.6"; die "Please configure the script before\n" if $mail_from eq "PLEASE PUT YOU ADDRESS HERE"; if (! -d $home) { mkdir $home || die "Can't create $home. Is the script configured ?\n"; } sub parse_report { my $package; my $translator; my $desc; my $trans; my $lang; # Pass the mail header while (<>) { last if (m,^$,); } # Read all packages while (<>) { chomp; # print "$_"; # Read the translator name $translator=$_; $_=<>; chomp; $package=$_; last if $translator eq ""; print "Translator: $translator\n" if $debug; print "Package: $package\n" if $debug; $_=<>; if (m,^Description: (.*)$,) { $desc="$1\n"; while (<>) { if (m,^ ,) { $desc .= $_; } else { last; } } } print "Description: $desc\n" if $debug; if (m,^Description-(..)(_..)?: (.*)$,) { $lang="$1$2"; $trans="$3\n"; while (<>) { if (m,^ ,) { $trans .= $_; } else { last; } } } if (m,^$,) { if ($package eq "") { my $shortdesc=$desc; $shortdesc =~ s/\n.*//mg; open APT, "apt-cache search '$shortdesc'|"; $package = <APT>; chomp($package); $package =~ s/^([^ ]*) .*$/$1/; print "I guess '$shortdesc' referes to '$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"; } 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.="Description:$desc"; $str.="Description-$lang:$trans"; print "$str\n" if $debug; 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"; # 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"; 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 (!system "diff -u $pkg $pkg.$revext > $pkg.diff") { # empty diff unlink "$pkg.diff"; unlink "$pkg.$newmailext" if (-e "$pkg.$newmailext"); unlink "$pkg.$revext" if (-e "$pkg.$revext"); unlink "$pkg.$todoext" if (-e "$pkg.$todoext"); } else { $boundary="----------=_".scalar(time)."-$$-".$BCount++; open PKG, "$pkg" || die "Can't read $pkg\n"; $_ = <PKG>; chomp; s/Translator: //; open MAIL, ">$pkg.$newmailext"; print MAIL "To: $_\n"; print MAIL "From: $mail_from\n"; print MAIL "Subject: "; printf MAIL $mail_title,$pkg; print MAIL "\nMime-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_dflt\n\n" ."--$boundary\n" ."Content-Type: text/plain; charset=$mail_charset\n" ."Content-Disposition: attachment; filename=\"$pkg.diff\"\n\n"; # puts the diff open DIFF, "$pkg.diff"; while (<DIFF>) { print MAIL "$_"; } # Ends the mime stuff print MAIL "--$boundary--\n\n"; close DIFF; close MAIL || die "Can't write $pkg.newmailext\n"; close PKG; } } } } sub send_mails { die "Cannot read the content of $home: $! \n" unless opendir (PKGLIST,$home); print "ACHTUNG: I am now sending mails to the translators.\n" ." I will send these files:\n"; foreach (readdir(PKGLIST)) { next unless /\.$mailext$/; print " - $_\n"; } print "\nIf you made something wrong, you have a 15 seconds to press CTRL C\n"; sleep 15; # Do the job die "Cannot read the content of $home: $! \n" unless opendir (PKGLIST,$home); chdir $home || die "Can't chdir to $home: $!\n"; foreach (readdir(PKGLIST)) { next unless /\.$mailext$/; my $pkg = $_; $pkg =~ s/\.$mailext$//; open SENDMAIL, "| /usr/lib/sendmail -t -oi -oem"; open MAIL, "$pkg.$mailext"; open SENTMAIL, ">$pkg.$sentmailext"; while (<MAIL>) { print SENDMAIL $_; print SENTMAIL $_; } close SENDMAIL || die "Can't fork sendmail: $!\n"; close SENTMAIL || die "Can't copy mail to $pkg.$sentmailext: $!\n"; close MAIL; unlink "$pkg.$mailext"; print "Send file $pkg.$mailext\n"; } print "done\n"; } my $cmd=shift; if ($cmd eq "parse") { parse_report(); } elsif ($cmd eq "mail") { make_mails(); } elsif ($cmd eq "send") { send_mails(); } else { my $me=$0; $me=~s,^.*?/([^/]*)$,$1,; die "Usage $me [parse|mail|send]\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" ." send: send the pkg.mail files (which are edited version of pkg.newmail)\n" ."\n$me version $version\n"; }