source: client/bin/gbrm @ 0d02eca

debianmacno-cupsweb
Last change on this file since 0d02eca was 0d02eca, checked in by Jessica B. Hamrick <jhamrick@…>, 14 years ago

Add a useful reminder message to client scripts, "Did you forget to add it [the queue] with gutenbach-client-config?"

  • Property mode set to 100755
File size: 1.2 KB
Line 
1#!/usr/bin/perl
2
3# Written by Jessica Hamrick (C) 2010
4
5use strict;
6use warnings;
7
8use Net::CUPS;
9use Net::CUPS::Destination;
10
11my $usage = "Usage: gbq QUEUE ID\n";
12
13my $q = $ARGV[0];
14my $id = $ARGV[1];
15
16if (!$q or !$id) {
17    print $usage;
18    exit 1
19}
20
21my $configpath = "$ENV{'HOME'}/.gutenbach/$q";
22if (! -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
27my ($host, $queue);
28
29if (-r $configpath) {
30    local $/;
31    my $fh;
32    open $fh, $configpath;
33    eval <$fh>;
34}
35
36my $cups = Net::CUPS->new();
37$cups->setServer("$host");
38my $printer = $cups->getDestination("$queue");
39my @jobs = $printer->getJobs(0, 0);
40
41if ($id eq "all") {
42    foreach $id(@jobs) {
43        cancel_job($id, $printer);
44    }
45}
46elsif ($id eq "current") {
47    $id = $jobs[0];
48    cancel_job($id, $printer);
49}
50elsif ($id eq "last") {
51    $id = $jobs[-1];
52    cancel_job($id, $printer);
53}
54else {
55    cancel_job($id, $printer);
56}
57
58sub 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.