diff options
author | Denis Barbier <barbier> | 2003-01-23 22:41:02 +0000 |
---|---|---|
committer | Denis Barbier <barbier> | 2003-01-23 22:41:02 +0000 |
commit | 8d51a48b769c88f012c40d631b594ffe69635ca9 (patch) | |
tree | 72652627e020d84623f53639a0b8d56972d4ce6c /smart_change.pl | |
parent | b47f45e808bfa8558756a8bbc74e5ac3014e8408 (diff) |
This script performs changes in English files and translations,
and bumps version number when they are up to date.
Example:
./smart_change.pl -s "s/foo/bar/" -s "s/baz/quux/" english/blah.wml
CVS version numbers
smart_change.pl: INITIAL -> 1.1
Diffstat (limited to 'smart_change.pl')
-rwxr-xr-x | smart_change.pl | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/smart_change.pl b/smart_change.pl new file mode 100755 index 00000000000..628075b424b --- /dev/null +++ b/smart_change.pl @@ -0,0 +1,107 @@ +#!/usr/bin/perl -w + +# This script perform changes in WML source files and bump version +# number when translated files are up to date. + +use strict; +use Getopt::Long; + +# These modules reside under webwml/Perl +use lib ($0 =~ m|(.*)/|, $1 or ".") ."/Perl"; +use Local::Cvsinfo; +use Webwml::TransCheck; +use Webwml::Langs; + +our ($opt_h, $opt_v, @opt_l, @opt_s); + +sub usage { + print <<'EOT'; +Usage: smart_change.pl [options] origfile +Options: + -h, --help display this message + -v, --verbose run verbosely + -l, --lang=STRING process this language (may be used more than once) + -s, --substitute=REGEXP + Perl regexp applied to source files + (may be used more than once) +EOT + exit(0); +} + +if (not Getopt::Long::GetOptions(qw( + h|help + v|verbose + l|lang=s@ + s|substitute=s@ +))) { + warn "Try `$0 --help' for more information.\n"; + exit(1); +} + +$opt_h && usage; + +sub verbose { + print STDERR $_[0] . "\n" if $opt_v; +} + +# We call constructor without argument. It means there must be a +# CVS/Repository file or program will abort. +if (not @opt_l) { + my $l = Webwml::Langs->new(); + @opt_l = $l->names(); +} + +my $argfile = $ARGV[0] or die "Invalid number of arguments"; +$argfile =~ m+^(english.*)/(.*\.wml)+ or die "pattern does not match"; +my ($path, $file) = ($1, $2); + +my $eval_opt_s = '1'; +foreach (@opt_s) { + $eval_opt_s .= "; $_"; +} +verbose("-s flags: $eval_opt_s"); +my $substitute = eval "sub { \$_ = shift; $eval_opt_s; die \$@ if \$@; return \$_}"; +die "Invalid -s option" if $@; + +my $cvs = Local::Cvsinfo->new(); +$cvs->options(matchfile => [ $file ]); +$cvs->readinfo($path); +my $origrev = $cvs->revision($argfile) || "1.0"; +verbose("Original revision: $origrev"); + +my $nextrev = $origrev; +$nextrev =~ s/(\d+)$/(1+$1)/e; +verbose("Next revision: $nextrev"); + +foreach my $lang (@opt_l) { + my $transfile = $argfile; + $transfile =~ s/^english/$lang/ || next; + next unless -f $transfile; + verbose("Now checking $transfile"); + + # Parse the translated file + my $transcheck = Webwml::TransCheck->new($transfile); + next unless $transcheck->revision(); + my $langrev = $transcheck->revision(); + + my $origtext = ''; + my $transtext = ''; + open (TRANS, "< $transfile"); + while (<TRANS>) { + $origtext .= $_; + if (m/^#use wml::debian::translation-check/ && + ($langrev eq $origrev || $langrev eq $nextrev)) { + # Also check for $nextrev in case this script + # is run several times + s/(translation="?)($origrev|$nextrev)("?)/$1$nextrev$3/; + verbose("Bump version number to $nextrev"); + } + $transtext .= &$substitute($_); + } + close (TRANS); + if ($origtext ne $transtext) { + open (TRANS, "> $transfile"); + print TRANS $transtext; + close (TRANS); + } +} |