debianmacno-cups
Last change
on this file since 9dee329 was
7cdd65d,
checked in by Kyle Brogle <broglek@…>, 14 years ago
|
Implemented default queue in client scripts.
Queue argument now optional for gb{r,rm,q}, and also takes form of -q QUEUE
now.
gutenbach-client-config -sset-default QUEUE will set default queue
Updated manpages accordingly.
|
-
Property mode set to
100755
|
File size:
1.5 KB
|
Line | |
---|
1 | #!/usr/bin/perl |
---|
2 | |
---|
3 | # Written by Jessica Hamrick (C) 2010 |
---|
4 | |
---|
5 | use strict; |
---|
6 | use warnings; |
---|
7 | |
---|
8 | use Net::CUPS; |
---|
9 | use Net::CUPS::Destination; |
---|
10 | use Getopt::Long; |
---|
11 | |
---|
12 | my $usage = "Usage: gbq [-q QUEUE] ID\n"; |
---|
13 | my $q = ""; |
---|
14 | GetOptions ('q|queue=s' => \$q); |
---|
15 | |
---|
16 | my @ids = @ARGV[0 .. $#ARGV]; |
---|
17 | |
---|
18 | if (!$q){ |
---|
19 | $q = "DEFAULT"; |
---|
20 | } |
---|
21 | if (!@ids) { |
---|
22 | print $usage; |
---|
23 | exit 1 |
---|
24 | } |
---|
25 | |
---|
26 | |
---|
27 | my $configpath = "$ENV{'HOME'}/.gutenbach/$q"; |
---|
28 | if (! -e $configpath) { |
---|
29 | print "Queue '$q' does not exist! Did you forget to add it with 'gutenbach-client-config'?\n"; |
---|
30 | exit 1; |
---|
31 | } |
---|
32 | |
---|
33 | my ($host, $queue); |
---|
34 | |
---|
35 | if (-r $configpath) { |
---|
36 | local $/; |
---|
37 | my $fh; |
---|
38 | open $fh, $configpath; |
---|
39 | eval <$fh>; |
---|
40 | } |
---|
41 | |
---|
42 | my $cups = Net::CUPS->new(); |
---|
43 | $cups->setServer("$host"); |
---|
44 | my $printer = $cups->getDestination("$queue"); |
---|
45 | unless( $printer){ |
---|
46 | print "Cannot access queue $q...do you have network connectivity and permission to view the queue?\n"; |
---|
47 | exit 1; |
---|
48 | } |
---|
49 | my @jobs = $printer->getJobs(0, 0); |
---|
50 | foreach my $id(@ids){ |
---|
51 | if ($id eq "all") { |
---|
52 | foreach $id(@jobs) { |
---|
53 | cancel_job($id, $printer); |
---|
54 | } |
---|
55 | } |
---|
56 | elsif ($id eq "current") { |
---|
57 | $id = $jobs[0]; |
---|
58 | cancel_job($id, $printer); |
---|
59 | } |
---|
60 | elsif ($id eq "last") { |
---|
61 | $id = $jobs[-1]; |
---|
62 | cancel_job($id, $printer); |
---|
63 | } |
---|
64 | else { |
---|
65 | foreach my $item(@jobs) { |
---|
66 | if($item =~ /$id/){ |
---|
67 | cancel_job($item, $printer); |
---|
68 | } |
---|
69 | } |
---|
70 | } |
---|
71 | } |
---|
72 | |
---|
73 | sub cancel_job { |
---|
74 | my ($id, $printer) = @_; |
---|
75 | my $job_ref = $printer->getJob($id); |
---|
76 | my $title = $job_ref->{'title'}; |
---|
77 | $printer->cancelJob($id); |
---|
78 | |
---|
79 | print "Canceled job '$title' (id $id)\n"; |
---|
80 | |
---|
81 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.