home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / usr / sbin / update-default-ispell < prev    next >
Encoding:
Text File  |  2006-12-19  |  5.7 KB  |  190 lines

  1. #!/usr/bin/perl -w
  2.  
  3. use Debian::DictionariesCommon q(:all);
  4. use Debconf::Client::ConfModule q(:all);
  5. use Getopt::Long;
  6.  
  7. die "$0: You must run this as root.\n" if ($> != 0);
  8.  
  9. my $rebuild = '';
  10. my $ignoresymlinks = '';
  11.  
  12. GetOptions ('rebuild' => \$rebuild,
  13.         'ignore-symlinks' => \$ignoresymlinks);
  14.  
  15. version ('2.0');
  16.  
  17. my $class     = "ispell";
  18. my $libdir    = "/usr/lib/ispell";
  19. my $question  = "dictionaries-common/default-$class";
  20. my $iquestion = "dictionaries-common/invalid_debconf_value";
  21. my $linkdir   = "/etc/dictionaries-common";
  22. my $manual    = '';
  23. my $emacsen_default = "nil";
  24. my $cache_dir = "/var/cache/dictionaries-common";
  25. my $emacsen_default_file = "$cache_dir/emacsen-ispell-default.el";
  26. my $ispell_dicts_list = "$cache_dir/ispell-dicts-list.txt";
  27.  
  28. ($ret, $value)  = get ($question);
  29.  
  30. if ($ret == 0 && $value ){
  31.   
  32.   updatedb ($class);
  33.   my $dictionaries = loaddb ($class);
  34.   
  35.   if ( scalar(keys %{$dictionaries}) == 0 ){
  36.     print STDERR "$0 No $class elements installed.\n";
  37.     $value = "Manual forced (No $class elements installed)";
  38.     set($question,$value);
  39.     go();
  40.   }
  41.   
  42.   if ( $value =~ m/^Manual.*/i ){       # Check if we are in manual mode
  43.     $ignoresymlinks = "yes";
  44.     $manual         = "yes";
  45.   }
  46.  
  47.   if ( not $ignoresymlinks) {
  48.     
  49.     if (not exists $dictionaries->{$value}){         # Handle invalid debconf values
  50.       my @available_keys=();
  51.       foreach ( split (/\s*,\s*/, metaget ($question, "choices")) ){
  52.     s/\s*(.*)\s*/$1/;          # strip possible leading/trailing whitespaces
  53.     push (@available_keys,$_) if ( exists $dictionaries->{$_} );
  54.       }
  55.       my $choices = join (', ', sort {lc $a cmp lc $b} @available_keys);
  56.       my $forced_key = $available_keys[0] ||
  57.       die "Selected ispell dictionary:\n" .
  58.       " $value \n" .
  59.       "does not correspond to any installed package in the system\n" .
  60.       "and no alternative ispell dictionary could be selected.\n";
  61.       subst($iquestion,"value",$value);
  62.       fset ($iquestion,"seen","false");
  63.       input("high",$iquestion);               # Warn about what happened
  64.       subst ($question, "choices", $choices); # Put sane values in debconf choices field
  65.       set ($question, $forced_key);           # Set debconf value to a sane one  
  66.       fset ($question,"seen","false");
  67.       input ("critical", $question);  
  68.       title ("dictionaries-common: ispell dictionaries");
  69.       go ();
  70.       ($ret, $value) = get ($question);
  71.       die "\n Could not get a valid value for debconf question:\n" .
  72.       "$question\n"
  73.           if ( $ret != 0 ); # This should never be reached
  74.     }
  75.     
  76.     die "Selected ispell dictionary:\n" .
  77.     " $value \n" .
  78.     "does not contain a hash name entry in the database.\n"
  79.     if (not exists $dictionaries->{$value}{"hash-name"});
  80.  
  81.     setsysdefault ($value); # This here is only for ispell, not wordlist
  82.  
  83.     my $hash   = "$libdir/" . $dictionaries->{$value}{"hash-name"};
  84.  
  85.     foreach my $i (".hash", ".aff") {
  86.  
  87.       die "
  88. When trying to make the default link to a ispell dictionary
  89. the file to link [$hash$i] was not found. Please report this as a bug to the
  90. maintainer of the ispell dictionary package you tried to
  91. select.
  92. In the meantime select other default value for your ispell dictionary.\n"
  93. if (not -e "$hash$i");
  94.       
  95.       system "ln -fs $hash$i $linkdir/default$i";
  96.       
  97.     }
  98.   }
  99. # Printing a plain list with installed ispell dictionaries,
  100.   open (IDICTS,"> $ispell_dicts_list") || 
  101.          die "Could not open $ispell_dicts_list for writing\n";
  102.   foreach ( sort keys %{$dictionaries} ){
  103.     print IDICTS "$_\n";
  104.   }
  105.   close (IDICTS);
  106.   # Write ispell default dict for emacsen
  107.   unless ( $manual ){
  108.     if ( exists $dictionaries->{$value}{"emacs-display"} 
  109.      and lc($dictionaries->{$value}{"emacs-display"}) eq "no" ){  
  110.       $emacsen_default = "nil";
  111.     } elsif ( exists $dictionaries->{$value}{"emacsen-name"} ){
  112.       $emacsen_default = "\"" . $dictionaries->{$value}{"emacsen-name"} . "\"";
  113.     } elsif( exists $dictionaries->{$value}{"hash-name"} ){
  114.       $emacsen_default = "\"" . $dictionaries->{$value}{"hash-name"} . "\"";
  115.     }
  116.   }
  117. }
  118.  
  119. # Printing the default ispell dictionary under emacs
  120. open (EMISDEFAULT,"> $emacsen_default_file");
  121. print EMISDEFAULT ";; File automatically generated by update-default-ispell
  122. ;; 
  123. ;; Do not manually edit!! Use select-default-ispell script instead
  124.  
  125. (set-variable \'debian-ispell-dictionary $emacsen_default)\n";
  126. close EMISDEFAULT;
  127.  
  128.  
  129. if ($rebuild) {
  130.  
  131.   updatedb ($class);
  132.  
  133.   # Ispell emacsen + jed support
  134.   build_emacsen_support ();
  135.   build_jed_support ();
  136.   system ("ispell-autobuildhash") == 0
  137.       or die "Error running ispell-autobuildhash\n";
  138.   # End of specific ispell support 
  139. }
  140.  
  141. #Local Variables:
  142. #perl-indent-level: 2
  143. #End:
  144.  
  145. __END__
  146.  
  147. =head1 NAME
  148.  
  149. update-default-ispell - update default ispell dictionary 
  150.  
  151. =head1 SYNOPSIS
  152.  
  153.  update-default-ispell [--rebuild] [--ignore-symlinks]
  154.  
  155. =head1 DESCRIPTION
  156.  
  157. WARNING: Not to be used from the command line unless you know very well what you are doing. 
  158.  
  159. This program is intended to be called from package postinst 
  160. (with B<--rebuild>), from B<select-default-ispell> or 
  161. from dictionaries-common 
  162. postinst (with B<--ignore-symlinks>).
  163.  
  164. Reads the system default from the debconf database and set default links in 
  165. F</etc/dictionaries-common> pointing to the appropriate files in 
  166. F</usr/lib/ispell/>.  Also 
  167. updates the system-wide setting F</etc/dictionaries-common/ispell-default>.
  168. If option B<--rebuild> is given, rebuilds the 
  169. F</var/cache/dictionaries-common/ispell.db>  
  170. and the emacsen and jed support (to be put in
  171. F</var/cache/dictionaries-common/>) from the files in
  172. F</var/lib/dictionaries-common/ispell>
  173.  
  174.  
  175. =head1 OPTIONS
  176.  
  177. --rebuild          Rebuild database, emacsen and jed stuff
  178. --ignore-symlinks  Do not set symlinks
  179.  
  180.  
  181. =head1 SEE ALSO
  182.  
  183. The dictionaries-common policy document
  184.  
  185. =head1 AUTHORS
  186.  
  187. Rafael Laboissiere
  188.  
  189. =cut
  190.