Changes in client/bin/gbq [fc8707b:9dee329]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
client/bin/gbq
rfc8707b r9dee329 1 1 #!/usr/bin/perl 2 2 3 # This script was largely written by Jessica Hamrick (jhamrick), with 4 # help from Kyle Brogle (broglek) 3 # Written by Jessica Hamrick (C) 2010 5 4 6 5 use strict; … … 11 10 use Getopt::Long; 12 11 13 # usage 14 my $usage = <<USAGE; 15 Usage: gbq [options] [-q QUEUE] 12 my $usage = "Usage: gbq [-q QUEUE]\n"; 16 13 17 -q, --queue Specify a queue other than the default 18 -h, --help Print this message 19 USAGE 14 my $q = ""; 15 GetOptions ('q|queue=s' => \$q); 20 16 21 # initialize the variables for the options22 my $q = "";23 my $help = 0;24 25 # parse the options26 GetOptions ('q|queue=s' => \$q,27 'h|help' => \$help);28 29 # if the -h flag was passed, then print the usage and exit30 if ($help) {31 print $usage;32 exit 0;33 }34 35 # if the -q option is not specified, then assume we're using the36 # default queue37 17 if (!$q) { 38 18 $q = "DEFAULT"; 39 19 } 40 20 41 # set configuration path, and complain if it doesn't exist42 21 my $configpath = "$ENV{'HOME'}/.gutenbach/$q"; 43 22 if (! -e $configpath) { … … 46 25 } 47 26 48 # initialize the host and queue variables: host holds the address for49 # the machine on which the remote queue runs, and queue holds the name50 # of the printer51 27 my ($host, $queue); 52 28 53 # load the configuration file (this will set $host and $queue)54 29 if (-r $configpath) { 55 30 local $/; … … 59 34 } 60 35 61 # initialize a new CUPS session62 36 my $cups = Net::CUPS->new(); 63 # set the server to the one specified in the config file64 37 $cups->setServer("$host"); 65 # set the printer name to the one specified in the config file66 38 my $printer = $cups->getDestination("$queue"); 67 39 68 # if $printer is not defined, then throw an error69 40 unless( $printer){ 70 41 print "Cannot access queue $q...do you have network connectivity and permission to view the queue?\n"; 71 42 exit 1; 72 43 } 73 74 # print pretty headings and stuff75 44 print "Queue listing for queue '$queue' on '$host'\n\n"; 76 45 printf ("%-8s%-15s%s\n","Job","Owner","Title"); 77 46 print "-"x70 . "\n"; 78 79 # get the list of jobs from the printer80 47 my @jobs = $printer->getJobs(0, 0); 81 82 # initialize the job reference and job id variables83 48 my ($job_ref, $jobid); 84 49 85 # for each job in the list of jobs:86 50 foreach $jobid(@jobs) 87 51 { 88 # get the reference to the job (so we can get various related 89 # variables) 90 $job_ref = $printer->getJob($jobid); 52 $job_ref = $printer->getJob($jobid); 53 my $id = $job_ref->{'id'}; 54 my $user = $job_ref->{'user'}; 55 my $title = $job_ref->{'title'}; 91 56 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)); 57 printf ("%-8s%-15s%s\n","$id",substr("$user",0,15),substr("$title",0,47)); 101 58 }
Note: See TracChangeset
for help on using the changeset viewer.