| 1 |
#!/usr/bin/perl
|
| 2 |
|
| 3 |
# This is a toy to compute the karma of translators in the Debian web site
|
| 4 |
# CVS repository.
|
| 5 |
|
| 6 |
# It use information about translation revisions please see
|
| 7 |
# http://www.debian.org/devel/website/uptodate
|
| 8 |
# it also need informations about the maintainer. Just add
|
| 9 |
# maintainer="Name"
|
| 10 |
# at the end of the wml::debian::translation-check template invocation
|
| 11 |
|
| 12 |
# This is GPL'ed code.
|
| 13 |
# Copyright 2002 Martin Quinson <martin.quinson@ens-lyon.fr>.
|
| 14 |
# Copyright 2008 Bas Zoetekouw <bas@debian.org>.
|
| 15 |
|
| 16 |
# Invocation:
|
| 17 |
# karma.pl [language]
|
| 18 |
# list of languages in webwml:
|
| 19 |
# english esperanto french japanese german arabic catalan bulgarian
|
| 20 |
# chinese croatian czech danish dutch farsi finnish greek hungarian
|
| 21 |
# indonesian italian korean lithuanian norwegian romanian russian
|
| 22 |
# slovene spanish swedish turkish
|
| 23 |
|
| 24 |
use File::Basename;
|
| 25 |
use File::Spec::Functions;
|
| 26 |
use FindBin;
|
| 27 |
|
| 28 |
# These modules reside under webwml/Perl
|
| 29 |
use lib "$FindBin::Bin/Perl";
|
| 30 |
use Local::VCS ':all';
|
| 31 |
use Local::WmlDiffTrans;
|
| 32 |
use Webwml::TransCheck;
|
| 33 |
use Webwml::TransIgnore;
|
| 34 |
|
| 35 |
use strict;
|
| 36 |
use warnings;
|
| 37 |
|
| 38 |
$| = 1;
|
| 39 |
|
| 40 |
# where to compute the Karma
|
| 41 |
my %Karma;
|
| 42 |
|
| 43 |
# include only files matching $filename
|
| 44 |
my $MATCH = '(\.wml$)|(\.html$)';
|
| 45 |
my $SKIP = '^template/';
|
| 46 |
|
| 47 |
# parse command line;
|
| 48 |
die("Please specify a language to examine\n") if not @ARGV;
|
| 49 |
my @DIRS = @ARGV;
|
| 50 |
foreach my $d (@DIRS)
|
| 51 |
{
|
| 52 |
$d =~ s{ /$ }{}x;
|
| 53 |
die("Language `$d' not found.\n") unless -d $d;
|
| 54 |
}
|
| 55 |
|
| 56 |
print "Reading data...";
|
| 57 |
|
| 58 |
my $lang_from = 'english';
|
| 59 |
my %info_from = vcs_path_info( $lang_from,
|
| 60 |
match_pat => $MATCH,
|
| 61 |
skip_pat => $SKIP,
|
| 62 |
recursive => 1,
|
| 63 |
verbose => 1
|
| 64 |
);
|
| 65 |
|
| 66 |
print "\n";
|
| 67 |
|
| 68 |
foreach my $subdir (@DIRS)
|
| 69 |
{
|
| 70 |
print "Examining $subdir...\n";
|
| 71 |
|
| 72 |
# find language from path
|
| 73 |
my ($lang_to) = $subdir =~ m{ ^ ([^/]+) }x;
|
| 74 |
die("No language found") unless $lang_to;
|
| 75 |
|
| 76 |
# remove the language from the subdir
|
| 77 |
$subdir =~ s{ ^ $lang_to /? }{}x;
|
| 78 |
|
| 79 |
|
| 80 |
# TODO: transignore
|
| 81 |
|
| 82 |
# fetch a list of all (translated) files in this subdir
|
| 83 |
my %info_to = vcs_path_info( catfile($lang_to,$subdir),
|
| 84 |
match_pat => $MATCH,
|
| 85 |
skip_pat => $SKIP,
|
| 86 |
recursive => 1,
|
| 87 |
verbose => 1
|
| 88 |
);
|
| 89 |
|
| 90 |
foreach my $file ( sort keys %info_to )
|
| 91 |
{
|
| 92 |
my $path = $subdir ? catfile( $subdir, $file ) : $file;
|
| 93 |
my $path_to = catfile( $lang_to, $path );
|
| 94 |
my $path_from = catfile( $lang_from, $path );
|
| 95 |
|
| 96 |
# NOTE: all keys in %info_from are relative to $WEBWML/english
|
| 97 |
# all keys in $info_to are relative to $WEBWML/$lang_to/$subdir
|
| 98 |
# so, use ONLY $info_from{$path} and ONLY $info_to{$file}
|
| 99 |
|
| 100 |
#print " ==> $file : $path : $path_to : $path_from\n";
|
| 101 |
|
| 102 |
# check if the english file exists
|
| 103 |
# (if not, the $path_to isn't a translation, so skip it )
|
| 104 |
next unless exists $info_from{$path};
|
| 105 |
|
| 106 |
# check if the translated file exists (if not, you've found a bug)
|
| 107 |
die("No such file `$path_to'") unless exists $info_to{$file};
|
| 108 |
|
| 109 |
# check if the file is in a transignore
|
| 110 |
my $dir = dirname($path_to);
|
| 111 |
my $transignore = new Webwml::TransIgnore->new($dir) or die;
|
| 112 |
if ( $transignore->is_local($path_to) or $transignore->is_global($path_to) )
|
| 113 |
{
|
| 114 |
#print "Ignoring $path_to\n";
|
| 115 |
next;
|
| 116 |
}
|
| 117 |
|
| 118 |
my $rev_from = $info_from{$path}->{'cmt_rev'} or die;;
|
| 119 |
|
| 120 |
check_file( \%Karma, $lang_to, $path_to, $path_from, $rev_from );
|
| 121 |
}
|
| 122 |
}
|
| 123 |
|
| 124 |
foreach my $translator (sort {$Karma{$b} <=> $Karma{$a}} keys %Karma)
|
| 125 |
{
|
| 126 |
printf "%s has a web karma of %s\n", $translator, $Karma{$translator};
|
| 127 |
}
|
| 128 |
|
| 129 |
exit 0;
|
| 130 |
|
| 131 |
|
| 132 |
sub check_file
|
| 133 |
{
|
| 134 |
my $karma = shift or die;
|
| 135 |
my $language = shift or die;
|
| 136 |
my $file_trans = shift or die;
|
| 137 |
my $file_orig = shift or die;
|
| 138 |
my $revision = shift or die;
|
| 139 |
|
| 140 |
return unless (-r $file_trans); # file_trans does not exists
|
| 141 |
|
| 142 |
my $transcheck = Webwml::TransCheck->new($file_trans);
|
| 143 |
my $oldr = $transcheck->revision() || 0;
|
| 144 |
|
| 145 |
my $translator = $transcheck->maintainer() || 'ANONYMOUS';
|
| 146 |
my $original = $transcheck->original();
|
| 147 |
|
| 148 |
return if $original; # if not, we'll loose karma if this page is badly translated
|
| 149 |
|
| 150 |
$translator = ucfirst($language) . " " . $translator;
|
| 151 |
$translator =~ s/^\s+ |\s+$//;
|
| 152 |
|
| 153 |
# calculate the number of revision the original english file has has
|
| 154 |
my $numrev = vcs_count_changes( $file_trans, undef, $revision );
|
| 155 |
# calculate the age of the translated file
|
| 156 |
my $age = vcs_count_changes( $file_orig, $oldr, $revision );
|
| 157 |
|
| 158 |
$karma->{$translator} += $numrev; # page translated. GOOD
|
| 159 |
$karma->{$translator} -= $numrev*$age/4; #out of date page; Bad
|
| 160 |
}
|
| 161 |
|
| 162 |
__END__
|
| 163 |
|
| 164 |
sub check_file {
|
| 165 |
my ($name, $revision,$translator) = @_;
|
| 166 |
my ($oldr, $oldname, $original);
|
| 167 |
my $docname = $name;
|
| 168 |
$docname =~ s#^$lang_to/##;
|
| 169 |
$docname =~ s#\.wml$##;
|
| 170 |
return unless (-r $name); # file does not exists
|
| 171 |
|
| 172 |
my $transcheck = Webwml::TransCheck->new($name);
|
| 173 |
$oldr = $transcheck->revision() || 0;
|
| 174 |
if (!$oldr && ($name =~ m#$lang_to/international/$lang_to#i)) {
|
| 175 |
# This document is original, check for
|
| 176 |
# english/international/$lang_to...
|
| 177 |
$name =~ s{^$to}{$from};
|
| 178 |
$transcheck = Webwml::TransCheck->new($name);
|
| 179 |
$oldr = $transcheck->revision() || 0;
|
| 180 |
}
|
| 181 |
$translator = $transcheck->maintainer();
|
| 182 |
$original = $transcheck->original();
|
| 183 |
$translator = "anonymous" unless $translator; # translator not found
|
| 184 |
$translator = ucfirst($to)." ".$translator;
|
| 185 |
|
| 186 |
$translator =~ s/^\s+//;
|
| 187 |
$translator =~ s/\s+$//;
|
| 188 |
$karma{$translator}=0 unless defined($karma{$translator});
|
| 189 |
$translator =~ s/^\s+//;
|
| 190 |
$translator =~ s/\s+$//;
|
| 191 |
|
| 192 |
return if $original; # if not, we'll loose karma if this page is badly translated
|
| 193 |
(my $numrev) = $revision =~ m/^1\.(\d+)$/; $numrev ||= "0";
|
| 194 |
(my $numoldr) = $oldr =~ m/^1\.(\d+)$/; $numoldr ||= "0";
|
| 195 |
my $age=$numrev - $numoldr;
|
| 196 |
# print "$translator: ";
|
| 197 |
# if ($age > 0) {
|
| 198 |
# print "NeedToUpdate $name from version 1.$numoldr to version 1.$numrev\n";
|
| 199 |
# } else {
|
| 200 |
# print "Uptodate $name\n";
|
| 201 |
# }
|
| 202 |
$karma{$translator} += $numrev; # page translated. GOOD
|
| 203 |
$karma{$translator} -= $numrev*$age/4; #out of date page; Bad
|
| 204 |
}
|
| 205 |
|
| 206 |
foreach my $translator (sort {$karma{$b} <=> $karma{$a}} keys %karma) {
|
| 207 |
print "$translator has a web karma of ".$karma{$translator}.".\n";
|
| 208 |
}
|