]> xenbits.xensource.com Git - people/iwj/osstest.git/commitdiff
mg-hosts: new subcommand previoustasks
authorIan Jackson <iwj@woking.cam.xci-test.com>
Fri, 26 Oct 2012 15:26:39 +0000 (16:26 +0100)
committerIan Jackson <iwj@woking.cam.xci-test.com>
Fri, 26 Oct 2012 15:26:39 +0000 (16:26 +0100)
mg-hosts

index deb1cde0c824b639fd5999289e64c849328143f0..fcdf056d9978e2499bc995d21ee74e77fd7709c4 100755 (executable)
--- a/mg-hosts
+++ b/mg-hosts
@@ -195,6 +195,61 @@ END
     });
 }
 
+sub cmd_previoustasks () {
+    my $doclear = (@ARGV==0 ? 0 :
+                  @ARGV==1 && $ARGV[0] eq '--clear' ? 1 :
+                  die "bad usage\n");
+
+    my $tasksq = $dbh_tests->prepare(<<END);
+        SELECT * FROM tasks
+               WHERE refkey LIKE 'previous %'
+                 AND live
+                 AND type = 'ownd'
+             ORDER BY comment, refkey
+END
+
+    my $resq = $dbh_tests->prepare(<<END);
+        SELECT * FROM resources
+               WHERE owntaskid = ?
+            ORDER BY restype, resname
+END
+
+    my $clearq = $dbh_tests->prepare(<<END);
+        UPDATE tasks
+          SET live = 'f'
+        WHERE refkey LIKE 'previous %'
+          AND live
+          AND type = 'ownd'
+          AND taskid = ?
+END
+
+    my $o = '';
+
+    db_retry($dbh_tests,[qw(resources)], sub {
+       $tasksq->execute();
+       while (my $trow = $tasksq->fetchrow_hashref()) {
+           $o .= sprintf("%10d %-20s | %s\n",
+                         $trow->{taskid},
+                         $trow->{username},
+                         "$trow->{comment}");
+           $resq->execute($trow->{taskid});
+           while (my $rrow = $resq->fetchrow_hashref()) {
+               $o .= sprintf("      %-25s | %s\n",
+                             "$rrow->{restype}/$rrow->{resname}".
+                             ($rrow->{shareix} ? "/$rrow->{shareix}" : ''),
+                             $rrow->{subtask});
+
+           }
+           $o .= "\n";
+           if ($doclear) {
+               $clearq->execute($trow->{taskid})
+                   or die "failed to clear task $trow->{taskid}";
+           }
+       }
+    });
+    print $o or die $!;
+}
+
 sub cmd_setflags () {
     update_hosts([qw(resources)], sub {
        my ($dst,$section) = @_;