Skip to content

Commit

Permalink
Merge pull request #40596 from rovere/FixRunTheMatrix
Browse files Browse the repository at this point in the history
Fix runTheMatrix interactive and add tests.
  • Loading branch information
cmsbuild authored Feb 10, 2023
2 parents f2c29ef + c221e1c commit cd4e36d
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 14 deletions.
38 changes: 24 additions & 14 deletions Configuration/PyReleaseValidation/scripts/runTheMatrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,8 @@ def stepOrIndex(s):
opt.overWrite=eval(opt.overWrite)
if opt.interactive:
import cmd
from colorama import Fore, Style
from os import isatty

class TheMatrix(cmd.Cmd):
intro = "Welcome to the Matrix (? for help)"
Expand Down Expand Up @@ -486,6 +488,12 @@ def do_exit(self, arg):
def default(self, inp):
if inp == 'x' or inp == 'q':
return self.do_exit(inp)
else:
is_pipe = not isatty(sys.stdin.fileno())
print(Fore.RED + "Error: " + Fore.RESET + "unrecognized command.")
# Quit only if given a piped command.
if is_pipe:
sys.exit(1)

def help_predefined(self):
print("\n".join(["predefined [predef1 [...]]\n",
Expand All @@ -509,7 +517,7 @@ def do_predefined(self, arg):
else:
print("Unknown Set: %s" % w)
else:
print(predefinedSet.keys())
print("[ " + Fore.RED + ", ".join([str(k) for k in predefinedSet.keys()]) + Fore.RESET + " ]")

def help_showWorkflow(self):
print("\n".join(["showWorkflow [workflow1 [...]]\n",
Expand All @@ -526,17 +534,18 @@ def do_showWorkflow(self, arg):
if arg == '':
print("Available workflows:")
for k in self.matrices_.keys():
print(k)
print(Fore.RED + Style.BRIGHT + k)
print(Style.RESET_ALL)
else:
selected = arg.split()
for k in selected:
if k not in self.matrices_.keys():
print("Unknown workflow %s: skipping" % k)
else:
for wfl in self.matrices_[k].workFlows:
wfName, stepNames = wfl.nameId.split('+',1)
print("%s %s %s" % (wfl.numId, wfName, stepNames))
print("%s contains %d workflows" % (k, len(self.matrices_[k].workFlows)))
print("%s %s" % (Fore.BLUE + str(wfl.numId) + Fore.RESET,
Fore.GREEN + wfl.nameId + Fore.RESET))
print("%s contains %d workflows" % (Fore.RED + k + Fore.RESET, len(self.matrices_[k].workFlows)))

def help_searchInWorkflow(self):
print("\n".join(["searchInWorkflow wfl_name search_regexp\n",
Expand Down Expand Up @@ -566,11 +575,12 @@ def do_searchInWorkflow(self, arg):
return
counter = 0
for wfl in self.matrices_[args[0]].workFlows:
wfName, stepNames = wfl.nameId.split('+',1)
if re.match(pattern, wfName) or re.match(pattern, stepNames):
print("%s %s %s" % (wfl.numId, wfName, stepNames))
counter += 1
print("Found %d compatible workflows inside %s" % (counter, args[0]))
if re.match(pattern, wfl.nameId):
print("%s %s" % (Fore.BLUE + str(wfl.numId) + Fore.RESET,
Fore.GREEN + wfl.nameId + Fore.RESET))
counter +=1
print("Found %s compatible workflows inside %s" % (Fore.RED + str(counter) + Fore.RESET,
Fore.YELLOW + str(args[0])) + Fore.RESET)

def help_search(self):
print("\n".join(["search search_regexp\n",
Expand All @@ -595,19 +605,19 @@ def do_dumpWorkflowId(self, arg):
print("dumpWorkflowId [wfl-id1 [...]]")
return

fmt = "[%d]: %s\n"
fmt = "[%s]: %s\n"
maxLen = 100
for wflid in wflids:
dump = True
for key, mrd in self.matrices_.items():
for wfl in mrd.workFlows:
if wfl.numId == float(wflid):
wfName, stepNames = wfl.nameId.split('+',1)
if dump:
dump = False
print(wfl.numId, stepNames)
print(Fore.GREEN + str(wfl.numId) + Fore.RESET + " " + Fore.YELLOW + wfl.nameId + Fore.RESET)
for i,s in enumerate(wfl.cmds):
print(fmt % (i+1, (str(s)+' ')))
print(fmt % (Fore.RED + str(i+1) + Fore.RESET,
(str(s)+' ')))
print("\nWorkflow found in %s." % key)
else:
print("Workflow also found in %s." % key)
Expand Down
3 changes: 3 additions & 0 deletions Configuration/PyReleaseValidation/test/BuildFile.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
<test name="test-das-selected-lumis" command="test-das-selected-lumis.sh">
<flags USE_UNITTEST_DIR="1"/>
</test>
<test name="test-runTheMatrix-interactive" command="test-runTheMatrix_interactive.sh">
<flags USE_UNITTEST_DIR="1"/>
</test>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash -e

echo 'help' | runTheMatrix.py --interactive || exit 1
echo 'predefined' | runTheMatrix.py --interactive || exit 1
echo 'showWorkflow' | runTheMatrix.py --interactive || exit 1
echo 'search .*D88.*' | runTheMatrix.py --interactive || exit 1
echo 'dumpWorkflowId 1.0' | runTheMatrix.py --interactive || exit 1
echo 'searchInWorkflow standard .*' | runTheMatrix.py --interactive || exit 1
echo 'wrongCommand' | runTheMatrix.py --interactive || exit 0

0 comments on commit cd4e36d

Please sign in to comment.