]> mj.ucw.cz Git - bex.git/commitdiff
bex queue: add --summary option and enable option bundling
authorMartin Mares <mj@ucw.cz>
Tue, 21 Feb 2012 11:22:56 +0000 (12:22 +0100)
committerMartin Mares <mj@ucw.cz>
Tue, 21 Feb 2012 11:22:56 +0000 (12:22 +0100)
lib/bin/bex-queue

index 58387eeb2588935b59452950adc21d4526e746a5..6f997d393958976f1ce521d9afc944cd1e848938 100755 (executable)
@@ -15,6 +15,7 @@ my $op_move_to;
 
 my $queue_name;
 my $given_job;
+my $summary;
 
 sub usage() {
        print <<AMEN ;
@@ -29,10 +30,12 @@ Actions:
 Options:
 -j, --job=<id>         Act on the specified job (default: on all)
 -q, --queue=<name>     Act on the given queue
+-s, --summary          Show only a summary
 AMEN
        exit 0;
 }
 
+Getopt::Long::Configure("bundling");
 GetOptions(
        "by-job!" => \$op_by_job,
        "h|by-host!" => \$op_by_host,
@@ -40,6 +43,7 @@ GetOptions(
        "move-to=s" => \$op_move_to,
        "j|job=s" => \$given_job,
        "q|queue=s" => \$queue_name,
+       "s|summary!" => \$summary,
        "help" => \&usage,
 ) or die "Try `bex queue --help' for more information.\n";
 
@@ -75,10 +79,15 @@ sub do_ls()
 {
        my %stat = ();
        my %mach_locked = ();
+       my %cnt_by_job = ();
+       my %cnt_by_mach = ();
        for my $m (keys %machs) {
                $mach_locked{$m} = $queue->is_locked($m, undef);
                for my $j (@{$machs{$m}}) {
                        my $st = $queue->read_job_status($m, $j);
+                       my $s = $st->{"Status"} // "UNKNOWN";
+                       $cnt_by_job{$j}{$s}++;
+                       $cnt_by_mach{$m}{$s}++;
                        if (defined($st->{'Time'}) && defined($st->{'Status'})) {
                                $stat{$m}{$j} = ' [' . $st->{'Status'} . ' on ' .
                                                POSIX::strftime('%Y-%m-%d', localtime $st->{'Time'}) . ']';
@@ -95,18 +104,30 @@ sub do_ls()
                print "### Queue lock present\n\n";
        }
 
-       if ($op_by_host) {
-               for my $m (sort keys %machs) {
-                       print "$m", ($mach_locked{$m} ? ' [LOCKED]' : ''), "\n";
-                       for my $j (@{$machs{$m}}) {
-                               print "\t" . $queue->job_name($j) . $stat{$m}{$j}, "\n";
+       if ($summary) {
+               if ($op_by_host) {
+                       for my $m (sort keys %cnt_by_mach) {
+                               print "$m: ", join(" ", map { "$_:" . $cnt_by_mach{$m}{$_} } sort keys %{$cnt_by_mach{$m}}), "\n";
+                       }
+               } else {
+                       for my $j (sort keys %cnt_by_job) {
+                               print $queue->job_name($j), ": ", join(" ", map { "$_:" . $cnt_by_job{$j}{$_} } sort keys %{$cnt_by_job{$j}}), "\n";
                        }
                }
        } else {
-               for my $j (sort keys %jobs) {
-                       print $queue->job_name($j), "\n";
-                       for my $m (sort @{$jobs{$j}}) {
-                               print "\t$m", $stat{$m}{$j}, "\n";
+               if ($op_by_host) {
+                       for my $m (sort keys %machs) {
+                               print "$m", ($mach_locked{$m} ? ' [LOCKED]' : ''), "\n";
+                               for my $j (@{$machs{$m}}) {
+                                       print "\t" . $queue->job_name($j) . $stat{$m}{$j}, "\n";
+                               }
+                       }
+               } else {
+                       for my $j (sort keys %jobs) {
+                               print $queue->job_name($j), "\n";
+                               for my $m (sort @{$jobs{$j}}) {
+                                       print "\t$m", $stat{$m}{$j}, "\n";
+                               }
                        }
                }
        }