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

Contents of /webwml/smart_change.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.8 - (show annotations) (download)
Fri Nov 5 20:39:07 2010 UTC (2 years, 7 months ago) by taffit-guest
Branch: MAIN
CVS Tags: HEAD
Changes since 1.7: +1 -1 lines
File MIME type: text/plain
Make smart_change.pl src-friendly
1 #!/usr/bin/perl -w
2
3 # This script perform changes in WML source files and bump version
4 # number when translated files are up to date.
5
6 # Known Issues:
7 # when there is no change to the origfile the translation="" revision is
8 # updated for current translations nevertheless
9
10 use strict;
11 use Getopt::Long;
12
13 # These modules reside under webwml/Perl
14 use lib ($0 =~ m|(.*)/|, $1 or ".") ."/Perl";
15 use Local::Cvsinfo;
16 use Webwml::TransCheck;
17 use Webwml::Langs;
18
19 our ($opt_h, $opt_v, $opt_n, $opt_p, @opt_l, @opt_s);
20
21 sub usage {
22 print <<'EOT';
23 Usage: smart_change.pl [options] origfile [origfile ...]
24 Options:
25 -h, --help display this message
26 -v, --verbose run verbosely
27 -n, --no-bump do not bump translation-check headers
28 -p, --previous get previous CVS revision
29 -l, --lang=STRING process this language (may be used more than once)
30 -s, --substitute=REGEXP
31 Perl regexp applied to source files
32 (may be used more than once)
33 EOT
34 exit(0);
35 }
36
37 if (not Getopt::Long::GetOptions(qw(
38 h|help
39 v|verbose
40 n|no-bump
41 p|previous
42 l|lang=s@
43 s|substitute=s@
44 ))) {
45 warn "Try `$0 --help' for more information.\n";
46 exit(1);
47 }
48
49 $opt_h && usage;
50 die "Invalid number of arguments\n" unless @ARGV;
51
52 sub verbose {
53 print STDERR $_[0] . "\n" if $opt_v;
54 }
55
56 # We call constructor without argument. It means there must be a
57 # CVS/Repository file or program will abort.
58 if (not @opt_l) {
59 my $l = Webwml::Langs->new();
60 @opt_l = $l->names();
61 }
62
63 my $eval_opt_s = '1';
64 foreach (@opt_s) {
65 $eval_opt_s .= "; $_";
66 }
67 verbose("-s flags: $eval_opt_s");
68
69 my $substitute = eval "sub { \$_ = shift; $eval_opt_s; die \$@ if \$@; return \$_}";
70 die "Invalid -s option" if $@;
71
72 foreach my $argfile (@ARGV) {
73 $argfile =~ m+^(english.*)/(.*\.(wml|src))+ or die "unknown path '$argfile'";
74 my ($path, $file) = ($1, $2);
75
76 verbose("File: $argfile");
77 my $cvs = Local::Cvsinfo->new();
78 $cvs->options(matchfile => [ $file ]);
79 $cvs->readinfo($path);
80 my $origrev = $cvs->revision($argfile) || "1.0";
81 if ($opt_p) {
82 $origrev =~ s/(\d+)$/($1 - 1)/e;
83 }
84 verbose("Original revision: $origrev");
85
86 my $nextrev = $origrev;
87 $nextrev =~ s/(\d+)$/(1+$1)/e;
88 verbose("Next revision: $nextrev");
89
90 foreach my $lang (@opt_l) {
91 my $transfile = $argfile;
92 $transfile =~ s/^english/$lang/ || next;
93 next unless -f $transfile;
94 verbose("Now checking $transfile");
95
96 # Parse the translated file
97 my $transcheck = Webwml::TransCheck->new($transfile);
98 next unless $transcheck->revision() || $lang eq 'english';
99 my $langrev = $transcheck->revision();
100
101 my $origtext = '';
102 my $transtext = '';
103 open (TRANS, "< $transfile");
104 while (<TRANS>) {
105 $origtext .= $_;
106 if (m/^#use wml::debian::translation-check/ && !$opt_n &&
107 ($langrev eq $origrev || $langrev eq $nextrev)) {
108 # Also check for $nextrev in case this script
109 # is run several times
110 s/(translation="?)($origrev|$nextrev)("?)/$1$nextrev$3/;
111 verbose("Bump version number to $nextrev");
112 }
113 $transtext .= $_;
114 }
115 close (TRANS);
116 $transtext = &$substitute($transtext);
117 if ($origtext ne $transtext) {
118 verbose("Writing $transfile");
119 open (TRANS, "> $transfile");
120 print TRANS $transtext;
121 close (TRANS);
122 }
123 }
124 }

  ViewVC Help
Powered by ViewVC 1.1.5