source: client/bin/gbrm @ 7cdd65d

debianmacno-cups
Last change on this file since 7cdd65d was 7cdd65d, checked in by Kyle Brogle <broglek@…>, 14 years ago

Implemented default queue in client scripts.
Queue argument now optional for gb{r,rm,q}, and also takes form of -q QUEUE
now.

gutenbach-client-config -sset-default QUEUE will set default queue

Updated manpages accordingly.

  • Property mode set to 100755
File size: 1.5 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;
10use Getopt::Long;
11
12my $usage = "Usage: gbq [-q QUEUE] ID\n";
13my $q = "";
14GetOptions ('q|queue=s' => \$q);
15
16my @ids = @ARGV[0 .. $#ARGV];
17
18if (!$q){
19    $q = "DEFAULT";
20}
21if (!@ids) {
22    print $usage;
23    exit 1
24}
25
26
27my $configpath = "$ENV{'HOME'}/.gutenbach/$q";
28if (! -e $configpath) {
29    print "Queue '$q' does not exist!  Did you forget to add it with 'gutenbach-client-config'?\n";
30    exit 1;
31}
32
33my ($host, $queue);
34
35if (-r $configpath) {
36    local $/;
37    my $fh;
38    open $fh, $configpath;
39    eval <$fh>;
40}
41
42my $cups = Net::CUPS->new();
43$cups->setServer("$host");
44my $printer = $cups->getDestination("$queue");
45unless( $printer){
46    print "Cannot access queue $q...do you have network connectivity and permission to view the queue?\n";
47    exit 1;
48}
49my @jobs = $printer->getJobs(0, 0);
50foreach my $id(@ids){
51if ($id eq "all") {
52    foreach $id(@jobs) {
53        cancel_job($id, $printer);
54    }
55}
56elsif ($id eq "current") {
57    $id = $jobs[0];
58    cancel_job($id, $printer);
59}
60elsif ($id eq "last") {
61    $id = $jobs[-1];
62    cancel_job($id, $printer);
63}
64else {
65    foreach my $item(@jobs) {
66        if($item =~ /$id/){
67            cancel_job($item, $printer);
68        }
69    }
70}
71}
72
73sub cancel_job {
74    my ($id, $printer) = @_;
75    my $job_ref = $printer->getJob($id);
76    my $title = $job_ref->{'title'};
77    $printer->cancelJob($id);
78
79    print "Canceled job '$title' (id $id)\n";
80 
81}
Note: See TracBrowser for help on using the repository browser.