~ubuntu-branches/ubuntu/lucid/dictionaries-common/lucid-201002122359

« back to all changes in this revision

Viewing changes to scripts/system/aspell-autobuildhash

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson
  • Date: 2005-09-02 13:39:19 UTC
  • mfrom: (1.1.1 sarge)
  • Revision ID: james.westby@ubuntu.com-20050902133919-1yjcebqd0y0op3tz
Tags: 0.49.2ubuntu1
scripts/system/dc-debconf-select.pl: Drop default question priority to
medium so that the default wordlist question is not asked on initial
installation. (This is a temporary workaround, and leaves a dangling
symlink in /usr/share/dict/words.)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl -w
 
2
# $Id: aspell-autobuildhash,v 1.5 2005/07/14 11:29:07 agmartin Exp $
 
3
#
 
4
#  script for aspell hash autorebuild in Debian systems
 
5
#
 
6
# (c) 2004-2005 Agustin Martin Domingo <agmartin@debian.org>
 
7
#
 
8
#
 
9
# This program is free software; you can redistribute it and/or modify
 
10
# it under the terms of the GNU General Public License as published by
 
11
# the Free Software Foundation; either version 2 of the License, or
 
12
# (at your option) any later version.
 
13
#
 
14
# This program is distributed in the hope that it will be useful,
 
15
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
# GNU General Public License for more details.
 
18
#
 
19
# You should have received a copy of the GNU General Public License
 
20
# along with this program; if not, write to the Free Software
 
21
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
22
#
 
23
 
 
24
sub usage {
 
25
    print STDERR "\nUsage:\taspell-autobuildhash [--debug] [--force]\n"
 
26
        . "\n"
 
27
        . "Options:\n"
 
28
        . "\t--debug         Show debugging information\n"
 
29
        . "\t--force         Do the job regardless of versions comparisons\n";
 
30
}
 
31
 
 
32
sub debugprint {
 
33
    print STDERR "@_\n" if $debug;
 
34
}
 
35
 
 
36
sub mymessage{
 
37
    my $message  = join(" ",@_);
 
38
    my $question = "dictionaries-common/ispell-autobuildhash-message";
 
39
    my $hashfile = '';
 
40
    
 
41
    if ( $lang ) {
 
42
        $hashfile = "$lang";
 
43
    } else {
 
44
        $hashfile = "dictionaries-common";
 
45
    }
 
46
 
 
47
    subst($question,"xxpell","aspell");
 
48
    subst($question,"XXpell","Aspell");
 
49
    subst($question,"hashfile",$hashfile);
 
50
    subst($question,"errormsg",$message);
 
51
    fset ($question,"seen","false");
 
52
    title("dictionaries-common: Running aspell-autobuildhash");
 
53
    input("critical",$question);
 
54
    go ();
 
55
}
 
56
 
 
57
sub myerror {
 
58
    mymessage @_;
 
59
    exit 1;
 
60
}
 
61
 
 
62
# ---------------------------------------------------------------------
 
63
#      Handle autorebuilding
 
64
# ---------------------------------------------------------------------
 
