Skip to contentSkip to conversation

cs-adjust-flight: Add job-rename command which applies a perlop to job names

PATCH Superseded Ian Campbell 2 participants 2 messages Dec 10, 2015

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cs-adjust-flight: Add job-rename command which applies a perlop to job names

My intention was to allow creation of adhoc jobs based on a template but modified e.g. to enable/disable XSM with a sequence something like:

./cs-adjust-flight $flight copy-jobs $template test-foo-xsm ./cs-adjust-flight $flight rename-job test-foo-xsm 's/-xsm$//' ./cs-adjust-flight $flight runvar-set $job enable_xsm false ./cs-adjust-flight ... update %buildjob

---
 cs-adjust-flight | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
cs-adjust-flight +24 -0
index a72cd88..e0638d4 100755
@@ -18,6 +18,7 @@
 #   intended-blessing <intended-blessing>
 #   branch-set <new-branch>
 #   job-status <job-spec>
+#   job-rename <job-spec> <perl-expr>
 #
 # <foo-spec>:
 #   <foo-name>
@@ -371,6 +372,29 @@ END
     });
 }
 
+sub change__job_rename {
+    die unless @changes >= 2;
+    my $jobs = shift @changes;
+    my $perlop = shift @changes;
+
+    my $jobq = $dbh_tests->prepare(<<END);
+    UPDATE jobs
+       SET job = ?
+     WHERE flight = ? AND job = ?
+END
+    my $runvarq = $dbh_tests->prepare(<<END);
+    UPDATE runvars
+       SET job = ?
+     WHERE flight = ? AND job = ?
+END
+    for_jobs($dstflight, $jobs, sub {
+	my ($oldjob) = @_;
+	my $newjob = perlop_value ($oldjob, '', $perlop, $oldjob);
+	print "$oldjob renamed to $newjob\n";
+	$jobq->execute($newjob, $dstflight, $oldjob);
+	$runvarq->execute($newjob, $dstflight, $oldjob);
+    })
+}
 sub changes () {
     debug("CHANGES...\n");
 
Signature · 1 line
2.6.1
Acked-by on v1 1/1
#1 lore raw

Ian Campbell writes ("[PATCH OSSTEST] cs-adjust-flight: Add job-rename command which applies a perlop to job names"):

Quoted 10 lines

My intention was to allow creation of adhoc jobs based on a template but modified e.g. to enable/disable XSM with a sequence something like:

./cs-adjust-flight $flight copy-jobs $template test-foo-xsm ./cs-adjust-flight $flight rename-job test-foo-xsm 's/-xsm$//' ./cs-adjust-flight $flight runvar-set $job enable_xsm false ./cs-adjust-flight ... update %buildjob

Although maybe it should be called `jobs-rename' by analogy with the other modifiers ?

Arguably job-status should be renamed too. But arguably it ought not since when it is used to print the status of several jobs its output is different (and necessarily fiddlier).

Ian.