Changeset 6b7441a for client/bin/gbr


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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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";
Note: See TracChangeset for help on using the changeset viewer.