Commits

Anonymous committed 6d3142f

Chyba działa

Comments (0)

Files changed (1)

print_in_parts.pl

 use namespace::autoclean;
 use PDF::API2;
 use List::Util qw(min);
+use autodie qw(:all);
 with 'MooseX::Getopt';
 
 has 'file' => (is => 'ro', isa=>'Str', required => 1,
 sub print_part {
     my ($self, $filename, $since, $to) = @_;
 
+    $self->wait_for_inactive_printer;
+
     my $command = "lp -o media=a4 -o sides=two-sided-long-edge -P '$since-$to' '$filename'";
-    print "Try:\n$command\n";
+    print "Trying:\n$command\n";
+    system($command);
+
+}
+
+sub wait_for_inactive_printer {
+    my $self = shift;
+
+    while($self->printer_active()) {
+        sleep(1);
+    }
+}
+
+sub printer_active {
+    my $self = shift;
+
+    print "Checking lpstat...\n";
+    my $active = 0;
+    open(my $fd, "lpstat |");
+    while(<$fd>) {
+        unless(/^$/) {
+            $active = 1;
+            print "    $_";
+        }
+    }
+    close($fd);
+
+    return $active;
 }
 
 ###########################################################################