65
 
 
66
sub autorebuild {
 
67
    my $lang      = shift ||                              # The dictionary name
 
68
        myerror "No argument passed to function autorebuild";
 
69
    my $data      = "/usr/lib/aspell";                    # The data/lib dir
 
70
    my $langsfile = "/usr/share/aspell/$lang.contents";   # The subdicts file
 
71
    my @sublangs  = ();
 
72
    
 
73
    my $options   = "--dont-validate-affixes"      unless $debug;
 
74
    
 
75
    myerror "aspell data dir $data does not exist" unless ( -d $data );
 
76
    
 
77
    if ( -e $langsfile ){
 
78
        open (LANGSFILE, "< $langsfile") || die "Could not open $langsfile for reading";
 
79
        @sublangs = <LANGSFILE>;
 
80
        close LANGSFILE;
 
81
    } else {
 
82
        push @sublangs, $lang;
 
83
    }
 
84
    
 
85
    foreach ( @sublangs ){
 
86
        
 
87
        next if m/^[\t\s]*$/;
 
88
        chomp;
 
89
        s/^[\s\t]*//;
 
90
        s/[\s\t]*$//;
 
91
        next if m/^\#/;
 
92
        
 
93
        my $sublang = $_;
 
94
        my $base    = "/usr/share/aspell/$sublang";     # the wordlist basename
 
95
        my $hash    = "/var/lib/aspell/$sublang.rws";   # the hash file
 
96
        my $msg     ='';
 
97
        my $unpack  = '';
 
98
        
 
99
        print STDERR "aspell-autobuildhash: processing: $lang [$sublang]\n";
 
100
        
 
101
 
 
102
        if ( -e "$base.mwl.gz" ){
 
103
            $unpack = "zcat $base.mwl.gz";
 
104
        } elsif ( -e "$base.wl.gz") {
 
105
            $unpack = "zcat $base.wl.gz";
 
106
        } elsif ( -e "$base.cwl.gz") {
 
107
            $unpack = "zcat $base.cwl.gz | precat";
 
108
        } else {
 
109
            mymessage "Could not find any of $base.{mwl,wl,cwl}.gz";
 
110
            return 0;
 
111
        }
 
112
        
 
113
        #$unpack = "$unpack | aspell clean strict";
 
114
        system ("$unpack | aspell $options --local-data-dir=$data --lang=$lang create master $hash") == 0
 
115
            or $msg = "Could not build the hash file for $sublang" ;
 
116
        
 
117
        if ( $msg ){             # Do not break postinst if hash cannot be built
 
118
            mymessage ($msg);    # Just inform about that
 
119
            return 0;
 
120
        }
 
121
    }
 
122
    return 1;
 
123
}
 
124
 
 
125
# ---------------------------------------------------------------------
 
126
#                   Get aspell compat version
 
127
# ---------------------------------------------------------------------
 
128
 
 
129
sub get_aspell_compat {
 
130
    
 
131
    my $aspell_compat = '';
 
132
    
 
133
    if ( -e $aspellcompatfile ){
 
134
        open (COMPAT,"$aspellcompatfile");
 
135
        chomp ( $aspell_compat = <COMPAT> );
 
136
        close COMPAT;
 
137
    } else {
 
138
        $force = "yes";
 
139
    }
 
140
    return $aspell_compat;
 
141
}
 
142
 
 
143
# ---------------------------------------------------------------------
 
144
#                        The main program
 
145
# ---------------------------------------------------------------------
 
146
 
 
147
die "$0: You must run this as root.\n" if ($> != 0);
 
148
 
 
149
use Debconf::Client::ConfModule q(:all);
 
150
use Getopt::Long;
 
151
 
 
152
$compatdir        = "/var/lib/aspell";
 
153
$aspellcompatfile = "/usr/share/aspell/aspell.compat";
 
154
 
 
155
$force        = '';
 
156
$debug        = '';
 
157
 
 
158
GetOptions ('debug' => \$debug, 
 
159
            'force' => \$force) or usage();
 
