source:
client/bin/gbrm
@
9fdf4a1
| Last change on this file since 9fdf4a1 was 9fdf4a1, checked in by Kyle Brogle <broglek@…>, 15 years ago | |
|---|---|
|
|
| File size: 1.3 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) { |
| [0d02eca] | 23 | print "Queue '$q' does not exist! Did you forget to add it with 'gutenbach-client-config'?\n"; |
| [85a1ac1] | 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"); | |
| [9fdf4a1] | 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 | } | |
| [b58aada] | 43 | my @jobs = $printer->getJobs(0, 0); |
| [2a2f76c] | 44 | |
| 45 | if ($id eq "all") { | |
| [b58aada] | 46 | foreach $id(@jobs) { |
| [d768767] | 47 | cancel_job($id, $printer); |
| [b58aada] | 48 | } |
| [2a2f76c] | 49 | } |
| [a81397c] | 50 | elsif ($id eq "current") { |
| [b58aada] | 51 | $id = $jobs[0]; |
| [d768767] | 52 | cancel_job($id, $printer); |
| 53 | } | |
| 54 | elsif ($id eq "last") { | |
| 55 | $id = $jobs[-1]; | |
| 56 | cancel_job($id, $printer); | |
| [a81397c] | 57 | } |
| [2a2f76c] | 58 | else { |
| [d768767] | 59 | cancel_job($id, $printer); |
| 60 | } | |
| 61 | ||
| 62 | sub cancel_job { | |
| 63 | my ($id, $printer) = @_; | |
| 64 | my $job_ref = $printer->getJob($id); | |
| 65 | my $title = $job_ref->{'title'}; | |
| [b58aada] | 66 | $printer->cancelJob($id); |
| [d768767] | 67 | |
| 68 | print "Canceled job '$title' (id $id)\n"; | |
| [2a2f76c] | 69 | } |
Note: See TracBrowser
for help on using the repository browser.
