1. Marcin Kasperski
  2. script_print

Commits

Marcin Kasperski  committed cf7bb0c

Kosmetyka

  • Participants
  • Parent commits 6d3142f
  • Branches default

Comments (0)

Files changed (1)

File print_in_parts.pl

View file
 has 'since' => (is => 'ro', isa=>'Int', required => 1,
                 default => sub { 1 },
                 documentation => 'Start from page ...');
+has 'verbose' => (is => 'ro', isa=>'Bool', required => 0, default => 0,
+                  documentation => "Be more verbose");
 
 sub run {
     my $self = shift;
 
     $self->wait_for_inactive_printer;
 
+    print "Printing pages $since-$to from $filename\n";
+
     my $command = "lp -o media=a4 -o sides=two-sided-long-edge -P '$since-$to' '$filename'";
-    print "Trying:\n$command\n";
+    print "Trying:\n$command\n" if $self->verbose;
     system($command);
 
 }
 sub wait_for_inactive_printer {
     my $self = shift;
 
+    print "Waiting for printer inactivity...";
+
     while($self->printer_active()) {
         sleep(1);
     }
+
+    print "READY\n";
 }
 
 sub printer_active {
     my $self = shift;
 
-    print "Checking lpstat...\n";
+    print "Checking lpstat...\n" if $self->verbose;
     my $active = 0;
     open(my $fd, "lpstat |");
     while(<$fd>) {
         unless(/^$/) {
             $active = 1;
-            print "    $_";
+            print "    $_" if $self->verbose;
         }
     }
     close($fd);