From: Martin Mares Date: Tue, 21 Feb 2012 11:22:56 +0000 (+0100) Subject: bex queue: add --summary option and enable option bundling X-Git-Tag: v3.1~17 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=b9991eca58a4c82e3546d1e02f6456f46b055fe2;p=bex.git bex queue: add --summary option and enable option bundling --- diff --git a/lib/bin/bex-queue b/lib/bin/bex-queue index 58387ee..6f997d3 100755 --- a/lib/bin/bex-queue +++ b/lib/bin/bex-queue @@ -15,6 +15,7 @@ my $op_move_to; my $queue_name; my $given_job; +my $summary; sub usage() { print < Act on the specified job (default: on all) -q, --queue= 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"; + } } } }