[Debian-l10n-commits] r1791 - in /dl10n/trunk: Changelog dl10n-pts html/fuzzy.png html/translated.png html/untranslated.png

nekral-guest at users.alioth.debian.org nekral-guest at users.alioth.debian.org
Wed Jul 22 00:18:43 UTC 2009


Author: nekral-guest
Date: Wed Jul 22 00:18:41 2009
New Revision: 1791

URL: http://svn.debian.org/wsvn/?sc=1&rev=1791
Log:
	* dl10n-pts, html/translated.png, html/fuzzy.png,
	html/untranslated.png: Added script to generate translation
	statistics for the PTS.

Added:
    dl10n/trunk/dl10n-pts   (with props)
    dl10n/trunk/html/fuzzy.png   (with props)
    dl10n/trunk/html/translated.png   (with props)
    dl10n/trunk/html/untranslated.png   (with props)
Modified:
    dl10n/trunk/Changelog

Modified: dl10n/trunk/Changelog
URL: http://svn.debian.org/wsvn/dl10n/trunk/Changelog?rev=1791&op=diff
==============================================================================
--- dl10n/trunk/Changelog (original)
+++ dl10n/trunk/Changelog Wed Jul 22 00:18:41 2009
@@ -1,3 +1,9 @@
+2009-07-22  Nicolas François  <nicolas.francois at centraliens.net>
+
+	* dl10n-pts, html/translated.png, html/fuzzy.png,
+	html/untranslated.png: Added script to generate translation
+	statistics for the PTS.
+
 2008-04-19  Nicolas François  <nicolas.francois at centraliens.net>
 
 	* lib/Debian/L10n/BTS.pm (parse_submitter): Extract the submitter

