source:
client/bin/gbrm
@
d768767
| Last change on this file since d768767 was d768767, checked in by Jessica B. Hamrick <jhamrick@…>, 16 years ago | |
|---|---|
|
|
| File size: 1.1 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; | |
| 10 | ||
| [2a2f76c] | 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"; | |
| [85a1ac1] | 22 | if (! -e $configpath) { |
| 23 | print "Queue '$q' does not exist!\n"; | |
| 24 | exit 1; | |
| 25 | } | |
| 26 | ||
| [2a2f76c] | 27 | my ($host, $queue); |
| 28 | ||
| 29 | if (-r $configpath) { | |
| 30 | local $/; | |
| 31 | my $fh; | |
| 32 | open $fh, $configpath; | |
| 33 | eval <$fh>; | |
| 34 | } | |
| 35 | ||
| [b58aada] | 36 | my $cups = Net::CUPS->new(); |
| 37 | $cups->setServer("$host"); | |
| 38 | my $printer = $cups->getDestination("$queue"); | |
| 39 | my @jobs = $printer->getJobs(0, 0); | |
| [2a2f76c] | 40 | |
| 41 | if ($id eq "all") { | |
| [b58aada] | 42 | foreach $id(@jobs) { |
| [d768767] | 43 | cancel_job($id, $printer); |
| [b58aada] | 44 | } |
| [2a2f76c] | 45 | } |
| [a81397c] | 46 | elsif ($id eq "current") { |
| [b58aada] | 47 | $id = $jobs[0]; |
| [d768767] | 48 | cancel_job($id, $printer); |
| 49 | } | |
| 50 | elsif ($id eq "last") { | |
| 51 | $id = $jobs[-1]; | |
| 52 | cancel_job($id, $printer); | |
| [a81397c] | 53 | } |
| [2a2f76c] | 54 | else { |
| [d768767] | 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'}; | |
| [b58aada] | 62 | $printer->cancelJob($id); |
| [d768767] | 63 | |
| 64 | print "Canceled job '$title' (id $id)\n"; | |
| [2a2f76c] | 65 | } |
Note: See TracBrowser
for help on using the repository browser.
