source: client/bin/gbrm @ 600e713

debianmacno-cups
Last change on this file since 600e713 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
RevLine 
[2a2f76c]1#!/usr/bin/perl
2
3# Written by Jessica Hamrick (C) 2010
4
5use strict;
6use warnings;
7
[a81397c]8use Net::CUPS;
9use Net::CUPS::Destination;
[7cdd65d]10use Getopt::Long;
[a81397c]11
[7cdd65d]12my $usage = "Usage: gbq [-q QUEUE] ID\n";
13my $q = "";
14GetOptions ('q|queue=s' => \$q);
[2a2f76c]15
[7cdd65d]16my @ids = @ARGV[0 .. $#ARGV];
[2a2f76c]17
[7cdd65d]18if (!$q){
19    $q = "DEFAULT";
20}
21if (!@ids) {
[2a2f76c]22    print $usage;
23    exit 1
24}
25
[7cdd65d]26
[2a2f76c]27my $configpath = "$ENV{'HOME'}/.gutenbach/$q";
[85a1ac1]28if (! -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]33my ($host, $queue);
34
35if (-r $configpath) {
36    local $/;
37    my $fh;
38    open $fh, $configpath;
39    eval <$fh>;
40}
41
[b58aada]42my $cups = Net::CUPS->new();
43$cups->setServer("$host");
44my $printer = $cups->getDestination("$queue");
[9fdf4a1]45unless( $printer){
46    print "Cannot access queue $q...do you have network connectivity and permission to view the queue?\n";
47    exit 1;
48}
[b58aada]49my @jobs = $printer->getJobs(0, 0);
[335786f]50foreach my $id(@ids){
[2a2f76c]51if ($id eq "all") {
[b58aada]52    foreach $id(@jobs) {
[d768767]53        cancel_job($id, $printer);
[b58aada]54    }
[2a2f76c]55}
[a81397c]56elsif ($id eq "current") {
[b58aada]57    $id = $jobs[0];
[d768767]58    cancel_job($id, $printer);
59}
60elsif ($id eq "last") {
61    $id = $jobs[-1];
62    cancel_job($id, $printer);
[a81397c]63}
[2a2f76c]64else {
[335786f]65    foreach my $item(@jobs) {
66        if($item =~ /$id/){
67            cancel_job($item, $printer);
68        }
69    }
70}
[d768767]71}
72
73sub 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.