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
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;
10
[2a2f76c]11my $usage = "Usage: gbq QUEUE ID\n";
12
13my $q = $ARGV[0];
[335786f]14my @ids = @ARGV[1 .. $#ARGV];
[2a2f76c]15
[335786f]16if (!$q or !@ids) {
[2a2f76c]17    print $usage;
18    exit 1
19}
20
21my $configpath = "$ENV{'HOME'}/.gutenbach/$q";
[85a1ac1]22if (! -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]27my ($host, $queue);
28
29if (-r $configpath) {
30    local $/;
31    my $fh;
32    open $fh, $configpath;
33    eval <$fh>;
34}
35
[b58aada]36my $cups = Net::CUPS->new();
37$cups->setServer("$host");
38my $printer = $cups->getDestination("$queue");
[9fdf4a1]39unless( $printer){
40    print "Cannot access queue $q...do you have network connectivity and permission to view the queue?\n";
41    exit 1;
42}
[b58aada]43my @jobs = $printer->getJobs(0, 0);
[335786f]44foreach my $id(@ids){
[2a2f76c]45if ($id eq "all") {
[b58aada]46    foreach $id(@jobs) {
[d768767]47        cancel_job($id, $printer);
[b58aada]48    }
[2a2f76c]49}
[a81397c]50elsif ($id eq "current") {
[b58aada]51    $id = $jobs[0];
[d768767]52    cancel_job($id, $printer);
53}
54elsif ($id eq "last") {
55    $id = $jobs[-1];
56    cancel_job($id, $printer);
[a81397c]57}
[2a2f76c]58else {
[335786f]59    foreach my $item(@jobs) {
60        if($item =~ /$id/){
61            cancel_job($item, $printer);
62        }
63    }
64}
[d768767]65}
66
67sub cancel_job {
68    my ($id, $printer) = @_;
69    my $job_ref = $printer->getJob($id);
70    my $title = $job_ref->{'title'};
[b58aada]71    $printer->cancelJob($id);
[d768767]72
73    print "Canceled job '$title' (id $id)\n";
[335786f]74 
[2a2f76c]75}
Note: See TracBrowser for help on using the repository browser.