diff options
author | Roger Leigh <rleigh@debian.org> | 2008-10-26 16:16:09 +0000 |
---|---|---|
committer | Roger Leigh <rleigh@debian.org> | 2008-10-26 16:16:09 +0000 |
commit | 3950c83c2919fe59dbf442c0d4859778fadd0e8d (patch) | |
tree | a94521b94f4a256b5b6d7f004f4afd5f9aae5db0 /src/cups/cups-genppdupdate.in | |
parent | 97aedb05b271e9486f51eac1aee64fce92da64ca (diff) |
Imported Upstream version 4.3.99+cvs20060521
Diffstat (limited to 'src/cups/cups-genppdupdate.in')
-rw-r--r-- | src/cups/cups-genppdupdate.in | 165 |
1 files changed, 119 insertions, 46 deletions
diff --git a/src/cups/cups-genppdupdate.in b/src/cups/cups-genppdupdate.in index 1b90140..b0c3b0b 100644 --- a/src/cups/cups-genppdupdate.in +++ b/src/cups/cups-genppdupdate.in @@ -1,5 +1,5 @@ #! @PERL@ -w -# $Id: cups-genppdupdate.in,v 1.22 2005/12/24 22:41:11 rlk Exp $ +# $Id: cups-genppdupdate.in,v 1.24 2006/03/29 02:27:15 rlk Exp $ # Update CUPS PPDs for Gutenprint queues. # Copyright (C) 2002-2003 Roger Leigh (rleigh@debian.org) # @@ -37,6 +37,8 @@ our $opt_n; # No action our $opt_q; # Quiet mode our $opt_s; # Source PPD location our $opt_v; # Verbose mode +our $opt_N; # Don't update PPD file options +our $opt_o; # Output directory my $debug = 0; my $verbose = 0; # Verbose output @@ -45,11 +47,13 @@ if ($debug) { } my $quiet = 0; # No output my $no_action = 0; # Don't output files +my $reset_defaults = 0; # Reset options to default settings my $version = "@GUTENPRINT_MAJOR_VERSION@.@GUTENPRINT_MINOR_VERSION@"; my $ppd_dir = "@cups_conf_serverroot@/ppd"; # Location of in-use CUPS PPDs my $ppd_root_dir = "@cups_conf_datadir@/model"; my $ppd_base_dir = "$ppd_root_dir/gutenprint/$version"; # Available PPDs +my $ppd_out_dir = ""; # By default output into source directory my $gzext = ".gz"; my $updated_ppd_count = 0; @@ -65,6 +69,7 @@ my %languagemappings = ( "french" => "fr", "german" => "de", "greek" => "el", + "hungarian" => "hu", "italian" => "it", "japanese" => "jp", "norwegian" => "no", @@ -90,10 +95,44 @@ umask 0177; # Find all in-use Gutenprint PPD files... -my @ppdglob = glob("$ppd_dir/*.{ppd,PPD}"); +my @ppdglob; +if (@ARGV) { + my $f; + foreach $f (@ARGV) { + if (-f $f and ($f =~ /\.ppd$/i or $f =~ /\//)) { + if (-f $f) { + push @ppdglob, $f; + } else { + print STDERR "Cannot find file $f\n"; + } + } elsif (-f "$ppd_dir/$f" or + -f "$ppd_dir/$f.ppd" or + -f "$ppd_dir/$f.PPD") { + if (-f "$ppd_dir/$f") { + push @ppdglob, "$ppd_dir/$f"; + } + if (-f "$ppd_dir/$f.ppd") { + push @ppdglob, "$ppd_dir/$f.ppd"; + } + if (-f "$ppd_dir/$f.PPD") { + push @ppdglob, "$ppd_dir/$f.PPD"; + } + } else { + print STDERR "Cannot find file $ppd_dir/$f, $ppd_dir/$f.ppd, or $ppd_dir/$f.PPD\n"; + } + } +} else { + @ppdglob = glob("$ppd_dir/*.{ppd,PPD}"); +} my $ppdlist = join ' ', @ppdglob; if (@ppdglob) { - open PPDFILES, '-|', 'egrep', '-i', '-l', 'Gutenprint|Gimp-Print', @ppdglob or die "can't grep $ppd_dir/*: $!"; + open PPDFILES, '-|', 'egrep', '-i', '-l', 'Gutenprint|Gimp-Print', @ppdglob or die "can't grep $ppdlist: $!"; + while (<PPDFILES>) { + chomp; + push @ppd_files, $_; + } + open PPDFILES, '-|', 'egrep', '-i', '-L', 'Foomatic', @ppd_files or die "can't grep $ppdlist: $!"; + @ppd_files = (); while (<PPDFILES>) { chomp; push @ppd_files, $_; @@ -118,7 +157,11 @@ foreach (@ppd_files) { if (!$quiet || $verbose) { if ($updated_ppd_count > 0) { - print STDOUT "Updated $updated_ppd_count PPD files. Restart cupsd for the changes to take effect.\n"; + my $plural = ""; + if ($updated_ppd_count != 1) { + $plural = "s"; + } + print STDOUT "Updated $updated_ppd_count PPD file${plural}. Restart cupsd for the changes to take effect.\n"; exit (0); } else { print STDOUT "Failed to update any PPD files\n"; @@ -129,7 +172,7 @@ if (!$quiet || $verbose) { sub parse_options () { - getopts("dhnqs:v"); + getopts("dhnqs:vNo:"); if ($opt_n) { $no_action = 1; @@ -142,7 +185,7 @@ sub parse_options () { $ppd_base_dir = "$opt_s"; } else { - die "$opt_s: invalid directory: $!"; + die "$opt_s: invalid directory: $!\n"; } } if ($opt_v) { @@ -153,8 +196,19 @@ sub parse_options () { $verbose = 0; $quiet = 1; } + if ($opt_N) { + $reset_defaults = 1; + } + if ($opt_o) { + if (-d $opt_o) { + $ppd_out_dir = "$opt_o"; + } + else { + die "$opt_s: invalid directory: $!\n"; + } + } if ($opt_h) { - print "Usage: $0 [OPTION]...\n"; + print "Usage: $0 [OPTION]... [PPD_FILE]...\n"; print "Update CUPS+Gutenprint PPD files.\n\n"; print " -d Enable debugging\n"; print " -h Display this help text\n"; @@ -162,6 +216,8 @@ sub parse_options () { print " -q Quiet mode. No messages except errors.\n"; print " -s ppd_dir Use ppd_dir as the source PPD directory.\n"; print " -v Verbose messages.\n"; + print " -N Reset options to defaults.\n"; + print " -o out_dir Output PPD files to out_dir.\n"; exit (0); } } @@ -170,6 +226,11 @@ sub parse_options () { # Update the named PPD file. sub update_ppd ($) { my $ppd_source_filename = $_; + my $ppd_dest_filename = $ppd_source_filename; + if ($ppd_out_dir) { + $ppd_dest_filename =~ s;(.*)/([^/]+);$2;; + $ppd_dest_filename = "$ppd_out_dir/$ppd_dest_filename"; + } open ORIG, $_ or die "$_: can't open PPD file: $!"; seek (ORIG, 0, 0) or die "can't seek to start of PPD file"; @@ -177,7 +238,6 @@ sub update_ppd ($) { if ($debug) { print "Source Filename: $ppd_source_filename\n"; } - # Get the `PCFileName'; the new source PPD will have the same name. my ($filename) = ""; my ($driver) = ""; my ($gutenprintdriver) = ""; @@ -322,45 +382,46 @@ sub update_ppd ($) { } - # Update source buffer with old defaults... + if (! $reset_defaults) { + # Update source buffer with old defaults... - # Loop through each default in turn. + # Loop through each default in turn. default_loop: - foreach (sort keys %defaults) { - my $default_option = $_; - my $option; - ($option = $_) =~ s/Default//; # Strip off `Default' - # Check method is valid - my $orig_method = $orig_default_types{$option}; - my $new_method = $new_default_types{$option}; - if ((!defined($orig_method) || !defined($new_method)) || - $orig_method ne $new_method) { - next; - } - if ($new_method eq "PickOne") { - # Check the old setting is valid - foreach (@{$options{$option}}) { - if ($defaults{$default_option} eq $_) { # Valid option - # Set the option in the new PPD - $source_data =~ s/\*($default_option).*/*$1:$defaults{$default_option}/m; - if ($verbose) { - print "$ppd_source_filename: Set *$default_option to $defaults{$default_option}\n"; + foreach (sort keys %defaults) { + my $default_option = $_; + my $option; + ($option = $_) =~ s/Default//; # Strip off `Default' + # Check method is valid + my $orig_method = $orig_default_types{$option}; + my $new_method = $new_default_types{$option}; + if ((!defined($orig_method) || !defined($new_method)) || + $orig_method ne $new_method) { + next; + } + if ($new_method eq "PickOne") { + # Check the old setting is valid + foreach (@{$options{$option}}) { + if ($defaults{$default_option} eq $_) { # Valid option + # Set the option in the new PPD + $source_data =~ s/\*($default_option).*/*$1:$defaults{$default_option}/m; + if ($verbose) { + print "$ppd_source_filename: Set *$default_option to $defaults{$default_option}\n"; + } + next default_loop; } - next default_loop; } + printf STDERR + "$ppd_source_filename: Invalid option: *$default_option: $defaults{$default_option}. Skipped.\n"; + next; } - printf STDERR - "$ppd_source_filename: Invalid option: *$default_option: $defaults{$default_option}. Skipped.\n"; - next; + print STDERR + "$ppd_source_filename: PPD OpenUI method $new_default_types{$_} not understood. Skipped\n"; } - print STDERR - "$ppd_source_filename: PPD OpenUI method $new_default_types{$_} not understood. Skipped\n"; } - # Write new PPD... - my $tmpnew = "${ppd_source_filename}.new"; + my $tmpnew = "${ppd_dest_filename}.new"; if (! open NEWPPD, "> $tmpnew") { warn "Can't open $tmpnew for writing: $!\n"; return 0; @@ -372,16 +433,20 @@ default_loop: return 0; } - if (! rename $tmpnew, $ppd_source_filename) { - warn "Can't rename $tmpnew to $ppd_source_filename: $!\n"; + if (! rename $tmpnew, $ppd_dest_filename) { + warn "Can't rename $tmpnew to $ppd_dest_filename: $!\n"; unlink $tmpnew; return 0; } - chown($orig_metadata[4], $orig_metadata[5], $ppd_source_filename); - chmod(($orig_metadata[2] & 0777), $ppd_source_filename); + chown($orig_metadata[4], $orig_metadata[5], $ppd_dest_filename); + chmod(($orig_metadata[2] & 0777), $ppd_dest_filename); if (!$quiet || $verbose) { - print STDOUT "Updated $ppd_source_filename using $source\n"; + if ($ppd_dest_filename eq $ppd_source_filename) { + print STDOUT "Updated $ppd_source_filename using $source\n"; + } else { + print STDOUT "Updated $ppd_source_filename to $ppd_dest_filename using $source\n"; + } } return 1; # All done! @@ -394,9 +459,14 @@ sub find_ppd ($$$$) { my ($key) = '^\\*FileVersion:[ ]*"@VERSION@"$'; my ($lingo, $suffix, $base, $basedir); my ($current_best_file, $current_best_time); - my ($stored_name, $stored_dir); + my ($stored_name, $stored_dir, $simplified); $stored_name = $gutenprintfilename; - $stored_name =~ s,.*/([^/]*)(.gz)?$,$1,; + $stored_name =~ s,.*/([^/]*)(.sim)?(.ppd)?(.gz)?$,$1,; + if ($gutenprintfilename =~ m,.*/([^/]*)(.sim)(.ppd)?(.gz)?$,) { + $simplified = ".sim"; + } else { + $simplified = ""; + } $stored_dir = $gutenprintfilename; $stored_dir =~ s,(.*)/([^/]*)$,$1,; @@ -411,8 +481,8 @@ sub find_ppd ($$$$) { "") { foreach $suffix (".ppd$gzext", ".ppd") { - foreach $base ("${drivername}.$version", - "stp-${drivername}.$version", + foreach $base ("${drivername}.$version${simplified}", + "stp-${drivername}.$version${simplified}", $stored_name, $drivername) { foreach $basedir ($ppd_base_dir, @@ -442,6 +512,9 @@ sub find_ppd ($$$$) { if ($sb[9] > $current_best_time) { $current_best_time = $sb[9]; $current_best_file = $fn; + if ($debug) { + print STDERR "***current_best_file is $fn\n"; + } } } elsif ($debug) { print " Format invalid\n"; |