/[d-i]/trunk/manual/scripts/doc-check
ViewVC logotype

Contents of /trunk/manual/scripts/doc-check

Parent Directory Parent Directory | Revision Log Revision Log


Revision 44153 - (show annotations) (download)
Sat Jan 13 20:50:15 2007 UTC (6 years, 4 months ago) by fjp
File size: 4032 byte(s)
Also support the case where a document revision is used together with a translation comment, as is the case for the Czech translation; we only check the first 10 lines of any document
1 #!/usr/bin/perl -w
2 #
3 # This script checks if the translations of the documents are up to date.
4 #
5
6 use Getopt::Std;
7 use File::Find;
8 $opt_d = $opt_h = $opt_r = $opt_s = $opt_v = $opt_V = 0;
9 getopts('hr:dsvV');
10 # You may set this to your default language code
11 $lang = shift || "pl";
12 if ($opt_r and $opt_r !~ /[0-9]+/) {
13 warn "Please enter a revision number for parameter -r.\n";
14 exit 1
15 }
16
17 sub usage
18 {
19 printf <<HERE, $lang;
20 Usage: $0 [options] [<language>]
21
22 -h print this help message.
23 -d print what has changed in the original since last translation.
24 -r <rev> take the diff against the revision number <rev> instead of the
25 latest revision of the English original.
26 -s show also all files marked untranslated.
27 -v be verbose.
28 -V be slightly more verbose.
29
30 Current <language> is '%s'.
31 HERE
32 exit 0;
33 }
34
35 sub checkdiff
36 {
37 my ($plfname, $enfname) = (@_);
38 my ($plrev, $enrev, $untrans) = getrev($plfname, $enfname);
39 $plrev and $enrev or return;
40 if ( "$plrev" ne "$enrev" ) {
41 if ($opt_d and $opt_r and $opt_r < $enrev) {
42 $enrev = $opt_r;
43 }
44 if ($untrans) {
45 print "$enfname : $plrev -> $enrev (untranslated)\n";
46 } else {
47 print "$enfname : $plrev -> $enrev\n";
48 }
49 if ($opt_d) {
50 my $s = "svn diff -r $plrev:$enrev $enfname";
51 warn "running $s:\n" if ($opt_V);
52 system($s);
53 }
54 } else {
55 if ($untrans && $opt_s) {
56 print "$plfname: untranslated\n";
57 }
58 }
59 }
60
61 sub getrev
62 {
63 my ($plfname, $enfname) = (@_);
64 my ($plrev, $enrev, $untrans, $notconverted) = (0, 0, 0, 0);
65 my $line = 0;
66
67 warn "checking $plfname:\n" if $opt_v;
68 open FILE, $plfname or warn "$plfname: $!\n" and return;
69 while (<FILE>) {
70 $line++;
71
72 # Also check for revision comments of original documents
73 # These may be used in combination with a translation comment in
74 # which case the translation comment overrules what's found here
75 if (($plrev == 0) && (/<!--\s*\$Id: \S+ (\d+) /)) {
76 $plrev = $1;
77 $notconverted = 1;
78 $untrans = 1;
79 }
80 if (/<!--\s*original version\D*([\d\.]+)\s*-->/) {
81 $plrev = $1;
82 $untrans = 0;
83 $notconverted = 0;
84 last;
85 }
86 if (/<!--\s*original version\D*(\d+)\s*untranslated\s*-->/) {
87 $plrev = $1;
88 $untrans = 1;
89 $notconverted = 0;
90 last;
91 }
92 # Also support CVS style revision comments (depreciated)
93 if (/<!--\s*original document: en\/\S+, revision ([\d\.]+)\s*-->/) {
94 $plrev = $1;
95 last;
96 }
97 if ($line++ > 10) {
98 last;
99 }
100 }
101 warn "checking $enfname:\n" if $opt_v;
102 open FILE, $enfname or warn "$enfname: $!\n" and return;
103 while (<FILE>) {
104 if (/\$Id: \S+ (\d+) /) {
105 $enrev = $1;
106 last;
107 }
108 # Also support CVS style revision comments (depreciated)
109 if (/\$Revision: (\d+) \$/) {
110 $enrev = $1;
111 last;
112 }
113 }
114 close FILE;
115 warn "failed to find revision for $plfname\n" unless $plrev;
116 warn "failed to find revision for $enfname\n" unless $enrev;
117 if ($notconverted) {
118 warn "$plfname: contains revision comment for original document\n";
119 warn " use 'rev-update' to convert\n";
120 }
121 return ($plrev, $enrev, $untrans);
122 }
123
124 sub process
125 {
126 my $enfname = $File::Find::name;
127 return unless $enfname =~ m/\.xml$/;
128 my $plfname = $enfname;
129 $plfname =~ s,^en/,$lang/,;
130 checkdiff($plfname, $enfname);
131 }
132
133 sub process_obsolete
134 {
135 my $plfname = $File::Find::name;
136 return unless $plfname =~ m/\.xml$/;
137 my $enfname = $plfname;
138 $enfname =~ s,^$lang/,en/,;
139 open FILE, $enfname or warn "$plfname: Probably obsoleted\n" and return;
140 close FILE;
141 }
142
143 usage() if $opt_h;
144
145 warn "\nChecking for outdated or missing translations...\n" if $opt_v;
146 File::Find::find({ wanted => \&process, no_chdir => 1 }, 'en');
147 warn "\nChecking for obsoleted translations...\n" if $opt_v;
148 File::Find::find({ wanted => \&process_obsolete, no_chdir => 1 }, $lang);
149
150 #checkdiff("build/install.$lang.xml", "build/install.en.xml");
151 #checkdiff("release-notes.$lang.sgml","release-notes.sgml");
152 #checkdiff("index.$lang.html.m4","index.en.html.m4");
153 #checkdiff("dselect-beginner.$lang.sgml","dselect-beginner.sgml");
154
155 warn "All done.\n" if $opt_v;

Properties

Name Value
svn:executable *
svn:keywords Id

  ViewVC Help
Powered by ViewVC 1.1.5