Changeset 6157f97 for queue/lib


Ignore:
Timestamp:
Jun 29, 2010, 1:19:49 AM (14 years ago)
Author:
Jessica B. Hamrick <jhamrick@…>
Branches:
master, debian, mac, no-cups, web
Children:
618236b, cd17920
Parents:
323f614
git-author:
Jessica B. Hamrick <jhamrick@…> (06/29/10 01:19:49)
git-committer:
Jessica B. Hamrick <jhamrick@…> (06/29/10 01:19:49)
Message:

Modify queue to be a perl script using Net::CUPS

Location:
queue/lib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • queue/lib/build-gutenbach-queue

    r30beeab r6157f97  
    88    time=$(date)
    99    echo "This is a work in progress!  Please send bugs to jhamrick." >> /var/run/gutenbach/current_queue_temp
    10     echo ""
     10    echo "" >> /var/run/gutenbach/current_queue_temp
    1111    echo "As of $time:" >> /var/run/gutenbach/current_queue_temp
     12    echo "" >> /var/run/gutenbach/current_queue_temp
    1213    /usr/lib/gutenbach/queue/queue >> /var/run/gutenbach/current_queue_temp
    1314    mv /var/run/gutenbach/current_queue_temp /var/run/gutenbach/current_queue
  • queue/lib/queue

    r30beeab r6157f97  
    1 #!/bin/bash
     1#!/usr/bin/perl                                                                                                       
    22
    3 found_current=
     3use Net::CUPS;
     4use Net::CUPS::Destination;
     5use Image::ExifTool qw(ImageInfo);
    46
    5 if [ -e "/var/run/gutenbach/queue_times" ]; then
    6     rm "/var/run/gutenbach/queue_times"
    7 fi
     7use strict;
     8use warnings;
    89
    9 if [ -e /usr/lib/gutenbach/config/printername ]; then
    10     printername=$(cat /usr/lib/gutenbach/config/printername)
     10use vars qw/$queue/;
     11require "/usr/lib/gutenbach/config/gutenbach-filter-config.pl" or die "Unable to load configuration";
    1112
    12     cd /var/spool/lpd/"$printername"/
    13     for i in $(ls . | grep ^hf); do
    14         done=$(cat "$i" | grep done)
    15     if [ ! -n "$done" ]; then
    16         timestamp=$(cat "$i" | grep ^job_time= | sed 's/.*=//')
    17         echo "$timestamp:$i" >> /var/run/gutenbach/queue_times
    18     fi
    19     done
     13my $cups = Net::CUPS->new();
     14my $printer = $cups->getDestination("$queue");
     15my @jobs = $printer->getJobs( 0, 0 );
     16my $job_ref;
     17my $jobid;
     18my $attr;
    2019
    21     if [ -e /var/run/gutenbach/queue_times ]; then
    22         for i in $(sort /var/run/gutenbach/queue_times); do
    23             i=$(echo "$i" | sed 's/.*://')
    24             prefix="df"${i:2}
    25             for j in "$prefix"*; do song="$j"; done
    26 
    27             user=$(cat "$i" | grep ^P=)
    28             user=${user:2}
    29            
    30             if [ -e /var/run/gutenbach/exiftool_data ]; then
    31                 rm /var/run/gutenbach/exiftool_data
    32             fi
    33 
    34             exiftool "$song" >> /var/run/gutenbach/exiftool_data
    35             title=$(cat /var/run/gutenbach/exiftool_data | grep "^Title " | sed 's/.*: //')
    36             artist=$(cat /var/run/gutenbach/exiftool_data | grep "^Artist " | sed 's/.*: //')
    37 
    38             if [ -z "$found_current" ]; then
    39                 host=$(cat "$i" | grep ^H=)
    40                 host=${host:2}
    41                 filenm="$(cat $i | grep "^filenames" | sed -e 's/filenames=//')"
    42                 album=$(cat /var/run/gutenbach/exiftool_data | grep "^Album " | sed 's/.*: //')
    43                 echo "$user@$host is currently playing: "
    44                 echo "$filenm"
    45                 echo "'$title'"
    46                 echo "by '$artist'"
    47                 echo "on '$album'"
    48                 echo ""
    49                 echo "Coming up in the queue:"
    50                 found_current="true"
    51             else
    52                 echo "$user: '$title' by '$artist'"
    53             fi
    54         done
    55     fi
    56 else
    57     echo "Error: Printer name configuration file /usr/lib/gutenbach/config/printername does not exist!"
    58     exit 1
    59 fi
     20my $jobnum = 0;
     21foreach $jobid(@jobs)
     22{
     23    $job_ref = $printer->getJob($jobid);
     24    my $filepath = "/var/spool/cups/d0$job_ref->{'id'}-001";
     25    my $fileinfo = ImageInfo($filepath);
     26    my $magic = $fileinfo->{FileType};
     27   
     28    if ($jobnum == 0)
     29    {
     30        print $job_ref->{'user'}." is currently playing:\n";
     31        print "\t".$magic." file ".$job_ref->{'title'}."\n";
     32       
     33        if ($magic)
     34        {
     35            foreach my $key (qw/Title Artist Album AlbumArtist/)
     36            {
     37                if (exists $fileinfo->{$key})
     38                {
     39                    print "\t$fileinfo->{$key}\n";
     40                }
     41            }
     42        }
     43       
     44        print "\nComing up the queue:\n\n";
     45    }
     46    else
     47    {
     48        if ($magic)
     49        {
     50            my $user = $job_ref->{'user'};
     51            my $title = $fileinfo->{'Title'};
     52            my $artist = $fileinfo->{'Artist'};
     53            my $album = $fileinfo->{'Album'};
     54            print "$user: \"$title\" by \"$artist\" on \"$album\"\n";
     55        }
     56    }
     57   
     58    $jobnum += 1;
     59}
Note: See TracChangeset for help on using the changeset viewer.