source: client/bin/gbq @ 6b7441a

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

Add comments to the client scripts.

  • Property mode set to 100755
File size: 2.2 KB
Line 
1#!/usr/bin/perl
2
3# This script was largely written by Jessica Hamrick (jhamrick), with
4# help from Kyle Brogle (broglek)
5
6use strict;
7use warnings;
8
9use Net::CUPS;
10use Net::CUPS::Destination;
11use Getopt::Long;
12
13my $usage = "Usage: gbq [-q QUEUE]\n";
14
15my $q = "";
16GetOptions ('q|queue=s' => \$q);
17
18# if the -q option is not specified, then assume we're using the
19# default queue
20if (!$q) {
21    $q = "DEFAULT";
22}
23
24# set configuration path, and complain if it doesn't exist
25my $configpath = "$ENV{'HOME'}/.gutenbach/$q";
26if (! -e $configpath) {
27    print "Queue '$q' does not exist!  Did you forget to add it with 'gutenbach-client-config'?\n";
28    exit 1;
29}
30
31# initialize the host and queue variables: host holds the address for
32# the machine on which the remote queue runs, and queue holds the name
33# of the printer
34my ($host, $queue);
35
36# load the configuration file (this will set $host and $queue)
37if (-r $configpath) {
38    local $/;
39    my $fh;
40    open $fh, $configpath;
41    eval <$fh>;
42}
43
44# initialize a new CUPS session
45my $cups = Net::CUPS->new();
46# set the server to the one specified in the config file
47$cups->setServer("$host");
48# set the printer name to the one specified in the config file
49my $printer = $cups->getDestination("$queue");
50
51# if $printer is not defined, then throw an error
52unless( $printer){
53    print "Cannot access queue $q...do you have network connectivity and permission to view the queue?\n";
54    exit 1;
55}
56
57# print pretty headings and stuff
58print "Queue listing for queue '$queue' on '$host'\n\n";
59printf ("%-8s%-15s%s\n","Job","Owner","Title");
60print "-"x70 . "\n";
61
62# get the list of jobs from the printer
63my @jobs = $printer->getJobs(0, 0);
64
65# initialize the job reference and job id variables
66my ($job_ref, $jobid);
67
68# for each job in the list of jobs:
69foreach $jobid(@jobs) 
70{       
71    # get the reference to the job (so we can get various related
72    # variables)
73    $job_ref = $printer->getJob($jobid);
74
75    # get the id of the job
76    my $id = $job_ref->{'id'};
77    # get the user who printed the job
78    my $user = $job_ref->{'user'};
79    # get the title of the job
80    my $title = $job_ref->{'title'};
81   
82    # print the job information to the screen
83    printf ("%-8s%-15s%s\n","$id",substr("$user",0,15),substr("$title",0,47));
84}
Note: See TracBrowser for help on using the repository browser.