Viewing file: foomatic-preferred-driver (8.95 KB) -rwxr-xr-x Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
#!/usr/bin/perl
# This is foomatic-preferred driver, it reads the printer database
# overview and puts default driver entries (..) into
# every printer's XML database entry.
use Foomatic::Defaults;
use Foomatic::DB qw/get_overview/;
use Data::Dumper;
use strict;
# Needs "get_overview" to be added to the "@EXPORT_OK" list of DB.pm!
# Read out the program name with which we were called, but discard the path
$0 =~ m!/([^/]+)\s*$!;
my $progname = $1;
my $debug = 0;
my $db = new Foomatic::DB;
# Get the printer overview list as a Perl data structure
$db->get_overview();
print "DB " . Dumper($db ) if $debug;
my $printer;
for $printer (@{$db->{'overview'}}) {
print "$printer->{'make'} $printer->{'model'} ($printer->{'id'})";
if ($printer->{'driver'}) { # We have already a default driver
# Check whether this driver is one which supports the printer
# If yes, this printer has a correct default driver so we do not
# need to set a new default driver
my $found = 0;
for my $d (@{$printer->{'drivers'}}) {
if ($d eq $printer->{'driver'}) {
$found = 1;
last;
}
}
if ($found) {
print " (Keeping old default driver): $printer->{'driver'}\n";
next;
} else {
print " (Default driver wrong)\n";
}
} else {
print " (No default driver defined)\n";
}
if ($printer->{'functionality'} eq 'F') {
# If the printer is a "Paperweight", do not correct the
# default driver, remove the wrong setting and skip the
# printer
$printer->{'driver'} = "";
print ": --> Skipping \"Paperweight\"\n";
} else {
#Sort drivers appropriate to ranking list
my @sorted = sort sortdrivers @{$printer->{'drivers'}};
print ": @sorted --> $sorted[0]\n";
$printer->{'driver'} = $sorted[0];
}
open PRINTERENTRY, "< $libdir/db/source/printer/$printer->{'id'}.xml" bool(false)
|