summaryrefslogtreecommitdiff
path: root/src/cups/cups-genppdupdate.in
diff options
context:
space:
mode:
authorRoger Leigh <rleigh@debian.org>2008-10-26 16:17:32 +0000
committerRoger Leigh <rleigh@debian.org>2008-10-26 16:17:32 +0000
commitcda0fb3b8a7cb56045b24fd0af0ed36591b5d7eb (patch)
tree31ef197ec5c98ac9ac08714a2440a787c065d8c7 /src/cups/cups-genppdupdate.in
parent92b02ddce00dec2787514568fa9d644d4f0350e9 (diff)
Imported Upstream version 5.0.1
Diffstat (limited to 'src/cups/cups-genppdupdate.in')
-rw-r--r--src/cups/cups-genppdupdate.in253
1 files changed, 175 insertions, 78 deletions
diff --git a/src/cups/cups-genppdupdate.in b/src/cups/cups-genppdupdate.in
index 1a1a8f4..ee49a0b 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.25 2006/05/22 20:25:51 rleigh Exp $
+# $Id: cups-genppdupdate.in,v 1.25.8.2 2007/05/29 01:47:26 rlk Exp $
# Update CUPS PPDs for Gutenprint queues.
# Copyright (C) 2002-2003 Roger Leigh (rleigh@debian.org)
#
@@ -25,6 +25,7 @@ use File::Copy qw(mv);
sub parse_options ();
sub update_ppd ($); # Original PPD filename
+sub get_ppd_contents ($$$$$); # Return contents of desired PPD
sub find_ppd ($$$$); # Gutenprint Filename, driver, language (e.g. en, sv),
# region (e.g. GB, DE)
sub get_default_types (*); # Source PPD FH
@@ -49,6 +50,8 @@ 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 $micro_version = "@GUTENPRINT_VERSION@";
+my $use_static_ppd = "@BUILD_CUPS_PPDS@";
my $ppd_dir = "@cups_conf_serverroot@/ppd"; # Location of in-use CUPS PPDs
my $ppd_root_dir = "@cups_conf_datadir@/model";
@@ -56,6 +59,11 @@ 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;
+my $exit_after_parse_args = 0;
+
+my $serverdir = "@cups_conf_serverbin@";
+
+$Getopt::Std::STANDARD_HELP_VERSION = 1;
my @ppd_files; # A list of in-use Gutenprint PPD files
@@ -166,21 +174,53 @@ if (!$quiet || $verbose) {
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";
+ if ($no_action) {
+ print STDOUT "Did not update any PPD files\n";
+ } else {
+ print STDOUT "Failed to update any PPD files\n";
+ }
exit (0);
}
}
+sub HELP_MESSAGE($;$$$) {
+ my ($fh) = @_;
+ print $fh "Usage: $0 [OPTION]... [PPD_FILE]...\n";
+ print $fh "Update CUPS+Gutenprint PPD files.\n\n";
+ print $fh " -d flags Enable debugging\n";
+ print $fh " -h Display this help text\n";
+ print $fh " -n No-action. Don't overwrite any PPD files.\n";
+ print $fh " -q Quiet mode. No messages except errors.\n";
+ print $fh " -s ppd_dir Use ppd_dir as the source PPD directory.\n";
+ print $fh " -v Verbose messages.\n";
+ print $fh " -N Reset options to defaults.\n";
+ print $fh " -o out_dir Output PPD files to out_dir.\n";
+ exit(0);
+}
+# Getopt::Std calls VERSION_MESSAGE followed by HELP_MESSAGE if --help
+# is passed. If --version is passed, it calls only VERSION_MESSAGE.
+# So we have to make sure to exit, but we want to allow --help to
+# print out the help message.
+sub VERSION_MESSAGE($;$$$) {
+ my ($fh) = @_;
+ print "cups-genppdupdate from Gutenprint $micro_version\n";
+ $exit_after_parse_args = 1;
+}
-sub parse_options () {
- getopts("dhnqs:vNo:");
+sub help() {
+ HELP_MESSAGE(\*STDOUT);
+}
+sub parse_options () {
+ if (!getopts('d:hnqs:vNo:')) {
+ help();
+ }
if ($opt_n) {
$no_action = 1;
}
if ($opt_d) {
- $debug = 1;
+ $debug = $opt_d;
}
if ($opt_s) {
if (-d $opt_s) {
@@ -210,20 +250,81 @@ sub parse_options () {
}
}
if ($opt_h) {
- 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";
- print " -n No-action. Don't overwrite any PPD files.\n";
- 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);
+ help();
+ }
+ if ($exit_after_parse_args) {
+ exit(0);
}
}
+sub get_ppd_contents($$$$$) {
+ my ($ppd_source_filename, $filename, $driver, $locale, $region) = @_;
+
+ my $source_data;
+ my ($new_ppd_filename);
+
+ if ($use_static_ppd eq "no") {
+ my ($driver_bin) = "$serverdir/driver/gutenprint.$version";
+ my ($driver_version) = `$driver_bin VERSION`;
+ chomp $driver_version;
+ if ($driver_version eq "@VERSION@") {
+ my ($simplified);
+ if ($filename =~ m,.*/([^/]*)(.sim)(.ppd)?(.gz)?$,) {
+ $simplified = "simple";
+ } else {
+ $simplified = "expert";
+ }
+ my ($url);
+ foreach $url ("gutenprint.$version://$driver/$simplified/${locale}_${region}",
+ "gutenprint.$version://$driver/$simplified/${locale}",
+ "gutenprint.$version://$driver/$simplified") {
+ $new_ppd_filename = $url;
+ if (open PPD, "$driver_bin cat $url 2>/dev/null |") {
+ while (<PPD>) {
+ $source_data .= $_;
+ }
+ close PPD;
+ if ($source_data) {
+ return ( $new_ppd_filename, $source_data );
+ }
+ }
+ }
+ }
+ # Otherwise fall through and try to find a static PPD
+ }
+
+ # Search for a PPD matching our criteria...
+
+ $new_ppd_filename = find_ppd($filename, $driver, $locale, $region);
+ if (!defined($new_ppd_filename)) {
+ # There wasn't a valid source PPD file, so give up.
+ print STDERR "$ppd_source_filename: no valid candidate for replacement. Skipping\n";
+ print STDERR "$ppd_source_filename: please upgrade this PPD manually\n";
+ return ("", 0);
+ }
+ if ($debug & 1) {
+ print "Candidate PPD: $new_ppd_filename\n";
+ }
+
+ my $suffix = "\\" . $gzext; # Add '\', so m// matches the '.'.
+ if ($new_ppd_filename =~ m/.gz$/) { # Decompress input buffer
+ open GZIN, "gunzip -c $new_ppd_filename |"
+ or die "$_: can't open for decompression: $!";
+ while (<GZIN>) {
+ $source_data .= $_;
+ }
+ close GZIN;
+ } else {
+ open SOURCE, $new_ppd_filename
+ or die "$new_ppd_filename: can't open source file: $!";
+ binmode SOURCE;
+ my $source_size = (stat(SOURCE))[7];
+ read (SOURCE, $source_data, $source_size)
+ or die "$new_ppd_filename: error reading source: $!";
+ close SOURCE or die "$new_ppd_filename: can't close file: $!";
+ }
+ return ( $new_ppd_filename, $source_data );
+}
# Update the named PPD file.
sub update_ppd ($) {
@@ -237,7 +338,7 @@ sub update_ppd ($) {
open ORIG, $_ or die "$_: can't open PPD file: $!";
seek (ORIG, 0, 0) or die "can't seek to start of PPD file";
my @orig_metadata = stat(ORIG);
- if ($debug) {
+ if ($debug & 1) {
print "Source Filename: $ppd_source_filename\n";
}
my ($filename) = "";
@@ -274,7 +375,7 @@ sub update_ppd ($) {
print STDERR "$ppd_source_filename: this PPD file cannot be upgraded automatically (only files based on Gutenprint 4.3.21 and newer can be)\n";
return 0;
}
- if ($debug) {
+ if ($debug & 2) {
print "Gutenprint Filename: $filename\n";
print "Locale: $locale\n";
print "Language: $lingo\n";
@@ -295,46 +396,19 @@ sub update_ppd ($) {
if (! defined($region)) {
$region = "";
}
- if ($debug) {
- print "Locale: $locale\n";
+ if ($debug & 2) {
+ print "Base Locale: $locale\n";
print "Region: $region\n";
}
- # Search for a PPD matching our criteria...
-
- my $source = find_ppd($filename, $driver, $locale, $region);
- if (!defined($source)) {
- # There wasn't a valid source PPD file, so give up.
- print STDERR "$ppd_source_filename: no valid candidate for replacement. Skipping\n";
- print STDERR "$ppd_source_filename: please upgrade this PPD manually\n";
- return 0;
- }
- if ($debug) {
- print "Candidate PPD: $source\n";
- }
-
-
# Read in the new PPD, decompressing it if needed...
- my $source_data;
+ my ($new_ppd_filename, $source_data) =
+ get_ppd_contents($ppd_source_filename, $filename,
+ $driver, $locale, $region);
- my $suffix = "\\" . $gzext; # Add '\', so m// matches the '.'.
- if ($source =~ m/.gz$/) { # Decompress input buffer
- open GZIN, "gunzip -c $source |"
- or die "$_: can't open for decompression: $!";
- while (<GZIN>) {
- $source_data .= $_;
- }
- close GZIN;
- }
- else {
- open SOURCE, $source
- or die "$source: can't open source file: $!";
- binmode SOURCE;
- my $source_size = (stat(SOURCE))[7];
- read (SOURCE, $source_data, $source_size)
- or die "$source: error reading source: $!";
- close SOURCE or die "$source: can't close file: $!";
+ if (! $source_data) {
+ die "Unable to retrieve PPD file!\n";
}
# Save new PPD in a temporary file, for processing...
@@ -360,30 +434,55 @@ sub update_ppd ($) {
close $tmpfile or die "can't close temporary file $tmpfile: $!";
- if ($debug) {
- print "Original Default Types:\n";
- foreach (sort keys %orig_default_types) {
- print " $_: $orig_default_types{$_}\n";
- }
- print "New Default Types:\n";
- foreach (sort keys %new_default_types) {
- print " $_: $new_default_types{$_}\n";
- }
- print "Defaults:\n";
- foreach (sort keys %defaults) {
- print " $_: $defaults{$_}\n";
- }
- print "Options:\n";
+ if ($debug & 4) {
+ print "Options (Old->New Default Type):\n";
foreach (sort keys %options) {
- print " $_: ";
+ my ($old_type) = $orig_default_types{$_};
+ my ($new_type) = $new_default_types{$_};
+ if (! defined($old_type)) {
+ $old_type = '(New)';
+ }
+ if ($old_type ne $new_type) {
+ print " $_ ($old_type -> $new_type) : ";
+ } else {
+ print " $_ ($new_type) : ";
+ }
+ my ($def) = $defaults{"Default$_"};
foreach my $opt (@{$options{$_}}) {
+ if (defined $def && $def eq $opt) {
+ print "*";
+ }
print "$opt ";
}
print "\n";
}
-
+ print "Non-UI Defaults:\n";
+ foreach (sort keys %defaults) {
+ my ($xkey) = $_;
+ $xkey =~ s/^Default//;
+ if (! defined ($options{$xkey})) {
+ print " $_: $defaults{$_}\n";
+ }
+ }
+ print "Default Types of dropped options:\n";
+ foreach (sort keys %orig_default_types) {
+ if (! defined($options{$_})) {
+ print " $_: $orig_default_types{$_}\n";
+ }
+ }
}
+ if ($no_action) {
+ if (!$quiet || $verbose) {
+ if ($ppd_dest_filename eq $ppd_source_filename) {
+ print STDOUT "Would update $ppd_source_filename using $new_ppd_filename\n";
+ } else {
+ print STDOUT "Would update $ppd_source_filename to $ppd_dest_filename using $new_ppd_filename\n";
+ }
+ }
+ return 0;
+ }
+
if (! $reset_defaults) {
# Update source buffer with old defaults...
@@ -412,12 +511,10 @@ default_loop:
next default_loop;
}
}
- printf STDERR
- "$ppd_source_filename: Invalid option: *$default_option: $defaults{$default_option}. Skipped.\n";
+ warn "Warning: $ppd_source_filename: Invalid option: *$default_option: $defaults{$default_option}. Using default setting.\n";
next;
}
- print STDERR
- "$ppd_source_filename: PPD OpenUI method $new_default_types{$_} not understood. Skipped\n";
+ warn "Warning: $ppd_source_filename: PPD OpenUI method $new_default_types{$_} not understood.\n";
}
}
@@ -445,9 +542,9 @@ default_loop:
if (!$quiet || $verbose) {
if ($ppd_dest_filename eq $ppd_source_filename) {
- print STDOUT "Updated $ppd_source_filename using $source\n";
+ print STDOUT "Updated $ppd_source_filename using $new_ppd_filename\n";
} else {
- print STDOUT "Updated $ppd_source_filename to $ppd_dest_filename using $source\n";
+ print STDOUT "Updated $ppd_source_filename to $ppd_dest_filename using $new_ppd_filename\n";
}
}
return 1;
@@ -492,7 +589,7 @@ sub find_ppd ($$$$) {
$ppd_root_dir) {
if (! $basedir || ! $base) { next; }
my ($fn) = "$basedir/$lingo$base$suffix";
- if ($debug) {
+ if ($debug & 8) {
print "Trying $fn for $gutenprintfilename, $lang, $region\n";
}
# Check that it is a regular file, owned by root.root, not writable
@@ -508,17 +605,17 @@ sub find_ppd ($$$$) {
$file_version = `cat $fn | grep '$key'`;
}
if ($file_version ne "") {
- if ($debug) {
+ if ($debug & 8) {
print " Format valid: time $sb[9] best $current_best_time prev $current_best_file cur $fn!\n";
}
if ($sb[9] > $current_best_time) {
$current_best_time = $sb[9];
$current_best_file = $fn;
- if ($debug) {
+ if ($debug & 8) {
print STDERR "***current_best_file is $fn\n";
}
}
- } elsif ($debug) {
+ } elsif ($debug & 8) {
print " Format invalid\n";
}
}