source:
client/bin/gbrm
@
600e713
Last change on this file since 600e713 was 7cdd65d, checked in by Kyle Brogle <broglek@…>, 14 years ago | |
---|---|
|
|
File size: 1.5 KB |
Rev | Line | |
---|---|---|
[2a2f76c] | 1 | #!/usr/bin/perl |
2 | ||
3 | # Written by Jessica Hamrick (C) 2010 | |
4 | ||
5 | use strict; | |
6 | use warnings; | |
7 | ||
[a81397c] | 8 | use Net::CUPS; |
9 | use Net::CUPS::Destination; | |
[7cdd65d] | 10 | use Getopt::Long; |
[a81397c] | 11 | |
[7cdd65d] | 12 | my $usage = "Usage: gbq [-q QUEUE] ID\n"; |
13 | my $q = ""; | |
14 | GetOptions ('q|queue=s' => \$q); | |
[2a2f76c] | 15 | |
[7cdd65d] | 16 | my @ids = @ARGV[0 .. $#ARGV]; |
[2a2f76c] | 17 | |
[7cdd65d] | 18 | if (!$q){ |
19 | $q = "DEFAULT"; | |
20 | } | |
21 | if (!@ids) { | |
[2a2f76c] | 22 | print $usage; |
23 | exit 1 | |
24 | } | |
25 | ||
[7cdd65d] | 26 | |
[2a2f76c] | 27 | my $configpath = "$ENV{'HOME'}/.gutenbach/$q"; |
[85a1ac1] | 28 | if (! -e $configpath) { |
[0d02eca] | 29 | print "Queue '$q' does not exist! Did you forget to add it with 'gutenbach-client-config'?\n"; |
[85a1ac1] | 30 | exit 1; |
31 | } | |
32 | ||
[2a2f76c] | 33 | my ($host, $queue); |
34 | ||
35 | if (-r $configpath) { | |
36 | local $/; | |
37 | my $fh; | |
38 | open $fh, $configpath; | |
39 | eval <$fh>; | |
40 | } | |
41 | ||
[b58aada] | 42 | my $cups = Net::CUPS->new(); |
43 | $cups->setServer("$host"); | |
44 | my $printer = $cups->getDestination("$queue"); | |
[9fdf4a1] | 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 | } | |
[b58aada] | 49 | my @jobs = $printer->getJobs(0, 0); |
[335786f] | 50 | foreach my $id(@ids){ |
[2a2f76c] | 51 | if ($id eq "all") { |
[b58aada] | 52 | foreach $id(@jobs) { |
[d768767] | 53 | cancel_job($id, $printer); |
[b58aada] | 54 | } |
[2a2f76c] | 55 | } |
[a81397c] | 56 | elsif ($id eq "current") { |
[b58aada] | 57 | $id = $jobs[0]; |
[d768767] | 58 | cancel_job($id, $printer); |
59 | } | |
60 | elsif ($id eq "last") { | |
61 | $id = $jobs[-1]; | |
62 | cancel_job($id, $printer); | |
[a81397c] | 63 | } |
[2a2f76c] | 64 | else { |
[335786f] | 65 | foreach my $item(@jobs) { |
66 | if($item =~ /$id/){ | |
67 | cancel_job($item, $printer); | |
68 | } | |
69 | } | |
70 | } | |
[d768767] | 71 | } |
72 | ||
73 | sub cancel_job { | |
74 | my ($id, $printer) = @_; | |
75 | my $job_ref = $printer->getJob($id); | |
76 | my $title = $job_ref->{'title'}; | |
[b58aada] | 77 | $printer->cancelJob($id); |
[d768767] | 78 | |
79 | print "Canceled job '$title' (id $id)\n"; | |
[335786f] | 80 | |
[2a2f76c] | 81 | } |
Note: See TracBrowser
for help on using the repository browser.