debianmacno-cupsweb
Last change
on this file since d768767 was
d768767,
checked in by Jessica B. Hamrick <jhamrick@…>, 14 years ago
|
Add 'last' keyword for gbrm
|
-
Property mode set to
100755
|
File size:
1.1 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 | |
---|
11 | my $usage = "Usage: gbq QUEUE ID\n"; |
---|
12 | |
---|
13 | my $q = $ARGV[0]; |
---|
14 | my $id = $ARGV[1]; |
---|
15 | |
---|
16 | if (!$q or !$id) { |
---|
17 | print $usage; |
---|
18 | exit 1 |
---|
19 | } |
---|
20 | |
---|
21 | my $configpath = "$ENV{'HOME'}/.gutenbach/$q"; |
---|
22 | if (! -e $configpath) { |
---|
23 | print "Queue '$q' does not exist!\n"; |
---|
24 | exit 1; |
---|
25 | } |
---|
26 | |
---|
27 | my ($host, $queue); |
---|
28 | |
---|
29 | if (-r $configpath) { |
---|
30 | local $/; |
---|
31 | my $fh; |
---|
32 | open $fh, $configpath; |
---|
33 | eval <$fh>; |
---|
34 | } |
---|
35 | |
---|
36 | my $cups = Net::CUPS->new(); |
---|
37 | $cups->setServer("$host"); |
---|
38 | my $printer = $cups->getDestination("$queue"); |
---|
39 | my @jobs = $printer->getJobs(0, 0); |
---|
40 | |
---|
41 | if ($id eq "all") { |
---|
42 | foreach $id(@jobs) { |
---|
43 | cancel_job($id, $printer); |
---|
44 | } |
---|
45 | } |
---|
46 | elsif ($id eq "current") { |
---|
47 | $id = $jobs[0]; |
---|
48 | cancel_job($id, $printer); |
---|
49 | } |
---|
50 | elsif ($id eq "last") { |
---|
51 | $id = $jobs[-1]; |
---|
52 | cancel_job($id, $printer); |
---|
53 | } |
---|
54 | else { |
---|
55 | cancel_job($id, $printer); |
---|
56 | } |
---|
57 | |
---|
58 | sub cancel_job { |
---|
59 | my ($id, $printer) = @_; |
---|
60 | my $job_ref = $printer->getJob($id); |
---|
61 | my $title = $job_ref->{'title'}; |
---|
62 | $printer->cancelJob($id); |
---|
63 | |
---|
64 | print "Canceled job '$title' (id $id)\n"; |
---|
65 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.