debianmacno-cups
Last change
on this file since 335786f was
335786f,
checked in by Kyle Brogle <broglek@…>, 14 years ago
|
[Trac #14] gbrm now accepts regex and multiple filename arguments
|
-
Property mode set to
100755
|
File size:
1.4 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 @ids = @ARGV[1 .. $#ARGV]; |
---|
15 | |
---|
16 | if (!$q or !@ids) { |
---|
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! Did you forget to add it with 'gutenbach-client-config'?\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 | unless( $printer){ |
---|
40 | print "Cannot access queue $q...do you have network connectivity and permission to view the queue?\n"; |
---|
41 | exit 1; |
---|
42 | } |
---|
43 | my @jobs = $printer->getJobs(0, 0); |
---|
44 | foreach my $id(@ids){ |
---|
45 | if ($id eq "all") { |
---|
46 | foreach $id(@jobs) { |
---|
47 | cancel_job($id, $printer); |
---|
48 | } |
---|
49 | } |
---|
50 | elsif ($id eq "current") { |
---|
51 | $id = $jobs[0]; |
---|
52 | cancel_job($id, $printer); |
---|
53 | } |
---|
54 | elsif ($id eq "last") { |
---|
55 | $id = $jobs[-1]; |
---|
56 | cancel_job($id, $printer); |
---|
57 | } |
---|
58 | else { |
---|
59 | foreach my $item(@jobs) { |
---|
60 | if($item =~ /$id/){ |
---|
61 | cancel_job($item, $printer); |
---|
62 | } |
---|
63 | } |
---|
64 | } |
---|
65 | } |
---|
66 | |
---|
67 | sub cancel_job { |
---|
68 | my ($id, $printer) = @_; |
---|
69 | my $job_ref = $printer->getJob($id); |
---|
70 | my $title = $job_ref->{'title'}; |
---|
71 | $printer->cancelJob($id); |
---|
72 | |
---|
73 | print "Canceled job '$title' (id $id)\n"; |
---|
74 | |
---|
75 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.