Added some code to peer into a data structure in Maemian/Schedule.pm. Also added the
[maemian] / nokia-lintian / checks / po-debconf
1 # po-debconf -- lintian check script -*- perl -*-
2
3 # Copyright (C) 2002-2004 by Denis Barbier <barbier@linuxfr.org>
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program.  If not, you can find it on the World Wide
17 # Web at http://www.gnu.org/copyleft/gpl.html, or write to the Free
18 # Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
19 # MA 02110-1301, USA.
20
21 package Lintian::po_debconf;
22 use strict;
23 use Tags;
24 use Util;
25
26 sub run {
27
28 my $pkg = shift;
29 my $type = shift;
30
31 # First, check wether this package seems to use debconf but not po-debconf.
32 # Read the templates file and look at the template names it provides, since
33 # some shared templates aren't translated.
34 opendir(DEB, 'debfiles')
35         or fail("Can't open debfiles directory.");
36 my $has_template = my $has_depends = my $has_config = 0;
37 my @lang_templates;
38 for my $file (readdir(DEB)) {
39         next if -d "debfiles/$file";
40         if ($file =~ m/^(.+\.)?templates(\..+)?$/) {
41                 if ($file =~ m/templates\.\w\w(_\w\w)?$/) {
42                         push (@lang_templates, $file);
43                 } else {
44                         open(PO, '<', "debfiles/$file")
45                                 or fail("Can't open debfiles/$file file.");
46                         while (<PO>) {
47                                 tag "translated-default-field", "$file: $."
48                                         if (m/^_Default(Choice)?: [^\[]*$/);
49                                 if (/^Template: (\S+)/i) {
50                                         my $template = $1;
51                                         next if $template =~ m,^shared/packages-(wordlist|ispell)$,;
52                                         next if $template =~ m,/languages$,;
53                                         $has_template = 1;
54                                 }
55                         }
56                         close PO;
57                 }
58         }
59 }
60 closedir(DEB);
61
62 #TODO: check whether all templates are named in TEMPLATES.pot
63 if ( $has_template ) {
64     if ( ! -d "debfiles/po" ) {
65         tag "not-using-po-debconf", "";
66         return 0;
67     }
68 } else {
69     return 0;
70 }
71
72 # If we got here, we're using po-debconf, so there shouldn't be any stray
73 # language templates left over from debconf-mergetemplate.
74 for (@lang_templates) {
75     tag "stray-translated-debconf-templates", $_ unless /templates\.in$/;
76 }
77
78 # yada builds its template and po/POTFILES.in dynamically at build time, so
79 # excuse yada from some of these checks (including the out of date templates
80 # check).
81 my $missing_files = 0;
82 my $yada = 0;
83 if (open (RULES, '<', 'debfiles/rules')) {
84     local $_;
85     while (<RULES>) {
86         if (m%^\t\s*(?:perl debian/)?yada\s%) {
87             $yada = 1;
88             $missing_files = 1;
89         }
90     }
91 }
92
93 if (!$yada && -f "debfiles/po/POTFILES.in") {
94         open(POTFILES, '<', "debfiles/po/POTFILES.in")
95                 or fail("Can't open debfiles/po/POTFILES.in.");
96         while (<POTFILES>) {
97                 chomp;
98                 s/.*\]\s*//;
99                 #  Cannot check files which are not under debian/
100                 next if m,^\.\./, or $_ eq '';
101                 unless (-f "debfiles/$_") {
102                         tag "missing-file-from-potfiles-in", "$_";
103                         $missing_files = 1;
104                 } 
105         }
106         close(POTFILES);
107 } elsif (!$yada) {
108         tag "missing-potfiles-in", "";
109         $missing_files = 1;
110 }
111 if (! -f "debfiles/po/templates.pot") {
112         tag "missing-templates-pot", "";
113         $missing_files = 1;
114 }
115
116 if (-x "/usr/bin/msgcmp" && -x "/usr/share/intltool-debian/intltool-update" ) {
117         if ($missing_files == 0) {
118                 $ENV{"INTLTOOL_EXTRACT"} ||= "/usr/share/intltool-debian/intltool-extract";
119                 system_env("cd debfiles/po && /usr/share/intltool-debian/intltool-update --gettext-package=test --pot");
120                 system_env("/usr/bin/msgcmp --use-untranslated debfiles/po/test.pot debfiles/po/templates.pot >/dev/null 2>&1"
121                            . "&& /usr/bin/msgcmp --use-untranslated debfiles/po/templates.pot debfiles/po/test.pot >/dev/null 2>&1") == 0
122                         or tag "newer-debconf-templates";
123         }
124 } else {
125         fail("either msgcmp or intltool-update not found");
126 }
127
128 if (! -x "/usr/bin/msgfmt" ) {
129         fail("msgfmt not found");
130 }
131 opendir(DEBIAN, 'debfiles/po')
132         or fail("Can't open debfiles/po directory.");
133 while (defined(my $file=readdir(DEBIAN))) {
134         next unless $file =~ m/\.po$/;
135         tag "misnamed-po-file", "debian/po/$file"
136                 unless ($file =~ /^[a-z]{2,3}(_[A-Z]{2})?\.po$/);
137         local ($/) = "\n\n";
138         $_ = '';
139         open(PO, '<', "debfiles/po/$file")
140                 or fail("Can't open debfiles/po/$file file.");
141         while (<PO>) {
142                 last if m/^msgstr/m;
143         }
144         close(PO);
145         unless ($_) {
146                 tag "invalid-po-file", "debian/po/$file";
147                 next;
148         }
149         s/"\n"//g;
150         my $charset = '';
151         if (m/charset=(.*?)\\n/) {
152                 $charset = ($1 eq 'CHARSET' ? '' : $1);
153         }
154         tag "unknown-encoding-in-po-file", "debian/po/$file"
155                 unless length($charset);
156         system_env("msgfmt -o /dev/null debfiles/po/$file 2>/dev/null") == 0
157                 or tag "invalid-po-file", "debian/po/$file";
158 }
159
160 }
161
162 1;
163
164 # Local Variables:
165 # indent-tabs-mode: t
166 # cperl-indent-level: 8
167 # End:
168 # vim: syntax=perl