160
 
 
161
if ( -x "/usr/bin/aspell" ){
 
162
 
 
163
    $aspell_compat = get_aspell_compat();
 
164
    
 
165
    foreach $compat ( <$compatdir/*.compat> ){
 
166
        my $build_hash  = '';
 
167
        my $lang_compat = '';
 
168
 
 
169
        $lang = $compat;
 
170
        $lang =~ s/\.compat$//;
 
171
        $lang =~ s/.*\///;
 
172
        
 
173
        open (COMPAT,"$compat");
 
174
        $lang_compat = <COMPAT>;
 
175
        close COMPAT;
 
176
        $lang_compat = 0     if not $lang_compat;
 
177
        chomp $lang_compat;
 
178
 
 
179
        $build_hash  = "yes" if ( $aspell_compat ne $lang_compat );
 
180
        $build_hash  = "yes" if $force;
 
181
        
 
182
        if ( $build_hash ){
 
183
            debugprint "$lang => aspell_compat: [$aspell_compat]; lang_compat: [$lang_compat]";
 
184
            if ( autorebuild($lang) ){
 
185
                debugprint " +++ Updating $compat";
 
186
                open (COMPAT,">","$compat");
 
187
                if ( $aspell_compat ){
 
188
                    print COMPAT "$aspell_compat\n";
 
189
                } else {
 
190
                    print COMPAT "0\n";
 
191
                }
 
192
                close COMPAT;
 
193
            } else {
 
194
                debugprint " --- $compat not updated because of an error";
 
195
            }
 
196
        }
 
197
    }
 
198
} else {
 
199
    debugprint " aspell is not installed. Doing nothing";
 
200
}
 
201
 
 
202
__END__
 
203
 
 
204
=head1 NAME
 
205
 
 
206
B<aspell-autobuildhash> - Autobuilding aspell hash files for some dicts
 
207
 
 
208
=head1 SYNOPSIS
 
209
 
 
210
 aspell-autobuildhash [--force]
 
211
 
 
212
   Options:
 
213
    --debug      Show some extra information.
 
214
    --force      Rebuild the hash file for all dicts providing a 
 
215
                 compat file skipping the test.
 
216
 
 
217
=head1 DESCRIPTION
 
218
 
 
219
B<aspell-autobuildhash> is a script that will manage aspell hash files 
 
220
autobuild, intended to be called from the dictionaries-common tools. 
 
221
Depending on the aspell 
 
222
compatibility level and on the compatibility level used for the hash file 
 
223
if present, will decide whether it must be rebuilt or not. This script will 
 
224
only work on aspell packages prepared to use it, it will do nothing for other 
 
225
aspell dict packages.
 
226
 
 
227
=head1 OPTIONS
 
228
 
 
229
--debug      Show some extra information.
 
230
--force      Rebuild the hash file for all dicts providing a compat 
 
231
             file regardless of the compatibility levels found.
 
232
 
 
233
=head1 PACKAGE MAINTAINERS
 
234
 
 
235
To use this system, just provide a F<$lang.compat> file in F</var/lib/aspell> 
 
236
(I<$lang> stands for the lang basename with variant if any, e.g. I<gl-minimos>
 
237
or I<en>). Put a "0" in it or just create an empty one with touch.
 
238
 
 
239
Wordlists should previously be compressed either with gzip
 
240
(and their extensions set as F<.mwl.gz> or F<.wl.gz>) or preferrably
 
241
first with aspell prezip and then gzipped (with F<.cwl.gz> extension).
 
242
This applies both for plain wordlists and munched wordlists
 
243
(in the ispell way) if you use affix compression.
 
244
 
 
245
If your package will provide a single hash, install prezipped+gzipped
 
246
wordlist as F</usr/share/aspell/$lang.cwl.gz> or, if prezip is not used,
 
247
as F</usr/share/aspell/$lang.mwl.gz>.
 
248
 
 
249
If your package will provide more than one aspell hash for the same $lang,
 
250
you will need to place each compressed wordlist as e.g.
 
251
F</usr/share/aspell/$subdict.cwl.gz>, and the common F<$lang.compat> as
 
252
above. Then create a F</usr/share/aspell/$lang.contents> file with the
 
253
base names of the subdicts, one in a line. For english that will contain,
 
254
amongst other possible lines
 
255
 
 
256
 en-common
 
257
 en-variant_0
 
258
 en-variant_1
 
259
 en-variant_2
 
260
 en_CA-w_accents-only
 
261
 
 
262
No need to use this file if a single hash is being created.
 
263
 
 
264
Dictionaries-common scripts will call internally this script and create a 
 
265
single hash file at F</var/lib/ispell/$lang.hash>, or hash files at
 
266
F</var/lib/ispell/$subdict.hash>. You must set a symlink to that 
 
267
files from F</usr/lib/aspell/$lang.hash> or
 
268
F</usr/lib/aspell/$subdict.hash> as appropriate.
 
269
You are also suggested to create empty files at
 
270
F</var/lib/aspell/$lang.hash> or for all of the
 
271
F</var/lib/aspell/$subdict.hash> in the install target of 
 
272
your package build process. This empty file will be overwritten when the 
 
273
real hash is created, but will make the hash be removed at package 
 
274
removal without any magic being done in the postrm and will also help to
 
275
keep track about which package owns that file.
 
276
 
 
277
B<aspell> maintainer should also call this script from package postinst. 
 
278
When comparing versions it will get the aspell version from file
 
279
F</usr/share/aspell/aspell.compat>.
 
280
 
 
281
=head1 AUTHORS
 
282
 
 
283
Agustin Martin <agmartin@debian.org>
 
284
 
 
285
=cut
 
286