From 5f0f67595919b63f927e0cc2707d82057ce2958a Mon Sep 17 00:00:00 2001 From: Steve McIntyre Date: Thu, 31 May 2018 11:56:33 +0100 Subject: Add an extra option to stattrans.pl to repair broken commit hashes Add -r to fix up the errors. In such cases, we update the header in the translated file to refer to the latest version of the original. --- stattrans.pl | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) (limited to 'stattrans.pl') diff --git a/stattrans.pl b/stattrans.pl index ab110bac63e..63bc0df6e57 100755 --- a/stattrans.pl +++ b/stattrans.pl @@ -41,9 +41,11 @@ $opt_v = 0; $opt_d = "u"; $opt_l = undef; $opt_b = ""; # Base URL, if not debian.org +# Should we try to repair any broken translation hash references? +$opt_r = 0; # path of web stats JSON data $opt_f = "/srv/www.debian.org/webwml/stats.json"; -getopts('h:w:b:p:t:vd:l:f:') || die; +getopts('h:w:b:p:t:vd:l:f:r') || die; # Replace filename globbing by Perl regexps $opt_p =~ s/\./\\./g; $opt_p =~ s/\?/./g; @@ -57,6 +59,7 @@ $opt_p =~ s/$/\$/g; 'verbose' => $opt_v, 'difftype'=> $opt_d, 'hit_file'=> $opt_f, + 'repair' => $opt_r, ); my $VCSHOST = "salsa"; @@ -231,6 +234,27 @@ sub get_color } } +# Update the translation-check metadata header in a wml file +sub update_file_metadata +{ + my $file = shift; + my $revision = shift; + my $hash = shift; + my $text = ""; + + open (IN, "< $file") or die "Can't open $file for reading: $!\n"; + while () { + if (m/^#use wml::debian::translation-check/) { + s/(translation="?)($revision)("?)/$1$hash$3/; + } + $text .= $_; + } + close(IN); + open(OUT, "> $file") or die "Can't open $file for writing: $!\n"; + print OUT $text; + close OUT; +} + sub check_translation { my ($translation, $version, $file, $orig_file) = @_; @@ -244,7 +268,15 @@ sub check_translation # From translation-check.wml my $version_diff = $VCS->count_changes($orig_file, $translation, $version); if (!defined $version_diff) { - print "check_translation: error from count_changes for orig_file $orig_file, file $file\n"; + print "check_translation: error from count_changes() for orig_file $orig_file, file $file\n"; + if ($config{'repair'}) { + # Replace the translation reference with the most + # recent version of the original? Yes, they're all + # either really old or files with only one commit... + my $latest_rev_orig = $VCS->get_newest_revision($orig_file); + print " fixing: using rev $latest_rev_orig instead of $translation\n"; + update_file_metadata($file, $translation, $latest_rev_orig); + } } else { if ($version_diff < 0) { return 'Wrong translation version'; -- cgit v1.2.3