summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTill Kamppeter <tkamppeter@mandriva.com>2003-01-27 03:52:34 +0000
committerTill Kamppeter <tkamppeter@mandriva.com>2003-01-27 03:52:34 +0000
commitd73f0db76b89b9fedb8747d2a622c9c401639078 (patch)
treeb7442d48a7d10f6433658784fa33b8053cc86ec9
parenta246914b7f2bad675b0a2fe937aa55c34293c2c2 (diff)
downloaddrakx-backup-do-not-use-d73f0db76b89b9fedb8747d2a622c9c401639078.tar
drakx-backup-do-not-use-d73f0db76b89b9fedb8747d2a622c9c401639078.tar.gz
drakx-backup-do-not-use-d73f0db76b89b9fedb8747d2a622c9c401639078.tar.bz2
drakx-backup-do-not-use-d73f0db76b89b9fedb8747d2a622c9c401639078.tar.xz
drakx-backup-do-not-use-d73f0db76b89b9fedb8747d2a622c9c401639078.zip
Adapted printerdrake to Foomatic 2.9.x, bug fix for use of native PPDs in recommended mode, bug fixes in association between detected printers and existing queues.
-rw-r--r--perl-install/printer/main.pm103
-rw-r--r--perl-install/printer/printerdrake.pm100
2 files changed, 122 insertions, 81 deletions
diff --git a/perl-install/printer/main.pm b/perl-install/printer/main.pm
index a63395181..de5e5e7ad 100644
--- a/perl-install/printer/main.pm
+++ b/perl-install/printer/main.pm
@@ -259,7 +259,7 @@ sub read_configured_queues($) {
if ($printer->{SPOOLER} eq "cups") {
$printer->{OLD_QUEUE} = $QUEUES[$i]{queuedata}{queue};
my $descr = get_descr_from_ppd($printer);
- $descr =~ m/^([^\|]*)\|([^\|]*)\|.*$/;
+ $descr =~ m/^([^\|]*)\|([^\|]*)(\|.*|)$/;
$printer->{configured}{$QUEUES[$i]{queuedata}{queue}}{queuedata}{make} ||= $1;
$printer->{configured}{$QUEUES[$i]{queuedata}{queue}}{queuedata}{model} ||= $2;
# Read out which PPD file was originally used to set up this
@@ -310,7 +310,9 @@ sub make_menuentry {
my $spooler = $shortspooler_inv{$printer->{SPOOLER}}{short_name};
my $connect = $printer->{configured}{$queue}{queuedata}{connect};
my $localremote;
- if ($connect =~ m!^file:! || $connect =~ m!^ptal:/mlc:!) {
+ if ($connect =~ m!^(file|parallel|usb|serial):! ||
+ $connect =~ m!^ptal:/mlc:! ||
+ $connect =~ m!^mtink:!) {
$localremote = N("Local Printers");
} else {
$localremote = N("Remote Printers");
@@ -318,12 +320,14 @@ sub make_menuentry {
my $make = $printer->{configured}{$queue}{queuedata}{make};
my $model = $printer->{configured}{$queue}{queuedata}{model};
my $connection;
- if ($connect =~ m!^file:/dev/lp(\d+)$!) {
- my $number = $1;
+ if ($connect =~ m!^(file|parallel):/dev/lp(\d+)$!) {
+ my $number = $2;
$connection = N(" on parallel port \#%s", $number);
- } elsif ($connect =~ m!^file:/dev/usb/lp(\d+)$!) {
- my $number = $1;
+ } elsif ($connect =~ m!^(file|usb):/dev/usb/lp(\d+)$!) {
+ my $number = $2;
$connection = N(", USB printer \#%s", $number);
+ } elsif ($connect =~ m!^usb://!) {
+ $connection = N(", USB printer");
} elsif ($connect =~ m!^ptal:/(.+)$!) {
my $ptaldevice = $1;
if ($ptaldevice =~ /^mlc:par:(\d+)$/) {
@@ -1483,6 +1487,9 @@ sub get_descr_from_ppd {
my %ppd;
#- if there is no ppd, this means this is a raw queue.
+ if (! -r "$::prefix/etc/cups/ppd/$printer->{OLD_QUEUE}.ppd") {
+ return "|" . N("Unknown model");
+ }
eval {
local $_;
foreach (cat_("$::prefix/etc/cups/ppd/$printer->{OLD_QUEUE}.ppd")) {
@@ -1492,8 +1499,7 @@ sub get_descr_from_ppd {
/^\*([^\s:]*)\s*:\s*([^\s\"]*)/ and
do { $ppd{$1} = $2; next };
}
- } or return "|" . N("Unknown model");
-
+ };
my $descr = ($ppd{NickName} || $ppd{ShortNickName} || $ppd{ModelName});
my $make = $ppd{Manufacturer};
my $lang = $ppd{LanguageVersion};
@@ -1603,60 +1609,35 @@ sub poll_ppd_base {
sub configure_queue($) {
my ($printer) = @_;
- if ($printer->{currentqueue}{foomatic}) {
- #- Create the queue with "foomatic-configure", in case of queue
- #- renaming copy the old queue
- run_program::rooted($::prefix, "foomatic-configure", "-q",
- "-s", $printer->{currentqueue}{spooler},
- "-n", $printer->{currentqueue}{queue},
- ($printer->{currentqueue}{queue} ne $printer->{OLD_QUEUE} &&
- $printer->{configured}{$printer->{OLD_QUEUE}} ?
- ("-C", $printer->{OLD_QUEUE}) : ()),
- "-c", $printer->{currentqueue}{connect},
- "-p", $printer->{currentqueue}{printer},
- "-d", $printer->{currentqueue}{driver},
- "-N", $printer->{currentqueue}{desc},
- "-L", $printer->{currentqueue}{loc},
- @{$printer->{currentqueue}{options}}
- ) or die "foomatic-configure failed";
- } elsif ($printer->{currentqueue}{ppd}) {
- #- If the chosen driver is a PPD file from /usr/share/cups/model,
- #- we use lpadmin to set up the queue
- run_program::rooted($::prefix, "lpadmin",
- "-p", $printer->{currentqueue}{queue},
-# $printer->{State} eq 'Idle' &&
-# $printer->{Accepting} eq 'Yes' ? ("-E") : (),
- "-E",
- "-v", $printer->{currentqueue}{connect},
- $printer->{currentqueue}{ppd} ne '1' ?
- ("-m", $printer->{currentqueue}{ppd}) : (),
- $printer->{currentqueue}{desc} ?
- ("-D", $printer->{currentqueue}{desc}) : (),
- $printer->{currentqueue}{loc} ?
- ("-L", $printer->{currentqueue}{loc}) : (),
- @{$printer->{currentqueue}{options}}
- ) or die "lpadmin failed";
+ #- Create the queue with "foomatic-configure", in case of queue
+ #- renaming copy the old queue
+ run_program::rooted($::prefix, "foomatic-configure", "-q",
+ "-s", $printer->{currentqueue}{spooler},
+ "-n", $printer->{currentqueue}{queue},
+ ($printer->{currentqueue}{queue} ne
+ $printer->{OLD_QUEUE} &&
+ $printer->{configured}{$printer->{OLD_QUEUE}} ?
+ ("-C", $printer->{OLD_QUEUE}) : ()),
+ "-c", $printer->{currentqueue}{connect},
+ ($printer->{currentqueue}{foomatic} ?
+ ("-p", $printer->{currentqueue}{printer},
+ "-d", $printer->{currentqueue}{driver}) :
+ ($printer->{currentqueue}{ppd} ?
+ ("--ppd",
+ ($printer->{currentqueue}{ppd} !~ m!^/! ?
+ "/usr/share/cups/model/" : "") .
+ $printer->{currentqueue}{ppd}) :
+ ("-d", "raw"))),
+ "-N", $printer->{currentqueue}{desc},
+ "-L", $printer->{currentqueue}{loc},
+ @{$printer->{currentqueue}{options}}
+ ) or return 0;;
+ if ($printer->{currentqueue}{ppd}) {
# Add a comment line containing the path of the used PPD file to the
# end of the PPD file
if ($printer->{currentqueue}{ppd} ne '1') {
append_to_file("$::prefix/etc/cups/ppd/$printer->{currentqueue}{queue}.ppd", "*%MDKMODELCHOICE:$printer->{currentqueue}{ppd}\n");
}
- # Copy the old queue's PPD file to the new queue when it is renamed,
- # to conserve the option settings
- if ($printer->{currentqueue}{queue} ne $printer->{OLD_QUEUE} &&
- $printer->{configured}{$printer->{OLD_QUEUE}}) {
- system("cp -f $::prefix/etc/cups/ppd/$printer->{OLD_QUEUE}.ppd $::prefix/etc/cups/ppd/$printer->{currentqueue}{queue}.ppd");
- }
- } else {
- # Raw queue
- run_program::rooted($::prefix, "foomatic-configure", "-q",
- "-s", $printer->{currentqueue}{spooler},
- "-n", $printer->{currentqueue}{queue},
- "-c", $printer->{currentqueue}{connect},
- "-d", $printer->{currentqueue}{driver},
- "-N", $printer->{currentqueue}{desc},
- "-L", $printer->{currentqueue}{loc}
- ) or die "foomatic-configure failed";
}
# Make sure that queue is active
@@ -1666,7 +1647,8 @@ sub configure_queue($) {
"-C", "up", $printer->{currentqueue}{queue});
}
- # In case of CUPS set some more useful defaults for text and image printing
+ # In case of CUPS set some more useful defaults for text and image
+ # printing
if ($printer->{SPOOLER} eq "cups") {
set_cups_special_options($printer->{currentqueue}{queue});
}
@@ -1688,7 +1670,8 @@ sub configure_queue($) {
# Open permissions for device file when PDQ is chosen as spooler
# so normal users can print.
if ($printer->{SPOOLER} eq 'pdq') {
- if ($printer->{currentqueue}{connect} =~ m!^\s*file:(\S*)\s*$!) {
+ if ($printer->{currentqueue}{connect} =~
+ m!^\s*(file|parallel|usb|serial):(\S*)\s*$!) {
set_permissions($1, "666");
}
}
@@ -1720,6 +1703,8 @@ sub configure_queue($) {
$printer->{ARGS} = {};
$printer->{DBENTRY} = "";
$printer->{currentqueue} = {};
+
+ return 1;
}
sub remove_queue($$) {
diff --git a/perl-install/printer/printerdrake.pm b/perl-install/printer/printerdrake.pm
index 79bd6a6e4..48f498985 100644
--- a/perl-install/printer/printerdrake.pm
+++ b/perl-install/printer/printerdrake.pm
@@ -564,7 +564,7 @@ sub setup_local_autoscan {
} elsif ($p->{port} =~ m!^smb://([^/:]+)/([^/:]+)$!) {
$menustr .= N(", printer \"%s\" on SMB/Windows server \"%s\"", $2, $1);
}
- $menustr .= " ($p->{port})" if $::expert;
+ $menustr .= " ($p->{port})" if $::expert;
$menuentries->{$menustr} = $p->{port};
push @str, N("Detected %s", $menustr);
} else {
@@ -585,7 +585,7 @@ sub setup_local_autoscan {
my @port;
if ($::expert) {
@port = detect_devices::whatPrinterPort();
- LOOP: foreach my $q (@port) {
+ LOOP: foreach my $q (@port) {
if (@str) {
foreach my $p (@autodetected) {
last LOOP if $p->{port} eq $q;
@@ -634,9 +634,36 @@ sub setup_local_autoscan {
my $oldmenuchoice = "";
my $device;
if ($printer->{configured}{$queue} &&
- $printer->{currentqueue}{connect} =~ m/^file:/) {
+ $printer->{currentqueue}{connect} =~
+ m!^usb://([^/]+)/([^/\?]+)(|\?serial=(\S+))$!) {
+ # USB device with URI referring to printer model
+ my $make = $1;
+ my $model = $2;
+ my $serial = $4;
+ if ($make and $model) {
+ $make =~ s/\%20/ /g;
+ $model =~ s/\%20/ /g;
+ $serial =~ s/\%20/ /g;
+ $make =~ s/Hewlett[-\s_]Packard/HP/;
+ $make =~ s/HEWLETT[-\s_]PACKARD/HP/;
+ foreach my $p (@autodetected) {
+ next if (!$p->{val}{MANUFACTURER} or
+ ($p->{val}{MANUFACTURER} ne $make));
+ next if (!$p->{val}{MODEL} or
+ ($p->{val}{MODEL} ne $model));
+ next if ((!$p->{val}{SERIALNUMBER} and $serial) or
+ ($p->{val}{SERIALNUMBER} and !$serial) or
+ ($p->{val}{SERIALNUMBER} ne $serial));
+ $device = $p->{port};
+ $menuchoice = { reverse %$menuentries }->{$device}
+ }
+ }
+ } elsif ($printer->{configured}{$queue} &&
+ $printer->{currentqueue}{connect} =~
+ m/^(file|parallel|usb|serial):/) {
# Non-HP or HP print-only device (HPOJ not used)
$device = $printer->{currentqueue}{connect};
+ $device =~ s/^(file|parallel|usb|serial)://;
$menuchoice = { reverse %$menuentries }->{$device}
} elsif ($printer->{configured}{$queue} &&
$printer->{currentqueue}{connect} =~ m!^ptal:/mlc:!) {
@@ -646,13 +673,12 @@ sub setup_local_autoscan {
if ($ptaldevice =~ /^par:(\d+)$/) {
$menuchoice = { reverse %$menuentries }->{"/dev/lp$1"}
} else {
- my $make = lc($printer->{currentqueue}{make});
- my $model = lc($printer->{currentqueue}{model});
+ $ptaldevice =~ /^usb:(.*)$/;
+ my $model = $1;
+ $model =~ s/_/ /g;
$device = "";
foreach my $p (keys %{$menuentries}) {
- my $menumakemodel = lc($p);
- if ($menumakemodel =~ /$make/ &&
- $menumakemodel =~ /$model/) {
+ if ($p =~ /$model/i) {
$menuchoice = $p;
$device = $menuentries->{$p};
last;
@@ -1264,13 +1290,16 @@ N("You can specify directly the URI to access the printer. The URI must fulfill
{ label => N("Printer Device URI"),
val => \$printer->{currentqueue}{connect},
list => [ $printer->{currentqueue}{connect},
- "file:/",
+ "parallel:/",
+ "usb:/",
+ "serial:/",
"http://",
"ipp://",
"lpd://",
"smb://",
"ncp://",
"socket://",
+ "file:/",
"postpipe:\"\"",
], not_edit => 0 }, ],
complete => sub {
@@ -1490,8 +1519,20 @@ sub setup_common {
}
if ($printer->{currentqueue}{connect} !~ /:/) {
- $printer->{currentqueue}{connect} =
- "file:" . $printer->{currentqueue}{connect};
+ if ($printer->{currentqueue}{connect} =~ /usb/) {
+ $printer->{currentqueue}{connect} =
+ "usb:" . $printer->{currentqueue}{connect};
+ } elsif ($printer->{currentqueue}{connect} =~ /(serial|tty)/) {
+ $printer->{currentqueue}{connect} =
+ "serial:" . $printer->{currentqueue}{connect};
+ } elsif ($printer->{currentqueue}{connect} =~
+ /(printers|parallel|parport|lp\d)/) {
+ $printer->{currentqueue}{connect} =
+ "parallel:" . $printer->{currentqueue}{connect};
+ } else {
+ $printer->{currentqueue}{connect} =
+ "file:" . $printer->{currentqueue}{connect};
+ }
}
#- if CUPS is the spooler, make sure that CUPS knows the device
@@ -1864,6 +1905,12 @@ N("If your printer is not listed, choose a compatible (see printer manual) or a
}
my %lexmarkinkjet_options = (
+ 'parallel:/dev/lp0' => " -o Port=ParPort1",
+ 'parallel:/dev/lp1' => " -o Port=ParPort2",
+ 'parallel:/dev/lp2' => " -o Port=ParPort3",
+ 'usb:/dev/usb/lp0' => " -o Port=USB1",
+ 'usb:/dev/usb/lp1' => " -o Port=USB2",
+ 'usb:/dev/usb/lp2' => " -o Port=USB3",
'file:/dev/lp0' => " -o Port=ParPort1",
'file:/dev/lp1' => " -o Port=ParPort2",
'file:/dev/lp2' => " -o Port=ParPort3",
@@ -1942,8 +1989,8 @@ sub get_printer_info {
# oki4w driver -> OKI winprinter which needs the
# oki4daemon to work
if ($printer->{currentqueue}{driver} eq 'oki4w') {
- if ($printer->{currentqueue}{connect} ne
- 'file:/dev/lp0') {
+ if ($printer->{currentqueue}{connect} !~
+ m!^(parallel|file):/dev/lp0$!) {
$in->ask_warn(N("OKI winprinter configuration"),
N("You are configuring an OKI laser winprinter. These printers\nuse a very special communication protocol and therefore they work only when connected to the first parallel port. When your printer is connected to another port or to a print server box please connect the printer to the first parallel port before you print a test page. Otherwise the printer will not work. Your connection type setting will be ignored by the driver."));
}
@@ -1970,13 +2017,14 @@ sub get_printer_info {
return 0;
}
# Set device permissions
- $printer->{currentqueue}{connect} =~ /^\s*file:(\S*)\s*$/;
+ $printer->{currentqueue}{connect} =~
+ /^\s*(file|parallel|usb):(\S*)\s*$/;
if ($printer->{SPOOLER} eq 'cups') {
- set_permissions($1, '660', 'lp', 'sys');
+ set_permissions($2, '660', 'lp', 'sys');
} elsif ($printer->{SPOOLER} eq 'pdq') {
- set_permissions($1, '666');
+ set_permissions($2, '666');
} else {
- set_permissions($1, '660', 'lp', 'lp');
+ set_permissions($2, '660', 'lp', 'lp');
}
# This is needed to have the device not blocked by the
# spooler backend.
@@ -2928,11 +2976,19 @@ sub setup_default_spooler {
sub configure_queue {
my ($printer, $in) = @_;
- my $_w = $in->wait_message(N("Printerdrake"), N("Configuring printer \"%s\"...",
- $printer->{currentqueue}{queue}));
+ my $_w = $in->wait_message(N("Printerdrake"),
+ N("Configuring printer \"%s\"...",
+ $printer->{currentqueue}{queue}));
$printer->{complete} = 1;
- printer::main::configure_queue($printer);
+ my $retval = printer::main::configure_queue($printer);
$printer->{complete} = 0;
+ if (!$retval) {
+ local $::isWizard = 0;
+ $in->ask_warn(N("Printerdrake"),
+ N("Failed to configure printer \"%s\"!",
+ $printer->{currentqueue}{queue}));
+ }
+ return $retval;
}
sub install_foomatic {
@@ -3321,7 +3377,7 @@ sub main {
step_5:
setup_options($printer, $in) or
goto step_4;
- configure_queue($printer, $in);
+ configure_queue($printer, $in) or die 'wizcancel';
undef $printer->{MANUAL} if $printer->{MANUAL};
$::Wizard_no_previous = 1;
setasdefault($printer, $in);
@@ -3373,7 +3429,7 @@ sub main {
}
get_printer_info($printer, $in) or next;
setup_options($printer, $in) or next;
- configure_queue($printer, $in);
+ configure_queue($printer, $in) or next;
undef $printer->{MANUAL} if $printer->{MANUAL};
setasdefault($printer, $in);
$cursorpos =