source: client/bin/gbrm @ 335786f

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

[Trac #14] gbrm now accepts regex and multiple filename arguments

  • Property mode set to 100755
File size: 1.4 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 @ids = @ARGV[1 .. $#ARGV];
15
16if (!$q or !@ids) {
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");
39unless( $printer){
40    print "Cannot access queue $q...do you have network connectivity and permission to view the queue?\n";
41    exit 1;
42}
43my @jobs = $printer->getJobs(0, 0);
44foreach my $id(@ids){
45if ($id eq "all") {
46    foreach $id(@jobs) {
47        cancel_job($id, $printer);
48    }
49}
50elsif ($id eq "current") {
51    $id = $jobs[0];
52    cancel_job($id, $printer);
53}
54elsif ($id eq "last") {
55    $id = $jobs[-1];
56    cancel_job($id, $printer);
57}
58else {
59    foreach my $item(@jobs) {
60        if($item =~ /$id/){
61            cancel_job($item, $printer);
62        }
63    }
64}
65}
66
67sub cancel_job {
68    my ($id, $printer) = @_;
69    my $job_ref = $printer->getJob($id);
70    my $title = $job_ref->{'title'};
71    $printer->cancelJob($id);
72
73    print "Canceled job '$title' (id $id)\n";
74 
75}
Note: See TracBrowser for help on using the repository browser.