Changeset 6b7441a for client/bin


Ignore:
Timestamp:
Oct 2, 2010, 8:53:02 PM (14 years ago)
Author:
Jessica B. Hamrick <jhamrick@…>
Branches:
master, debian, mac, no-cups
Children:
fc8707b
Parents:
814d4f8
git-author:
Jessica B. Hamrick <jhamrick@…> (10/02/10 20:53:02)
git-committer:
Jessica B. Hamrick <jhamrick@…> (10/02/10 20:53:02)
Message:

Add comments to the client scripts.

Location:
client/bin
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • client/bin/gbq

    r9dee329 r6b7441a  
    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;
     
    1516GetOptions ('q|queue=s' => \$q);
    1617
     18# if the -q option is not specified, then assume we're using the
     19# default queue
    1720if (!$q) {
    1821    $q = "DEFAULT";
    1922}
    2023
     24# set configuration path, and complain if it doesn't exist
    2125my $configpath = "$ENV{'HOME'}/.gutenbach/$q";
    2226if (! -e $configpath) {
     
    2529}
    2630
     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
    2734my ($host, $queue);
    2835
     36# load the configuration file (this will set $host and $queue)
    2937if (-r $configpath) {
    3038    local $/;
     
    3442}
    3543
     44# initialize a new CUPS session
    3645my $cups = Net::CUPS->new();
     46# set the server to the one specified in the config file
    3747$cups->setServer("$host");
     48# set the printer name to the one specified in the config file
    3849my $printer = $cups->getDestination("$queue");
    3950
     51# if $printer is not defined, then throw an error
    4052unless( $printer){
    4153    print "Cannot access queue $q...do you have network connectivity and permission to view the queue?\n";
    4254    exit 1;
    4355}
     56
     57# print pretty headings and stuff
    4458print "Queue listing for queue '$queue' on '$host'\n\n";
    4559printf ("%-8s%-15s%s\n","Job","Owner","Title");
    4660print "-"x70 . "\n";
     61
     62# get the list of jobs from the printer
    4763my @jobs = $printer->getJobs(0, 0);
     64
     65# initialize the job reference and job id variables
    4866my ($job_ref, $jobid);
    4967
     68# for each job in the list of jobs:
    5069foreach $jobid(@jobs)
    5170{       
    52         $job_ref = $printer->getJob($jobid);
    53         my $id = $job_ref->{'id'};
    54         my $user = $job_ref->{'user'};
    55         my $title = $job_ref->{'title'};
     71    # get the reference to the job (so we can get various related
     72    # variables)
     73    $job_ref = $printer->getJob($jobid);
    5674
    57         printf ("%-8s%-15s%s\n","$id",substr("$user",0,15),substr("$title",0,47));
     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));
    5884}
  • client/bin/gbr

    r600e713 r6b7441a  
    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;
     
    1819my @files = @ARGV[0 .. $#ARGV];
    1920
     21# if the -q option is not specified, then assume we're using the
     22# default queue
    2023if (!$q){
    2124    $q = "DEFAULT";
    2225}
     26
     27# if there are no files specified to print, then show the usage,
     28# because the user is Doing It Wrong
    2329if (!@files) {
    2430    print $usage;
     
    2632}
    2733
     34# set configuration path, and complain if it doesn't exist
    2835my $configpath = "$ENV{'HOME'}/.gutenbach/$q";
    2936if (! -e $configpath) {
     
    3239}
    3340
     41# initialize the host and queue variables: host holds the address for
     42# the machine on which the remote queue runs, and queue holds the name
     43# of the printer
    3444my ($host, $queue);
    3545
     46# load the configuration file (this will set $host and $queue)
    3647if (-r $configpath) {
    3748    local $/;
     
    4152}
    4253
     54# initialize a new CUPS session
    4355my $cups = Net::CUPS->new();
     56# set the server to the one specified in the config file
    4457$cups->setServer("$host");
     58# set the printer name to the one specified in the config file
    4559my $printer = $cups->getDestination("$queue");
     60
     61# if $printer is not defined, then throw an error
    4662unless( $printer){
    4763    print "Cannot access queue $q...do you have network connectivity and permission to view the queue?\n";
    4864    exit 1;
    4965}
     66
     67# initialize the job id and title variables for use below
    5068my ($jobid, $title);
    5169
     70# for each file that the user wants to print
    5271foreach my $file(@files) {
     72
     73    # check to see if the file is a youtube video.  If it is, then
     74    # write the URL to a temporary file, and set the number of copies
     75    # on the print job to 42 (this is the dirty hack we have in place
     76    # to indicate that the job is a youtube file instead of a normal
     77    # file)
    5378    if ($file =~ m|http://www\.youtube\.com/watch\?v=|) {
    5479        open FILE, ">", "/tmp/gutenbach-youtube" or die "Couldn't create temporary file";
     
    5883        $printer->addOption("copies", 42);
    5984    }
     85
     86    # otherwise, we assume it's a normal file.  Try to use exiftool's
     87    # ImageInfo to find out the tag information about the file (i.e.,
     88    # title, artist, and album).  If you can, then rename the job to
     89    # reflect those tags.  Otherwise, keep the normal title.
    6090    else {
    6191        my $fileinfo = ImageInfo($file);
     
    70100    }
    71101
     102    # send the print job, given the file and the job title
    72103    $jobid = $printer->printFile($file, $title);
    73104   
     105    # if the printFile command returned a job id, then print that out
     106    # for the user to see
    74107    if ($jobid) {
    75108        print "Sent job '$title' (id $jobid)\n";
    76109    }
     110
     111    # otherwise, let them know that an error occurred
    77112    else {
    78113        print "Error sending job '$title'\n";
  • client/bin/gbrm

    r7cdd65d r6b7441a  
    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;
     
    1617my @ids = @ARGV[0 .. $#ARGV];
    1718
     19# if the -q option is not specified, then assume we're using the
     20# default queue
    1821if (!$q){
    1922    $q = "DEFAULT";
    2023}
     24
     25# if there are no ids specified to remove, then print the usage
    2126if (!@ids) {
    2227    print $usage;
     
    2429}
    2530
    26 
     31# set configuration path, and complain if it doesn't exist
    2732my $configpath = "$ENV{'HOME'}/.gutenbach/$q";
    2833if (! -e $configpath) {
     
    3136}
    3237
     38# initialize the host and queue variables: host holds the address for
     39# the machine on which the remote queue runs, and queue holds the name
     40# of the printer
    3341my ($host, $queue);
    3442
     43# load the configuration file (this will set $host and $queue)
    3544if (-r $configpath) {
    3645    local $/;
     
    4049}
    4150
     51# initialize a new CUPS session
    4252my $cups = Net::CUPS->new();
     53# set the server to the one specified in the config file
    4354$cups->setServer("$host");
     55# set the printer name to the one specified in the config file
    4456my $printer = $cups->getDestination("$queue");
     57
     58# if $printer is not defined, then throw an error
    4559unless( $printer){
    4660    print "Cannot access queue $q...do you have network connectivity and permission to view the queue?\n";
    4761    exit 1;
    4862}
     63
     64# get the list of jobs from the printer
    4965my @jobs = $printer->getJobs(0, 0);
     66
     67# for each id that we want to remove
    5068foreach my $id(@ids){
    51 if ($id eq "all") {
    52     foreach $id(@jobs) {
     69
     70    # if the id is 'all', then we remove all jobs
     71    if ($id eq "all") {
     72        foreach $id(@jobs) {
     73            cancel_job($id, $printer);
     74        }
     75    }
     76
     77    # if the id is 'current', then we remove just the currently
     78    # playing job
     79    elsif ($id eq "current") {
     80        $id = $jobs[0];
    5381        cancel_job($id, $printer);
    5482    }
    55 }
    56 elsif ($id eq "current") {
    57     $id = $jobs[0];
    58     cancel_job($id, $printer);
    59 }
    60 elsif ($id eq "last") {
    61     $id = $jobs[-1];
    62     cancel_job($id, $printer);
    63 }
    64 else {
    65     foreach my $item(@jobs) {
    66         if($item =~ /$id/){
    67             cancel_job($item, $printer);
     83
     84    # if the id is 'last', then we remove just the last job
     85    elsif ($id eq "last") {
     86        $id = $jobs[-1];
     87        cancel_job($id, $printer);
     88    }
     89
     90    # otherwise, remove the job based on its actual (numeric) id
     91    else {
     92        foreach my $item(@jobs) {
     93            if($item =~ /$id/){
     94                cancel_job($item, $printer);
     95            }
    6896        }
    6997    }
    7098}
    71 }
    7299
     100# helper function to remove a job
    73101sub cancel_job {
     102    # get the id and printer from the arguments
    74103    my ($id, $printer) = @_;
     104    # get the reference to the job
    75105    my $job_ref = $printer->getJob($id);
     106    # find the job title (so we can print it out for the user)
    76107    my $title = $job_ref->{'title'};
     108    # cancel the job
    77109    $printer->cancelJob($id);
    78110
     111    # print out that we canceled the job
    79112    print "Canceled job '$title' (id $id)\n";
    80  
    81113}
  • client/bin/gutenbach-client-config

    r814d4f8 r6b7441a  
    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;
     
    78use Getopt::Long;
    89
     10# the usage for the program
    911my $usage = <<USAGE;
    1012Usage: gutenbach-client-config [-l|--list|-a|--add|-d|--delete] [QUEUE] [--host=HOST]
     
    1719USAGE
    1820
     21# initialize the variables that will hold the arguments
    1922my $list = 0;
    2023my $add = "";
     
    2326my $default = "";
    2427
     28# get the options from the command line
    2529GetOptions ('l|list' => \$list,
    2630            's|set-default=s' => \$default,
     
    2933            'h|host=s' => \$host);
    3034
     35# set the path where the configuration files live
    3136my $configpath = "$ENV{'HOME'}/.gutenbach";
    3237
     38# if the configuration path doens't exist, then make it
    3339if (! -e $configpath) {
    3440    mkdir "$configpath";
    3541}
    36 #set given queue to default
     42
     43# if the 'default' option was specified, then set given queue to
     44# default
    3745if($default and !$add and !$delete and !$list) {
     46    # if the specified queue doesn't exist, then throw an error
    3847    unless(-e "$configpath/$default") {
    3948        print "Error: queue '$default' doesn't exist yet...you should add it first.\n";
    4049        exit 1;
    4150    }
     51   
     52    # if there already exists a default, then remove it so we can
     53    # replace it with the new default
    4254    if( -e "$configpath/DEFAULT"){
    4355        unlink("$configpath/DEFAULT") or die "Couldn't remove config file '$configpath/DEFAULT'";
    4456    }
     57
     58    # check to make sure we can create symlinks
    4559    my $symlink_exists = eval { symlink("",""); 1 };
     60
     61    # if so, then create the symlink and report it
    4662    if ($symlink_exists){
    4763        symlink("$configpath/$default","$configpath/DEFAULT");
    4864        print "Changed default queue to $default.\n";
    4965    }
     66
     67    # otherwise, throw an error
    5068    else
    5169    {
     
    5472    }
    5573}
    56    
    57        
    5874
    59 # list the existing queues
     75# if the 'list' option was specified, then list the existing queues
    6076elsif ($list and !$add and !$delete and !$default) {
     77    # get the config files in the configuration path -- these are the queues
    6178    my @queues = glob("$configpath/*") or die "Couldn't find configuration files at '$configpath'";
    6279
     80    # for each of the queues, load the configuration file and print
     81    # the queue name and the host it's on
    6382    print "Queue\t\tHost\n";
    6483    foreach my $q (@queues) {
     
    7695}
    7796
    78 # add a new queue
     97# if the 'add' option was specified, then add a new queue
    7998elsif (!$list and $add and !$delete) {
     99
     100    # make sure there was a host specified as well (otherwise, we
     101    # won't know where to print to)
    80102    if (!$host) {
    81103        print $usage;
     
    83105    }
    84106
     107    # if the queue already exists, then print a warning
    85108    if (-e "$configpath/$add") {
    86109        print "Warning: queue '$add' already exists\n";
    87110    }
    88111
     112    # create the configuration file
    89113    open CONFIG, "> $configpath/$add" or die "Couldn't open config file '$configpath/$add'";
    90114    print CONFIG "\$host = \"$host\";\n";
     
    95119}
    96120
    97 # delete an existing queue
     121# if the 'delete' option was specified, then delete an existing queue
    98122elsif (!$list and !$add and $delete) {
     123
     124    # if the queue doesn't exist, then print an error and exit
    99125    if (! -e "$configpath/$delete") {
    100         print "Error: queue '$delete' already exists\n";
     126        print "Error: queue '$delete' does not exist\n";
    101127        exit 1;
    102128    }
    103129
     130    # otherwise, remove the configuration file
    104131    unlink("$configpath/$delete") or die "Couldn't remove config file '$configpath/$delete'";
    105132}
    106133
     134# otherwise, it's an unrecognized option, so print the usage and exit
    107135else {
    108136    print $usage;
Note: See TracChangeset for help on using the changeset viewer.