Changeset 6b7441a
- Timestamp:
- Oct 2, 2010, 8:53:02 PM (14 years ago)
- 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)
- Location:
- client/bin
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
client/bin/gbq
r9dee329 r6b7441a 1 1 #!/usr/bin/perl 2 2 3 # Written by Jessica Hamrick (C) 2010 3 # This script was largely written by Jessica Hamrick (jhamrick), with 4 # help from Kyle Brogle (broglek) 4 5 5 6 use strict; … … 15 16 GetOptions ('q|queue=s' => \$q); 16 17 18 # if the -q option is not specified, then assume we're using the 19 # default queue 17 20 if (!$q) { 18 21 $q = "DEFAULT"; 19 22 } 20 23 24 # set configuration path, and complain if it doesn't exist 21 25 my $configpath = "$ENV{'HOME'}/.gutenbach/$q"; 22 26 if (! -e $configpath) { … … 25 29 } 26 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 27 34 my ($host, $queue); 28 35 36 # load the configuration file (this will set $host and $queue) 29 37 if (-r $configpath) { 30 38 local $/; … … 34 42 } 35 43 44 # initialize a new CUPS session 36 45 my $cups = Net::CUPS->new(); 46 # set the server to the one specified in the config file 37 47 $cups->setServer("$host"); 48 # set the printer name to the one specified in the config file 38 49 my $printer = $cups->getDestination("$queue"); 39 50 51 # if $printer is not defined, then throw an error 40 52 unless( $printer){ 41 53 print "Cannot access queue $q...do you have network connectivity and permission to view the queue?\n"; 42 54 exit 1; 43 55 } 56 57 # print pretty headings and stuff 44 58 print "Queue listing for queue '$queue' on '$host'\n\n"; 45 59 printf ("%-8s%-15s%s\n","Job","Owner","Title"); 46 60 print "-"x70 . "\n"; 61 62 # get the list of jobs from the printer 47 63 my @jobs = $printer->getJobs(0, 0); 64 65 # initialize the job reference and job id variables 48 66 my ($job_ref, $jobid); 49 67 68 # for each job in the list of jobs: 50 69 foreach $jobid(@jobs) 51 70 { 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); 56 74 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)); 58 84 } -
client/bin/gbr
r600e713 r6b7441a 1 1 #!/usr/bin/perl 2 2 3 # Written by Jessica Hamrick (C) 2010 3 # This script was largely written by Jessica Hamrick (jhamrick), with 4 # help from Kyle Brogle (broglek) 4 5 5 6 use strict; … … 18 19 my @files = @ARGV[0 .. $#ARGV]; 19 20 21 # if the -q option is not specified, then assume we're using the 22 # default queue 20 23 if (!$q){ 21 24 $q = "DEFAULT"; 22 25 } 26 27 # if there are no files specified to print, then show the usage, 28 # because the user is Doing It Wrong 23 29 if (!@files) { 24 30 print $usage; … … 26 32 } 27 33 34 # set configuration path, and complain if it doesn't exist 28 35 my $configpath = "$ENV{'HOME'}/.gutenbach/$q"; 29 36 if (! -e $configpath) { … … 32 39 } 33 40 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 34 44 my ($host, $queue); 35 45 46 # load the configuration file (this will set $host and $queue) 36 47 if (-r $configpath) { 37 48 local $/; … … 41 52 } 42 53 54 # initialize a new CUPS session 43 55 my $cups = Net::CUPS->new(); 56 # set the server to the one specified in the config file 44 57 $cups->setServer("$host"); 58 # set the printer name to the one specified in the config file 45 59 my $printer = $cups->getDestination("$queue"); 60 61 # if $printer is not defined, then throw an error 46 62 unless( $printer){ 47 63 print "Cannot access queue $q...do you have network connectivity and permission to view the queue?\n"; 48 64 exit 1; 49 65 } 66 67 # initialize the job id and title variables for use below 50 68 my ($jobid, $title); 51 69 70 # for each file that the user wants to print 52 71 foreach 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) 53 78 if ($file =~ m|http://www\.youtube\.com/watch\?v=|) { 54 79 open FILE, ">", "/tmp/gutenbach-youtube" or die "Couldn't create temporary file"; … … 58 83 $printer->addOption("copies", 42); 59 84 } 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. 60 90 else { 61 91 my $fileinfo = ImageInfo($file); … … 70 100 } 71 101 102 # send the print job, given the file and the job title 72 103 $jobid = $printer->printFile($file, $title); 73 104 105 # if the printFile command returned a job id, then print that out 106 # for the user to see 74 107 if ($jobid) { 75 108 print "Sent job '$title' (id $jobid)\n"; 76 109 } 110 111 # otherwise, let them know that an error occurred 77 112 else { 78 113 print "Error sending job '$title'\n"; -
client/bin/gbrm
r7cdd65d r6b7441a 1 1 #!/usr/bin/perl 2 2 3 # Written by Jessica Hamrick (C) 2010 3 # This script was largely written by Jessica Hamrick (jhamrick), with 4 # help from Kyle Brogle (broglek) 4 5 5 6 use strict; … … 16 17 my @ids = @ARGV[0 .. $#ARGV]; 17 18 19 # if the -q option is not specified, then assume we're using the 20 # default queue 18 21 if (!$q){ 19 22 $q = "DEFAULT"; 20 23 } 24 25 # if there are no ids specified to remove, then print the usage 21 26 if (!@ids) { 22 27 print $usage; … … 24 29 } 25 30 26 31 # set configuration path, and complain if it doesn't exist 27 32 my $configpath = "$ENV{'HOME'}/.gutenbach/$q"; 28 33 if (! -e $configpath) { … … 31 36 } 32 37 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 33 41 my ($host, $queue); 34 42 43 # load the configuration file (this will set $host and $queue) 35 44 if (-r $configpath) { 36 45 local $/; … … 40 49 } 41 50 51 # initialize a new CUPS session 42 52 my $cups = Net::CUPS->new(); 53 # set the server to the one specified in the config file 43 54 $cups->setServer("$host"); 55 # set the printer name to the one specified in the config file 44 56 my $printer = $cups->getDestination("$queue"); 57 58 # if $printer is not defined, then throw an error 45 59 unless( $printer){ 46 60 print "Cannot access queue $q...do you have network connectivity and permission to view the queue?\n"; 47 61 exit 1; 48 62 } 63 64 # get the list of jobs from the printer 49 65 my @jobs = $printer->getJobs(0, 0); 66 67 # for each id that we want to remove 50 68 foreach 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]; 53 81 cancel_job($id, $printer); 54 82 } 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 } 68 96 } 69 97 } 70 98 } 71 }72 99 100 # helper function to remove a job 73 101 sub cancel_job { 102 # get the id and printer from the arguments 74 103 my ($id, $printer) = @_; 104 # get the reference to the job 75 105 my $job_ref = $printer->getJob($id); 106 # find the job title (so we can print it out for the user) 76 107 my $title = $job_ref->{'title'}; 108 # cancel the job 77 109 $printer->cancelJob($id); 78 110 111 # print out that we canceled the job 79 112 print "Canceled job '$title' (id $id)\n"; 80 81 113 } -
client/bin/gutenbach-client-config
r814d4f8 r6b7441a 1 1 #!/usr/bin/perl 2 2 3 # Written by Jessica Hamrick, (C) 2010 3 # This script was largely written by Jessica Hamrick (jhamrick), with 4 # help from Kyle Brogle (broglek) 4 5 5 6 use strict; … … 7 8 use Getopt::Long; 8 9 10 # the usage for the program 9 11 my $usage = <<USAGE; 10 12 Usage: gutenbach-client-config [-l|--list|-a|--add|-d|--delete] [QUEUE] [--host=HOST] … … 17 19 USAGE 18 20 21 # initialize the variables that will hold the arguments 19 22 my $list = 0; 20 23 my $add = ""; … … 23 26 my $default = ""; 24 27 28 # get the options from the command line 25 29 GetOptions ('l|list' => \$list, 26 30 's|set-default=s' => \$default, … … 29 33 'h|host=s' => \$host); 30 34 35 # set the path where the configuration files live 31 36 my $configpath = "$ENV{'HOME'}/.gutenbach"; 32 37 38 # if the configuration path doens't exist, then make it 33 39 if (! -e $configpath) { 34 40 mkdir "$configpath"; 35 41 } 36 #set given queue to default 42 43 # if the 'default' option was specified, then set given queue to 44 # default 37 45 if($default and !$add and !$delete and !$list) { 46 # if the specified queue doesn't exist, then throw an error 38 47 unless(-e "$configpath/$default") { 39 48 print "Error: queue '$default' doesn't exist yet...you should add it first.\n"; 40 49 exit 1; 41 50 } 51 52 # if there already exists a default, then remove it so we can 53 # replace it with the new default 42 54 if( -e "$configpath/DEFAULT"){ 43 55 unlink("$configpath/DEFAULT") or die "Couldn't remove config file '$configpath/DEFAULT'"; 44 56 } 57 58 # check to make sure we can create symlinks 45 59 my $symlink_exists = eval { symlink("",""); 1 }; 60 61 # if so, then create the symlink and report it 46 62 if ($symlink_exists){ 47 63 symlink("$configpath/$default","$configpath/DEFAULT"); 48 64 print "Changed default queue to $default.\n"; 49 65 } 66 67 # otherwise, throw an error 50 68 else 51 69 { … … 54 72 } 55 73 } 56 57 58 74 59 # list the existing queues75 # if the 'list' option was specified, then list the existing queues 60 76 elsif ($list and !$add and !$delete and !$default) { 77 # get the config files in the configuration path -- these are the queues 61 78 my @queues = glob("$configpath/*") or die "Couldn't find configuration files at '$configpath'"; 62 79 80 # for each of the queues, load the configuration file and print 81 # the queue name and the host it's on 63 82 print "Queue\t\tHost\n"; 64 83 foreach my $q (@queues) { … … 76 95 } 77 96 78 # add a new queue97 # if the 'add' option was specified, then add a new queue 79 98 elsif (!$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) 80 102 if (!$host) { 81 103 print $usage; … … 83 105 } 84 106 107 # if the queue already exists, then print a warning 85 108 if (-e "$configpath/$add") { 86 109 print "Warning: queue '$add' already exists\n"; 87 110 } 88 111 112 # create the configuration file 89 113 open CONFIG, "> $configpath/$add" or die "Couldn't open config file '$configpath/$add'"; 90 114 print CONFIG "\$host = \"$host\";\n"; … … 95 119 } 96 120 97 # delete an existing queue121 # if the 'delete' option was specified, then delete an existing queue 98 122 elsif (!$list and !$add and $delete) { 123 124 # if the queue doesn't exist, then print an error and exit 99 125 if (! -e "$configpath/$delete") { 100 print "Error: queue '$delete' already exists\n";126 print "Error: queue '$delete' does not exist\n"; 101 127 exit 1; 102 128 } 103 129 130 # otherwise, remove the configuration file 104 131 unlink("$configpath/$delete") or die "Couldn't remove config file '$configpath/$delete'"; 105 132 } 106 133 134 # otherwise, it's an unrecognized option, so print the usage and exit 107 135 else { 108 136 print $usage;
Note: See TracChangeset
for help on using the changeset viewer.