Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • client/bin/gbq

    r9dee329 rfc8707b  
    11#!/usr/bin/perl
    22
    3 # Written by Jessica Hamrick (C) 2010
     3# This script was largely written by Jessica Hamrick (jhamrick), with
     4# help from Kyle Brogle (broglek)
    45
    56use strict;
     
    1011use Getopt::Long;
    1112
    12 my $usage = "Usage: gbq [-q QUEUE]\n";
     13# usage
     14my $usage = <<USAGE;
     15Usage: gbq [options] [-q QUEUE]
    1316
     17        -q, --queue             Specify a queue other than the default
     18        -h, --help              Print this message
     19USAGE
     20
     21# initialize the variables for the options
    1422my $q = "";
    15 GetOptions ('q|queue=s' => \$q);
     23my $help = 0;
    1624
     25# parse the options
     26GetOptions ('q|queue=s' => \$q,
     27            'h|help' => \$help);
     28
     29# if the -h flag was passed, then print the usage and exit
     30if ($help) {
     31    print $usage;
     32    exit 0;
     33}
     34
     35# if the -q option is not specified, then assume we're using the
     36# default queue
    1737if (!$q) {
    1838    $q = "DEFAULT";
    1939}
    2040
     41# set configuration path, and complain if it doesn't exist
    2142my $configpath = "$ENV{'HOME'}/.gutenbach/$q";
    2243if (! -e $configpath) {
     
    2546}
    2647
     48# initialize the host and queue variables: host holds the address for
     49# the machine on which the remote queue runs, and queue holds the name
     50# of the printer
    2751my ($host, $queue);
    2852
     53# load the configuration file (this will set $host and $queue)
    2954if (-r $configpath) {
    3055    local $/;
     
    3459}
    3560
     61# initialize a new CUPS session
    3662my $cups = Net::CUPS->new();
     63# set the server to the one specified in the config file
    3764$cups->setServer("$host");
     65# set the printer name to the one specified in the config file
    3866my $printer = $cups->getDestination("$queue");
    3967
     68# if $printer is not defined, then throw an error
    4069unless( $printer){
    4170    print "Cannot access queue $q...do you have network connectivity and permission to view the queue?\n";
    4271    exit 1;
    4372}
     73
     74# print pretty headings and stuff
    4475print "Queue listing for queue '$queue' on '$host'\n\n";
    4576printf ("%-8s%-15s%s\n","Job","Owner","Title");
    4677print "-"x70 . "\n";
     78
     79# get the list of jobs from the printer
    4780my @jobs = $printer->getJobs(0, 0);
     81
     82# initialize the job reference and job id variables
    4883my ($job_ref, $jobid);
    4984
     85# for each job in the list of jobs:
    5086foreach $jobid(@jobs)
    5187{       
    52         $job_ref = $printer->getJob($jobid);
    53         my $id = $job_ref->{'id'};
    54         my $user = $job_ref->{'user'};
    55         my $title = $job_ref->{'title'};
     88    # get the reference to the job (so we can get various related
     89    # variables)
     90    $job_ref = $printer->getJob($jobid);
    5691
    57         printf ("%-8s%-15s%s\n","$id",substr("$user",0,15),substr("$title",0,47));
     92    # get the id of the job
     93    my $id = $job_ref->{'id'};
     94    # get the user who printed the job
     95    my $user = $job_ref->{'user'};
     96    # get the title of the job
     97    my $title = $job_ref->{'title'};
     98   
     99    # print the job information to the screen
     100    printf ("%-8s%-15s%s\n","$id",substr("$user",0,15),substr("$title",0,47));
    58101}
Note: See TracChangeset for help on using the changeset viewer.