summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--perl-install/printer/cups.pm67
-rw-r--r--perl-install/printer/main.pm39
-rw-r--r--perl-install/printer/printerdrake.pm4
3 files changed, 51 insertions, 59 deletions
diff --git a/perl-install/printer/cups.pm b/perl-install/printer/cups.pm
index 6999c0063..60efc7a04 100644
--- a/perl-install/printer/cups.pm
+++ b/perl-install/printer/cups.pm
@@ -1,30 +1,61 @@
package printer::cups;
use strict;
+
use printer::data;
+use run_program;
+use common;
+
+
+#------------------------------------------------------------------------------
+sub lpstat_v {
+ map {
+ if (my ($queuename, $uri) = m/^\s*device\s+for\s+([^:\s]+):\s*(\S+)\s*$/) {
+ +{ queuename => $queuename, uri => $uri, if_($uri =~ m!^ipp://([^/:]+)[:/]!, ipp => $1) };
+ } else {
+ ();
+ }
+ } run_program::rooted_get_stdout($::prefix, 'lpstat', '-v');
+}
+
+sub read_printer_list {
+ my ($printer) = @_;
+ # This function reads in a list of all printers which the local CUPS
+ # daemon currently knows, including remote ones.
+ map {
+ my $comment =
+ $_->{ipp} && !$printer->{configured}{$_->{queuename}} ?
+ N("(on %s)", $_->{ipp}) : N("(on this machine)");
+ "$_->{queuename} $comment";
+ } lpstat_v();
+}
+
+sub get_formatted_remote_queues {
+ my ($printer) = @_;
+
+ # This function reads in a list of all remote printers which the local
+ # CUPS daemon knows due to broadcasting of remote servers or
+ # "BrowsePoll" entries in the local /etc/cups/cupsd.conf/
+ map {
+ join('!', if_($::expert, N("CUPS")), N("Remote Printers"), $_);
+ } map {
+ my $comment = N("On CUPS server \"%s\"", $_->{ipp}) . ($_->{queuename} eq $printer->{DEFAULT} ? N(" (Default)") : "");
+ "$_->{queuename}: $comment";
+ } grep {
+ $_->{ipp} && !$printer->{configured}{$_->{queuename}};
+ } lpstat_v();
+}
sub get_remote_queues {
- my ($printer) = $_[0];
+ my ($printer) = @_;
# The following code reads in a list of all remote printers which the
# local CUPS daemon knows due to broadcasting of remote servers or
# "BrowsePoll" entries in the local /etc/cups/cupsd.conf
- local *F;
- open F, ($::testing ? $::prefix : "chroot $::prefix/ ") .
- "lpstat -v |" or return ();
- my @printerlist;
- my $line;
- while ($line = <F>) {
- if ($line =~ m/^\s*device\s+for\s+([^:\s]+):\s*(\S+)\s*$/) {
- my $queuename = $1;
- if ($2 =~ m!^ipp://([^/:]+)[:/]! &&
- !$printer->{configured}{$queuename}) {
- my $server = $1;
- push @printerlist, "$queuename|$server";
- }
- }
- }
- close F;
- return @printerlist;
+ map {
+ "$_->{queuename}|$_->{ipp}";
+ } grep {
+ $_->{ipp} && !$printer->{configured}{$_->{queuename}};
+ } lpstat_v();
}
1;
diff --git a/perl-install/printer/main.pm b/perl-install/printer/main.pm
index 329834e0a..ebf29db59 100644
--- a/perl-install/printer/main.pm
+++ b/perl-install/printer/main.pm
@@ -627,45 +627,6 @@ sub set_cups_special_options {
return 1;
}
-#------------------------------------------------------------------------------
-sub lpstat_v {
- map {
- if (my ($queuename, $uri) = m/^\s*device\s+for\s+([^:\s]+):\s*(\S+)\s*$/) {
- +{ queuename => $queuename, uri => $uri, if_($uri =~ m!^ipp://([^/:]+)[:/]!, ipp => $1) };
- } else {
- ();
- }
- } run_program::rooted_get_stdout($::prefix, 'lpstat', '-v');
-}
-
-sub read_cups_printer_list {
- my ($printer) = @_;
- # This function reads in a list of all printers which the local CUPS
- # daemon currently knows, including remote ones.
- map {
- my $comment =
- $_->{ipp} && !$printer->{configured}{$_->{queuename}} ?
- N("(on %s)", $_->{ipp}) : N("(on this machine)");
- "$_->{queuename} $comment";
- } lpstat_v();
-}
-
-sub get_cups_remote_queues {
- my ($printer) = @_;
-
- # This function reads in a list of all remote printers which the local
- # CUPS daemon knows due to broadcasting of remote servers or
- # "BrowsePoll" entries in the local /etc/cups/cupsd.conf/
- map {
- join('!', if_($::expert, N("CUPS")), N("Remote Printers"), $_);
- } map {
- my $comment = N("On CUPS server \"%s\"", $_->{ipp}) . ($_->{queuename} eq $printer->{DEFAULT} ? N(" (Default)") : "");
- "$_->{queuename}: $comment";
- } grep {
- $_->{ipp} && !$printer->{configured}{$_->{queuename}};
- } lpstat_v();
-}
-
sub set_cups_autoconf {
my $autoconf = $_[0];
diff --git a/perl-install/printer/printerdrake.pm b/perl-install/printer/printerdrake.pm
index 318bcfe3d..27a08eeac 100644
--- a/perl-install/printer/printerdrake.pm
+++ b/perl-install/printer/printerdrake.pm
@@ -2889,7 +2889,7 @@ sub main {
} elsif ($printer->{SPOOLER} eq "cups") {
($cursorpos) =
grep { /!$printer->{DEFAULT}:[^!]*$/ }
- printer::main::get_cups_remote_queues($printer);
+ printer::cups::get_formatted_remote_queues($printer);
}
}
# Generate the list of available printers
@@ -2900,7 +2900,7 @@ sub main {
keys(%{$printer->{configured}
|| {}})),
($printer->{SPOOLER} eq "cups" ?
- printer::main::get_cups_remote_queues($printer) :
+ printer::cups::get_formatted_remote_queues($printer) :
()));
my $noprinters = $#printerlist < 0;
# Position the cursor where it were before (in case