/[webwml]/webwml/check_desc_trans.pl
ViewVC logotype

Contents of /webwml/check_desc_trans.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.6 - (hide annotations) (download)
Mon Sep 29 20:44:05 2008 UTC (4 years, 8 months ago) by bas
Branch: MAIN
Changes since 1.5: +2 -2 lines
File MIME type: text/plain
Use Local::VCS instead of Local::VCS_CVS
1 bas 1.4 #!/usr/bin/perl
2 peterk 1.1
3     # Check translation status for mailing list descriptions. Since these files
4     # aren't WML files, the translation data is stored in a separate file in
5     # each directory, listing the names of the files and the corresponding
6     # English version.
7     #
8     # Since I couldn't figure out how to add this to the regular check_trans.pl
9     # script, this is a separate script.
10     #
11     # To use this script, create a file called translation-check in each
12     # directory under <language>/MailingLists/desc/. In it you list the name of
13     # the translated file and the version of the English original, separated by
14     # whitespace. Then run this script, and it will tell you about which files
15     # are missing, which files are outdated, and if there are files translating
16     # files that are no longer in the English directory.
17     #
18 bas 1.4 # The language to check can be specified on the command line, in
19     # language.conf, or in the DWWW_LANG environment variable.
20     #
21     # Originally written 2002-10-05 by Peter Karlsson <peterk@debian.org>
22 bas 1.5 # © Copyright 2002-2007 Software in the public interest, Inc.
23 bas 1.4 # Complete rewrite 2008 by Bas Zoetekouw <bas@debian.org>
24 bas 1.5 # © Copyright 2008 by Bas Zoetekouw <bas@debian.org>
25 bas 1.4 #
26     # This program is free software; you can redistribute it and/or modify it
27     # under the terms of version 2 of the GNU General Public License as published
28     # by the Free Software Foundation.
29     #
30    
31 bas 1.6 # $Id: check_desc_trans.pl,v 1.6 2008/09/29 20:44:05 bas Exp $
32 bas 1.4
33     use FindBin;
34     use lib "$FindBin::Bin/Perl";
35    
36     use File::Basename;
37     use File::Spec::Functions;
38     use File::Find::Rule;
39     use List::MoreUtils qw{ uniq };
40     use Term::ANSIColor;
41 peterk 1.1
42 bas 1.6 use Local::VCS ':all';
43 peterk 1.1
44 bas 1.4 use strict;
45     use warnings;
46 peterk 1.1
47 bas 1.4 # Get language configuration
48     my $language;
49     if ( $ARGV[0] )
50     {
51     $language = $ARGV[0];
52     }
53     elsif (exists $ENV{DWWW_LANG})
54 peterk 1.1 {
55     $language = $ENV{DWWW_LANG};
56     }
57 bas 1.4 elsif ( open( my $conf, '<', 'language.conf' ) )
58 peterk 1.1 {
59 bas 1.4 while ( my $line = <$conf> )
60 peterk 1.1 {
61 bas 1.4 next if $line =~ /^#/;
62     chomp $line ;
63     $language = $line;
64     last;
65 peterk 1.1 }
66 bas 1.4
67     close $conf;
68 peterk 1.1 }
69    
70     die "Language not defined in DWWW_LANG or language.conf\n"
71     unless defined $language;
72 bas 1.4 die "Language `$language' doesn't exist\n"
73     unless -d $language;
74 peterk 1.1
75 peterk 1.2 # Counters
76 bas 1.4 my $old = 0;
77     my $uptodate = 0;
78     my $unknown = 0;
79     my $needtranslation = 0;
80    
81     # directories
82     my $directory = catdir( 'MailingLists' , 'desc' );
83     my $srcdir = catdir( 'english', $directory );
84     my $destdir = catdir( $language, $directory );
85    
86     # read svn info about files in source dir
87     my %revision_info = vcs_path_info( $srcdir, 'recursive' => 1 );
88 peterk 1.1
89 bas 1.4 # read the translation-check files in dest dir
90     my %transcheck = read_transcheck( $destdir );
91    
92     # check all files
93     my ($nr_uptodate,$nr_old,$nr_needtrans,$nr_obsolete,$nr_error) =
94     check_all( $language, $directory, \%transcheck, \%revision_info );
95    
96     # print results
97     print "\nResults:\n";
98     printf " %3i are up to date.\n", $nr_uptodate;
99     printf " %3i need to be updated.\n", $nr_old;
100     printf " %3i need to be translated.\n", $nr_needtrans;
101     printf " %3i are obsolete.\n", $nr_obsolete;
102     printf " %3i are broken.\n", $nr_error;
103    
104     exit 0;
105    
106    
107     #============================================================
108    
109    
110     # read in all transcheck files under the specified directory
111     sub read_transcheck
112 peterk 1.1 {
113 bas 1.4 my $dir = shift or die("No directory specified");
114    
115     # get a listof all translation-check files
116     my @files = File::Find::Rule->file()->name('translation-check')->in($dir);
117    
118     my %info;
119     foreach my $file (@files)
120     {
121     my $thisdir = dirname $file;
122    
123     # TODO: use a nice File::Spec function for this
124     $thisdir =~ s{^$dir/*}{} ;
125    
126     open( my $fd, '<', $file ) or die("Can't open `$file': $!\n");
127     while ( my $line = <$fd> )
128     {
129     chomp $line;
130    
131     # skip comments and empty lines
132     next if $line =~ m{^#};
133     next if $line =~ m{^\s+$};
134    
135     # read the file name and the revision from the file
136     my ($listfile,$revision) = split( /\s+/, $line, 2 );
137     warn "Couldn't parse line $. of $file\n" unless $revision;
138    
139     # prepend the directory name, if needed
140     my $thefile = $thisdir ? catfile( $thisdir, $listfile ) : $listfile;
141    
142     # save the data
143     $info{ $thefile } = $revision;
144     }
145     close( $fd );
146     }
147    
148     return %info;
149    
150     }
151    
152    
153     # check all translations
154     sub check_all
155     {
156     my $lang = shift or die("No language specified");
157     my $dir = shift or die("No directory specified");
158     my $files = shift or die("No transcheck files specified");
159     my $revinfo = shift or die("No revision info specified");
160    
161     die("Language `$lang' doesn't exists\n") unless -d $lang;
162    
163     my $source = catdir( 'english', $dir );
164     my $destination = catdir( $lang, $dir );
165    
166     # create a list of all files (note that the filenames are relative to the
167     # english and translated mailinglist directories)
168     my @allfiles = sort {$a cmp $b} uniq( keys %$files, keys %$revinfo );
169    
170     # counters
171     my ($nr_uptodate,$nr_old,$nr_obsolete,$nr_needtrans,$nr_error) = (0,0,0,0,0);
172    
173     foreach my $file ( @allfiles )
174     {
175     # special case, this doesn't need to be translated
176     next if $file eq 'README';
177    
178     my $file_english = catfile( 'english', $dir, $file );
179     my $file_transl = catfile( $lang, $dir, $file );
180    
181     # check if the info from vcs and from the fs are consistent
182     if ( -e $file_english and not exists $revinfo->{$file} )
183     {
184     warn "$file: english version found, but no revision info available!\n";
185     next;
186     }
187     # check if the info from translation-check and from the fs are consistent
188     if ( -e $file_transl and not exists $files->{$file} )
189     {
190     warn "$file: $lang version found, but not found in a translation-check file!\n";
191     next;
192     }
193    
194     # now check for out-of-dateness and other things
195     if ( -e $file_english and -e $file_transl )
196     {
197     # needs update
198     if ( vcs_cmp_rev( $files->{$file}, $revinfo->{$file}->{'cmt_rev'} ) == -1 )
199     {
200     $nr_old++;
201     print color('blue'), $file, color('reset');
202     printf ": needs to be updated from revision %s to revison %s\n",
203     $files->{$file}, $revinfo->{$file}->{'cmt_rev'};
204     }
205     # translated file is too new
206     elsif ( vcs_cmp_rev( $files->{$file}, $revinfo->{$file}->{'cmt_rev'} ) == -1 )
207     {
208     $nr_error++;
209     print color('blue'), $file, color('reset');
210     printf ": %s revision %s is larger than english revision %s\n",
211     $lang, $files->{$file}, $revinfo->{$file}->{'cmt_rev'};
212     }
213     # up to date!
214     else
215     {
216     $nr_uptodate++;
217     }
218     }
219     # file not translated yet
220     elsif ( -e $file_english )
221     {
222     $nr_needtrans++;
223     print color('blue'), $file, color('reset');
224     printf ": need to translate revision %s\n", $revinfo->{$file}->{'cmt_rev'};
225     }
226     # translation exists, but original has been removed
227     elsif ( -e $file_transl )
228     {
229     $nr_obsolete++;
230     print color('blue'), $file, color('reset');
231     print ": no english file found!\n";
232     }
233     # weirdness
234     else
235     {
236     $nr_error++;
237     print color('blue'), $file, color('reset');
238     print ": Woopsie, neither english nor $lang file found\n";
239     next;
240     }
241     }
242    
243     return ($nr_uptodate,$nr_old,$nr_needtrans,$nr_obsolete,$nr_error);
244 peterk 1.1 }
245 bas 1.4
246     __END__

  ViewVC Help
Powered by ViewVC 1.1.5