Added: dl10n/trunk/dl10n-pts
URL: http://svn.debian.org/wsvn/dl10n/trunk/dl10n-pts?rev=1791&op=file
==============================================================================
--- dl10n/trunk/dl10n-pts (added)
+++ dl10n/trunk/dl10n-pts Wed Jul 22 00:18:41 2009
@@ -1,0 +1,365 @@
+#! /usr/bin/perl -w
+
+# dl10n-rrd -- Debian l10n PTS links
+#
+# Copyright (C) 2009 Nicolas François
+#
+# Based on dl10n-txt:
+# Copyright (C) 2004 Martin Quinson
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+
+use strict;
+use Getopt::Long; #to parse the args
+
+my $progname= $0; $progname= $& if $progname =~ m,[^/]+$,;
+
+my $VERSION = "1.0"; #External Version Number
+my $BANNER = "Debian l10n infrastructure -- PTS support v$VERSION"; # Version Banner - text form
+my $DB_FILE="./data/status";
+my $IGNORE_FILE='';
+my $GENDIR="l10n-pkg-status";
+my $STATUS_FILE='./data/status.$lang';
+my $assume_bts = 0;
+
+use Debian::L10n::Db;
+
+sub syntax_msg {
+    my $msg = shift;
+    if (defined $msg) {
+        print "$progname: $msg\n";
+    } else {
+        print "$BANNER\n";
+    }
+    print 
+"Syntax: $0 [options]
+General options:
+    -h, --help                display short help text
+    -V, --version             display version and exit
+
+Informations to display:
+    -a,--assume-bts           Assume that the content bugs in the BTS were
+                                applied.
+
+Database to use:
+    --db=DB_FILE              use DB_FILE as database file
+                                (instead of $DB_FILE)
+    --idb=IGNORE_FILE         use IGNORE_FILE as list of packages to ignore
+    --sdb=STATUS_FILE         use STATUS_FILE as status file
+                                (instead of $STATUS_FILE)
+    --gendir                  Generate the files in this directory
+";
+    if (defined $msg) {
+        exit 1;
+    } else {
+        exit 0;
+    }
+}
+
+# Display Version Banner
+# Options: -V|--version, --print-version
+sub banner {
+    if ($_[0] eq 'print-version') {
+        print "$VERSION\n";
+    } else {
+        print "$BANNER\n";
+    }
+    exit 0;
+}
+
+# Hash used to process commandline options
+my %opthash = (
+# ------------------ general options
+        "help|h"        => \&syntax_msg,
+        "version|V"     => \&banner,
+        "print-version" => \&banner,
+
+# ------------------ configuration options
+        "assume-bts|a"  => \$assume_bts,
+
+        "db=s"          => \$DB_FILE,
+        "idb=s"         => \$IGNORE_FILE,
+        "sdb=s"         => \$STATUS_FILE,
+
+        "gendir=s"      => \$GENDIR,
+        );
+
+# init commandline parser
+Getopt::Long::config('bundling', 'no_getopt_compat', 'no_auto_abbrev');
+
+# process commandline options
+GetOptions(%opthash)
+    or syntax_msg("error parsing options");
+
+#-----------------------------------------------------------------------------
+#                        The main program                                     
+#-----------------------------------------------------------------------------
+###
+### initialisation
+###
+
+my $data = Debian::L10n::Db->new();
+$data->read($DB_FILE);
+
+my %ignored_pkgs = ();
+if ($IGNORE_FILE) {
+    open IGNORE, "$IGNORE_FILE"
+        or die "Impossible to read the ignore file $IGNORE_FILE\n";
+    while (<IGNORE>) {
+        chomp;
+        next unless $_;
+        $ignored_pkgs{$_} = 1;
+    }
+    close IGNORE;
+}
+
+my @poparts=qw(podebconf po po4a); # Only POs, no template or man
+
+my %score;
+foreach my $pkg ($data->list_packages()) {
+    next if defined $ignored_pkgs{$pkg};
+
+    foreach my $part (@poparts) {
+        my $has_part="has_$part";
+        if ($data->$has_part($pkg)) {
+            foreach my $line (@{$data->$part($pkg)}){
+                my ($pofile, $lang, $stat) = @{$line};
+                if (defined $lang and length $lang) {
+                    $score{$pkg}{$lang}{$part} =
+                        add_stat($stat, $score{$pkg}{$lang}{$part});
+                }
+            }
+
+            unless (defined $score{$pkg}{'_'}{$part}) {
+                # If there is no POT file, try to find the number of strings
+                # from the other POs. This is usually a sign for non up to date
+                # PO files, so the number of strings in the PO files may vary.
+                # I choose to take the greatest number.
+                my $t = 0;
+                foreach my $lang (keys %{$score{$pkg}}) {
+                    if (    (defined $score{$pkg}{$lang}{$part})
+                        and (tot($score{$pkg}{$lang}{$part}) > $t)) {
+                        $t = tot($score{$pkg}{$lang}{$part});
+                    }
+                }
+                $score{$pkg}{'__'}{$part} = "0t0f".$t."u";
+            } else {
+                $score{$pkg}{'__'}{$part} = $score{$pkg}{'_'}{$part};
+            }
+        }
+    }
+}
+
+my %global_score;
+foreach my $pkg (keys %score) {
+    foreach my $lang (keys %{$score{$pkg}}) {
+        if ($lang ne "_" and $lang ne "__") {
+            foreach my $part (keys %{$score{$pkg}{$lang}}) {
+                if ($part eq "podebconf") {
+                    $global_score{$pkg}{debian} =
+                        add_stat ($score{$pkg}{$lang}{$part},
+                                  $global_score{$pkg}{debian});
+                } elsif ($part eq "po") {
+                    # FIXME: use heuristics or control field
+                    $global_score{$pkg}{nondebian} =
+                        add_stat ($score{$pkg}{$lang}{$part},
+                                  $global_score{$pkg}{nondebian});
+                } elsif ($part eq "po4a") {
+                    $global_score{$pkg}{debian} =
+                        add_stat ($score{$pkg}{$lang}{$part},
+                                  $global_score{$pkg}{debian});
+                }
+            }
+        }
+    }
+}
+open PKGLIST, ">$GENDIR/pkglist"
+    or die "Cannot open $GENDIR/pkglist: $!";
+print PKGLIST "# <package> <version> (<comma sperated scores>) <link>\n";
+foreach my $pkg (keys %global_score) {
+    my $pkgstatus = pkg_letter($pkg)."/$pkg.html";
+    next unless (   (    (defined $global_score{$pkg}{debian})
+                     and ($global_score{$pkg}{debian} ne "0t0f0u"))
+                 or (    (defined $global_score{$pkg}{nondebian})
+                     and ($global_score{$pkg}{nondebian} ne "0t0f0u")));
+    print PKGLIST "$pkg ".
+                  $data->version($pkg).
+                  " (".
+                  output_percent($global_score{$pkg}{debian}).
+                  ",".
+                  output_percent($global_score{$pkg}{nondebian}).
+                  ") ".
+                  "http://i18n.debian.org/l10n-pkg-status/$pkgstatus".
+                  "\n";
+    $pkgstatus = "$GENDIR/".$pkgstatus;
+    unless (-d "$GENDIR/".pkg_letter($pkg)) {
+        mkdir "$GENDIR/".pkg_letter($pkg);
+    }
+    open PKGSTATUS,">$pkgstatus"
+        or die "Cannot open $pkgstatus: $!";
+    print PKGSTATUS
+    "<html><body><table><tr><th>Language</th><th>podebconf</th><th>po</th><th>po4a</th></tr>\n";
+    foreach my $lang (sort keys %{$score{$pkg}}) {
+        if ($lang ne "_" and $lang ne "__") {
+            print PKGSTATUS "<tr><td>$lang</td><td>".
+                            graph_stats($score{$pkg}{$lang}{"podebconf"}).
+                            "</td><td>".
+                            graph_stats($score{$pkg}{$lang}{"po"}).
+                            "</td><td>".
+                            graph_stats($score{$pkg}{$lang}{"po4a"}).
+                            "</td></tr>\n";
+        }
+    }
+    print PKGSTATUS "</table></body></html>";
+    close PKGSTATUS
+        or die "Cannot close $pkgstatus: $!";
+}
+close PKGLIST
+    or die "Cannot close $GENDIR/pkglist: $!";
+
+sub pkg_letter {
+    my $pkg = shift;
+    if ($pkg =~ m/^(lib.)/) {
+        return $1;
+    }
+    
+    $pkg =~ s/^(.).*$/$1/;
+    return $pkg;
+}
+
+sub add_stat {
+    my $new=shift;
+    my $old=shift;
+
+    return $new unless ($old);
+    return $new if ($old eq '---');
+    $new =~ /([0-9]*)t([0-9]*)f([0-9]*)u/;
+    my ($nt,$nf,$nu) = ($1||0, $2||0, $3||0);
+    $old =~ /([0-9]*)t([0-9]*)f([0-9]*)u/;
+    my ($ot,$of,$ou) = ($1||0, $2||0, $3||0);
+    my $res= ($nt+$ot)."t".($nf+$of)."f".($nu+$ou)."u";
+    return $res;
+}
+
+my %statusDB;
+sub merge_bts_stats {
+    my $pkg = shift;
+    my $lang = shift;
+    my $part = shift;
+    my $stats = shift;
+    my $ori = shift;
+
+    return $stats unless $assume_bts;
+
+    unless (defined $statusDB{$lang}) {
+        my $statusDBname = "$STATUS_FILE";
+        $statusDBname =~ s/\$lang/$lang/g;
+
+        return $stats unless ( -f $statusDBname );
+
+        $statusDB{$lang} = Debian::L10n::Db->new();
+        $statusDB{$lang}->read($statusDBname,0);
+    }
+
+    return $stats unless (   $statusDB{$lang}->has_package($pkg)
+                          && $statusDB{$lang}->has_status($pkg));
+
+    my $bts_reported = 0;
+    foreach my $statusline (@{$statusDB{$lang}->status($pkg)}) {
+        my ($kind,$file,$date,$status_from_db,$translator,$url,$bug_nb) = @{$statusline};
+        if ($kind eq $part) {
+            if ($status_from_db =~ m/^(bts|done|hold|fix|wontfix)$/i) {
+                $bts_reported = 1;
+            } else {
+                $bts_reported = 0;
+                last;
+            }
+        }
+    }
+
+    if ($bts_reported) {
+        $ori =~ /([0-9]*)t([0-9]*)f([0-9]*)u/;
+        $stats = ($1+$2+$3)."t0f0u";
+    }
+
+    return $stats;
+}
+
+sub tot {
+    my $stats = shift;
+    return 0 unless $stats;
+    return 0 if $stats eq "---";
+    my $t = "0";
+    my $f = "0";
+    my $u = "0";
+
+    if ($stats =~ /([0-9]+)t/) {  $t=$1;  }
+    if ($stats =~ /([0-9]+)f/) {  $f=$1;  }
+    if ($stats =~ /([0-9]+)u/) {  $u=$1;  }
+
+    return $t+$f+$u;
+}
+
+sub output_percent {
+    my $stats=shift||"";
+    my $t = "0";
+    my $u = "0";
+    my $f = "0";
+    my $percent;
+
+    if ($stats =~ /([0-9]*)t/) {  $t=$1;  }
+    if ($stats =~ /([0-9]*)u/) {  $u=$1;  }
+    if ($stats =~ /([0-9]*)f/) {  $f=$1;  }
+    $percent = calc_percent($t,$t+$u+$f);
+    if ($percent eq "NaN" || $percent == 0) {
+        return '-';
+    }
+    return "$percent";
+}
+
+sub calc_percent{
+    my $up=shift;
+    my $down=shift;
+    my $res;
+
+    if ($down==0) {
+        return "NaN";
+    }
+    $res = $up/$down*100;
+    $res =~ s/^([0-9]*)\..*/$1/;
+    return $res;
+}
+
+sub graph_stats {
+    my $stats = shift||"";
+
+    my %s = (
+        translated   => 0,
+        untranslated => 0,
+        fuzzy        => 0);
+
+    if ($stats =~ /([0-9]*)t/) {  $s{translated}=$1;  }
+    if ($stats =~ /([0-9]*)u/) {  $s{untranslated}=$1;  }
+    if ($stats =~ /([0-9]*)f/) {  $s{fuzzy}=$1;  }
+
+    my $total = scalar ($s{translated} + $s{untranslated} + $s{fuzzy});
+
+    return "" if $total == 0;
+
+    my $graph = "";
+    foreach my $type (qw/translated fuzzy untranslated/) {
+        my $pcent = scalar ($s{$type} * 100 / $total);
+        my $width = scalar ($s{$type} * 100 / $total);
+        $graph .= "<img height=\"10\" src=\"../img/$type.png\" ";
+        $graph .= "style=\"height: 1em;\" ";
+        $graph .= "width=\"$width\" ";
+        $graph .= "alt=\"$pcent% $type (".$s{$type}."/$total), \" ";
+        $graph .= "title=\"$type: $pcent% (".$s{$type}."/$total)\"/>";
+    }
+
+    return $graph;
+}

Propchange: dl10n/trunk/dl10n-pts
------------------------------------------------------------------------------
    svn:executable = *

Added: dl10n/trunk/html/fuzzy.png
URL: http://svn.debian.org/wsvn/dl10n/trunk/html/fuzzy.png?rev=1791&op=file
==============================================================================
Binary file - no diff available.

Propchange: dl10n/trunk/html/fuzzy.png
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: dl10n/trunk/html/translated.png
URL: http://svn.debian.org/wsvn/dl10n/trunk/html/translated.png?rev=1791&op=file
==============================================================================
Binary file - no diff available.

Propchange: dl10n/trunk/html/translated.png
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: dl10n/trunk/html/untranslated.png
URL: http://svn.debian.org/wsvn/dl10n/trunk/html/untranslated.png?rev=1791&op=file
==============================================================================
Binary file - no diff available.

Propchange: dl10n/trunk/html/untranslated.png
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream




More information about the Debian-l10n-commits mailing list