-
Notifications
You must be signed in to change notification settings - Fork 257
/
Copy pathabort_dep_tasks.py
executable file
·59 lines (47 loc) · 1.98 KB
/
abort_dep_tasks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env python
from __future__ import print_function
import ecflow
import re
# this script will work ONLY for standalone nmmb regression test ecflow workflow
class DefsTraverser:
def __init__(self, defs, ci):
assert (isinstance(defs, ecflow.Defs)),"Expected ecflow.Defs as first argument"
assert (isinstance(ci, ecflow.Client)),"Expected ecflow.Client as second argument"
self.__defs = defs
self.__ci = ci
self.__suite = None
def force_abort(self):
for suite in self.__defs.suites:
self.__suite = suite
self.__walk_node(suite)
def __walk_node(self, node_container):
for node in node_container.nodes:
if isinstance(node, ecflow.Task):
self.__check_task(node)
else:
self.__walk_node(node)
def __check_task(self, node):
trigger_expr = node.get_trigger()
if trigger_expr:
tasks = re.findall( r'(\S*) ==', trigger_expr.get_expression())
for t in tasks:
task = self.__defs.find_abs_node( self.__suite.get_abs_node_path() + "/" + t)
if task.get_state() == ecflow.State.aborted:
if node.get_state() != ecflow.State.aborted:
print("Will force aborted state for task", node.get_abs_node_path())
self.__ci.force_state(node.get_abs_node_path(), ecflow.State.aborted)
try:
# Create the client. This will read the default environment variables
ci = ecflow.Client()
# Get the node tree suite definition as stored in the server
# The definition is retrieved and stored on the variable 'ci'
ci.sync_local()
# access the definition retrieved from the server
server_defs = ci.get_defs()
if server_defs == None :
print("The server has no definition")
exit(1)
traverser = DefsTraverser(server_defs, ci)
traverser.force_abort()
except RuntimeError as e:
print("failed: " + str(e))