happyscript 0.0.7__tar.gz → 0.0.9__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {happyscript-0.0.7 → happyscript-0.0.9}/PKG-INFO +1 -1
- {happyscript-0.0.7 → happyscript-0.0.9}/happyscript/__init__.py +1 -1
- {happyscript-0.0.7 → happyscript-0.0.9}/happyscript/charts/matplotlib_chart.py +15 -4
- {happyscript-0.0.7 → happyscript-0.0.9}/happyscript/charts/panel_charts.py +2 -0
- {happyscript-0.0.7 → happyscript-0.0.9}/happyscript/scriptcontrol.py +8 -11
- {happyscript-0.0.7 → happyscript-0.0.9}/happyscript/scriptgui.py +15 -0
- {happyscript-0.0.7 → happyscript-0.0.9}/happyscript/scriptinfo.py +24 -10
- {happyscript-0.0.7 → happyscript-0.0.9}/happyscript/scriptmanager.py +3 -3
- {happyscript-0.0.7 → happyscript-0.0.9}/happyscript/scriptparams.py +1 -0
- {happyscript-0.0.7 → happyscript-0.0.9}/happyscript/scriptrunner.py +64 -17
- {happyscript-0.0.7 → happyscript-0.0.9}/happyscript.egg-info/PKG-INFO +1 -1
- {happyscript-0.0.7 → happyscript-0.0.9}/happyscript.egg-info/SOURCES.txt +1 -0
- happyscript-0.0.9/publish.bat +6 -0
- {happyscript-0.0.7 → happyscript-0.0.9}/pyproject.toml +1 -1
- {happyscript-0.0.7 → happyscript-0.0.9}/README.md +0 -0
- {happyscript-0.0.7 → happyscript-0.0.9}/copy_code.py +0 -0
- {happyscript-0.0.7 → happyscript-0.0.9}/happyscript/charts/__init__.py +0 -0
- {happyscript-0.0.7 → happyscript-0.0.9}/happyscript/charts/chart.py +0 -0
- {happyscript-0.0.7 → happyscript-0.0.9}/happyscript/charts/histogram_chart.py +0 -0
- {happyscript-0.0.7 → happyscript-0.0.9}/happyscript/charts/histogram_series.py +0 -0
- {happyscript-0.0.7 → happyscript-0.0.9}/happyscript/charts/scatter_chart.py +0 -0
- {happyscript-0.0.7 → happyscript-0.0.9}/happyscript/charts/scatter_series.py +0 -0
- {happyscript-0.0.7 → happyscript-0.0.9}/happyscript/charts/time_chart.py +0 -0
- {happyscript-0.0.7 → happyscript-0.0.9}/happyscript/charts/time_series.py +0 -0
- {happyscript-0.0.7 → happyscript-0.0.9}/happyscript/forms/form_askchoice.py +0 -0
- {happyscript-0.0.7 → happyscript-0.0.9}/happyscript/forms/form_askimage.py +0 -0
- {happyscript-0.0.7 → happyscript-0.0.9}/happyscript/forms/form_main.py +0 -0
- {happyscript-0.0.7 → happyscript-0.0.9}/happyscript/forms/form_ontestfailure.py +0 -0
- {happyscript-0.0.7 → happyscript-0.0.9}/happyscript/forms/form_serials.py +0 -0
- {happyscript-0.0.7 → happyscript-0.0.9}/happyscript/forms/form_stop.py +0 -0
- {happyscript-0.0.7 → happyscript-0.0.9}/happyscript/forms/formsbase.py +0 -0
- {happyscript-0.0.7 → happyscript-0.0.9}/happyscript/imglib.py +0 -0
- {happyscript-0.0.7 → happyscript-0.0.9}/happyscript/panels/panel_log.py +0 -0
- {happyscript-0.0.7 → happyscript-0.0.9}/happyscript/panels/panel_messages.py +0 -0
- {happyscript-0.0.7 → happyscript-0.0.9}/happyscript/panels/panel_scripts2.py +0 -0
- {happyscript-0.0.7 → happyscript-0.0.9}/happyscript/panels/panel_tests.py +0 -0
- {happyscript-0.0.7 → happyscript-0.0.9}/happyscript/panels/panelsbase.py +0 -0
- {happyscript-0.0.7 → happyscript-0.0.9}/happyscript/scriptartwork.py +0 -0
- {happyscript-0.0.7 → happyscript-0.0.9}/happyscript/scriptexceptions.py +0 -0
- {happyscript-0.0.7 → happyscript-0.0.9}/happyscript/scriptreader.py +0 -0
- {happyscript-0.0.7 → happyscript-0.0.9}/happyscript/testlog/global_log_handler.py +0 -0
- {happyscript-0.0.7 → happyscript-0.0.9}/happyscript/testlog/log_to_text.py +0 -0
- {happyscript-0.0.7 → happyscript-0.0.9}/happyscript/testlog/logtoxml.py +0 -0
- {happyscript-0.0.7 → happyscript-0.0.9}/happyscript/testlog/printredirect.py +0 -0
- {happyscript-0.0.7 → happyscript-0.0.9}/happyscript.egg-info/dependency_links.txt +0 -0
- {happyscript-0.0.7 → happyscript-0.0.9}/happyscript.egg-info/top_level.txt +0 -0
- {happyscript-0.0.7 → happyscript-0.0.9}/increment_version.py +0 -0
- {happyscript-0.0.7 → happyscript-0.0.9}/setup.cfg +0 -0
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
__version__ = "0.0.
|
|
1
|
+
__version__ = "0.0.9"
|
|
2
2
|
from .scriptmanager import ScriptManager
|
|
@@ -1,15 +1,23 @@
|
|
|
1
1
|
import logging
|
|
2
2
|
import wx
|
|
3
|
-
|
|
4
|
-
from matplotlib.backends.backend_wxagg import
|
|
5
|
-
from matplotlib.
|
|
6
|
-
|
|
3
|
+
try:
|
|
4
|
+
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
|
|
5
|
+
from matplotlib.backends.backend_wxagg import NavigationToolbar2WxAgg as NavigationToolbar
|
|
6
|
+
from matplotlib.figure import Figure
|
|
7
|
+
import matplotlib.pyplot as plt
|
|
8
|
+
HAVE_MATPLOTLIB = True
|
|
9
|
+
except ImportError:
|
|
10
|
+
HAVE_MATPLOTLIB = False
|
|
7
11
|
class MatPlotLibChart(wx.Panel):
|
|
8
12
|
def __init__(self, parent_control, name):
|
|
9
13
|
super().__init__(parent_control, -1)
|
|
10
14
|
self.__name = name
|
|
11
15
|
self.__dirty = False
|
|
12
16
|
self.__on_update_func = None
|
|
17
|
+
if not HAVE_MATPLOTLIB:
|
|
18
|
+
logging.error("Matplotlib is not installed.")
|
|
19
|
+
self.__figure = None
|
|
20
|
+
return
|
|
13
21
|
self.__figure = Figure(dpi=None, figsize=(2, 2))
|
|
14
22
|
self.__figure.set_tight_layout(True)
|
|
15
23
|
self.canvas = FigureCanvas(self, -1, self.__figure)
|
|
@@ -27,6 +35,7 @@ class MatPlotLibChart(wx.Panel):
|
|
|
27
35
|
return self.__figure
|
|
28
36
|
def configure(self, /, x_label=None, y_label=None, title=None,
|
|
29
37
|
y_log=None, x_log=None, x_range=None, y_range=None):
|
|
38
|
+
if not HAVE_MATPLOTLIB: return
|
|
30
39
|
if title is not None and isinstance(title, str):
|
|
31
40
|
if len(self.figure.axes)>0:
|
|
32
41
|
self.figure.axes[0].set_title(title)
|
|
@@ -52,8 +61,10 @@ class MatPlotLibChart(wx.Panel):
|
|
|
52
61
|
self.do_redraw()
|
|
53
62
|
self.__dirty = False
|
|
54
63
|
def do_redraw(self):
|
|
64
|
+
if not HAVE_MATPLOTLIB: return
|
|
55
65
|
self.canvas.draw()
|
|
56
66
|
def clear(self):
|
|
67
|
+
if not HAVE_MATPLOTLIB: return
|
|
57
68
|
try:
|
|
58
69
|
self.figure.clf()
|
|
59
70
|
except:
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import wx
|
|
2
2
|
import os
|
|
3
|
+
import logging
|
|
3
4
|
from ..panels.panelsbase import PanelCharts_Base
|
|
4
5
|
from ..charts.scatter_chart import ScatterChart
|
|
5
6
|
from ..charts.time_chart import TimeChart
|
|
@@ -102,6 +103,7 @@ class PanelCharts( PanelCharts_Base):
|
|
|
102
103
|
def add_matplotlib(self, name ):
|
|
103
104
|
self.delete_chart(name)
|
|
104
105
|
chart = MatPlotLibChart(self.m_nbkPlots, name)
|
|
106
|
+
assert chart.figure is not None, "Could not add matplotlib chart."
|
|
105
107
|
chart.on_update = self.update
|
|
106
108
|
self.charts[name] = chart
|
|
107
109
|
self.m_nbkPlots.AddPage( chart, name, True)
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import wx
|
|
2
1
|
import time
|
|
3
2
|
from .scriptexceptions import ScriptUserAbortException
|
|
4
3
|
class ScriptControl:
|
|
5
4
|
def __init__(self):
|
|
6
5
|
self.m_stop_script = False
|
|
7
6
|
self._is_busy = False
|
|
8
|
-
self.
|
|
7
|
+
self._script_runner = None
|
|
8
|
+
def set_script_runner(self, runner):
|
|
9
|
+
self._script_runner = runner
|
|
9
10
|
def set_busy(self, is_busy):
|
|
10
11
|
self._is_busy = is_busy
|
|
11
12
|
self.m_stop_script = False
|
|
@@ -18,26 +19,22 @@ class ScriptControl:
|
|
|
18
19
|
print("Normally no script is active, but I'll set the 'stop' flag anyway.")
|
|
19
20
|
self.m_stop_script = True
|
|
20
21
|
def ok(self):
|
|
21
|
-
wx.Yield()
|
|
22
22
|
return not self.m_stop_script
|
|
23
23
|
def check(self):
|
|
24
|
-
wx.Yield()
|
|
25
24
|
if self.m_stop_script:
|
|
26
25
|
raise ScriptUserAbortException( "Script stopping on user request" )
|
|
27
26
|
def sleep(self, time_in_seconds):
|
|
28
27
|
t = time_in_seconds
|
|
29
|
-
wx.Yield()
|
|
30
28
|
while t>0:
|
|
31
29
|
if t > 0.5:
|
|
32
30
|
time.sleep(0.5)
|
|
33
31
|
else:
|
|
34
32
|
time.sleep(t)
|
|
35
|
-
t = t-0.5
|
|
36
|
-
wx.Yield()
|
|
33
|
+
t = t-0.5
|
|
37
34
|
if self.m_stop_script:
|
|
38
35
|
raise ScriptUserAbortException( "Script stopping on user request" )
|
|
39
36
|
def run(self, script_name, **argv):
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
37
|
+
assert self._script_runner is not None, "Internal error: scriptrunner is not set"
|
|
38
|
+
return self._script_runner.run_script(script_name, **argv)
|
|
39
|
+
def run_parallel(self, func, parname, parvalues, **extra_params):
|
|
40
|
+
return self._script_runner.run_parallel(func, parname, parvalues, **extra_params)
|
|
@@ -29,6 +29,7 @@ class ScriptGui:
|
|
|
29
29
|
raise self.__reply
|
|
30
30
|
return self.__reply
|
|
31
31
|
def do_func(self, func, *params):
|
|
32
|
+
assert not threading.currentThread().getName().startswith("Parallel"), "GUI functions cannot be called from a parallel thread"
|
|
32
33
|
if func is None or not callable(func):
|
|
33
34
|
raise Exception("Given function to execute is not something callable.")
|
|
34
35
|
if threading.currentThread().getName()=="ScriptThread":
|
|
@@ -36,6 +37,7 @@ class ScriptGui:
|
|
|
36
37
|
else:
|
|
37
38
|
return func(*params)
|
|
38
39
|
def ask(self, message, default_value="" ):
|
|
40
|
+
assert not threading.currentThread().getName().startswith("Parallel"), "GUI functions cannot be called from a parallel thread"
|
|
39
41
|
if threading.currentThread().getName()=="ScriptThread":
|
|
40
42
|
return self.__run_with_timer(self.ask, message, default_value )
|
|
41
43
|
result = None
|
|
@@ -47,6 +49,7 @@ class ScriptGui:
|
|
|
47
49
|
raise ScriptUserAbortException( "User did not provide value in dialog" )
|
|
48
50
|
return result
|
|
49
51
|
def ask_number(self, message, default_value=None ):
|
|
52
|
+
assert not threading.currentThread().getName().startswith("Parallel"), "GUI functions cannot be called from a parallel thread"
|
|
50
53
|
if threading.currentThread().getName()=="ScriptThread":
|
|
51
54
|
return self.__run_with_timer(self.ask_number, message, default_value )
|
|
52
55
|
result = None
|
|
@@ -69,6 +72,7 @@ class ScriptGui:
|
|
|
69
72
|
raise ScriptUserAbortException( "User did not provide value in dialog" )
|
|
70
73
|
return result
|
|
71
74
|
def ask_yesno(self, message, cancel = False):
|
|
75
|
+
assert not threading.currentThread().getName().startswith("Parallel"), "GUI functions cannot be called from a parallel thread"
|
|
72
76
|
if threading.currentThread().getName()=="ScriptThread":
|
|
73
77
|
return self.__run_with_timer(self.ask_yesno, message, cancel )
|
|
74
78
|
style = wx.YES_NO|wx.CANCEL if cancel else wx.YES_NO
|
|
@@ -81,6 +85,7 @@ class ScriptGui:
|
|
|
81
85
|
return False
|
|
82
86
|
raise ScriptUserAbortException( "User did not answer yes/no dialog" )
|
|
83
87
|
def ask_image(self, message, filename, arrow_pos=None, yesno=False, cancel=False, numeric=False):
|
|
88
|
+
assert not threading.currentThread().getName().startswith("Parallel"), "GUI functions cannot be called from a parallel thread"
|
|
84
89
|
if threading.currentThread().getName()=="ScriptThread":
|
|
85
90
|
return self.__run_with_timer(self.ask_image, message, filename, arrow_pos, yesno, cancel, numeric )
|
|
86
91
|
form = FormAskImage(message, filename, arrow_pos, yesno, cancel, numeric )
|
|
@@ -91,6 +96,7 @@ class ScriptGui:
|
|
|
91
96
|
form.Destroy()
|
|
92
97
|
return result
|
|
93
98
|
def ask_choice(self, message, choices, do_assert = True):
|
|
99
|
+
assert not threading.currentThread().getName().startswith("Parallel"), "GUI functions cannot be called from a parallel thread"
|
|
94
100
|
if threading.currentThread().getName()=="ScriptThread":
|
|
95
101
|
return self.__run_with_timer(self.ask_choice, message, choices )
|
|
96
102
|
form = FormAskChoice(message, choices )
|
|
@@ -102,6 +108,7 @@ class ScriptGui:
|
|
|
102
108
|
form.Destroy()
|
|
103
109
|
return result
|
|
104
110
|
def ask_open_file(self, message, wildcard):
|
|
111
|
+
assert not threading.currentThread().getName().startswith("Parallel"), "GUI functions cannot be called from a parallel thread"
|
|
105
112
|
if threading.currentThread().getName() == "ScriptThread":
|
|
106
113
|
return self.__run_with_timer(self.ask_open_file, message, wildcard)
|
|
107
114
|
style = wx.FD_OPEN | wx.FD_FILE_MUST_EXIST
|
|
@@ -111,6 +118,7 @@ class ScriptGui:
|
|
|
111
118
|
return None
|
|
112
119
|
return dlg.GetPath()
|
|
113
120
|
def show_stop_dialog(self, message=None ):
|
|
121
|
+
assert not threading.currentThread().getName().startswith("Parallel"), "GUI functions cannot be called from a parallel thread"
|
|
114
122
|
if threading.currentThread().getName() == "ScriptThread":
|
|
115
123
|
return self.__run_with_timer(self.show_stop_dialog, message)
|
|
116
124
|
if message is None:
|
|
@@ -121,6 +129,7 @@ class ScriptGui:
|
|
|
121
129
|
self.m_stop_dialog.update_message(message)
|
|
122
130
|
self.m_stop_dialog.Show()
|
|
123
131
|
def close_stop_dialog(self):
|
|
132
|
+
assert not threading.currentThread().getName().startswith("Parallel"), "GUI functions cannot be called from a parallel thread"
|
|
124
133
|
if self.m_stop_dialog is None:
|
|
125
134
|
return
|
|
126
135
|
if threading.currentThread().getName() == "ScriptThread":
|
|
@@ -128,24 +137,30 @@ class ScriptGui:
|
|
|
128
137
|
self.m_stop_dialog.Destroy()
|
|
129
138
|
self.m_stop_dialog = None
|
|
130
139
|
def add_scatter_chart(self, name):
|
|
140
|
+
assert not threading.currentThread().getName().startswith("Parallel"), "GUI functions cannot be called from a parallel thread"
|
|
131
141
|
if threading.currentThread().getName() == "ScriptThread":
|
|
132
142
|
return self.__run_with_timer(self.add_scatter_chart, name)
|
|
133
143
|
return self._mngr.charts.add_scatter_chart(name)
|
|
134
144
|
def add_time_chart(self, name):
|
|
145
|
+
assert not threading.currentThread().getName().startswith("Parallel"), "GUI functions cannot be called from a parallel thread"
|
|
135
146
|
if threading.currentThread().getName() == "ScriptThread":
|
|
136
147
|
return self.__run_with_timer(self.add_time_chart, name)
|
|
137
148
|
return self._mngr.charts.add_time_chart(name)
|
|
138
149
|
def add_histogram(self, name, binsize):
|
|
150
|
+
assert not threading.currentThread().getName().startswith("Parallel"), "GUI functions cannot be called from a parallel thread"
|
|
139
151
|
if threading.currentThread().getName() == "ScriptThread":
|
|
140
152
|
return self.__run_with_timer(self.add_histogram, name, binsize)
|
|
141
153
|
return self._mngr.charts.add_histogram(name, binsize)
|
|
142
154
|
def add_matplotlib(self, name):
|
|
155
|
+
assert not threading.currentThread().getName().startswith("Parallel"), "GUI functions cannot be called from a parallel thread"
|
|
143
156
|
if threading.currentThread().getName() == "ScriptThread":
|
|
144
157
|
return self.__run_with_timer(self.add_matplotlib, name)
|
|
145
158
|
return self._mngr.charts.add_matplotlib(name)
|
|
146
159
|
def get_chart(self, name):
|
|
160
|
+
assert not threading.currentThread().getName().startswith("Parallel"), "GUI functions cannot be called from a parallel thread"
|
|
147
161
|
return self._mngr.charts.get_chart(name)
|
|
148
162
|
def delete_chart(self, name):
|
|
163
|
+
assert not threading.currentThread().getName().startswith("Parallel"), "GUI functions cannot be called from a parallel thread"
|
|
149
164
|
if threading.currentThread().getName() == "ScriptThread":
|
|
150
165
|
return self.__run_with_timer(self.delete_chart, name)
|
|
151
166
|
self._mngr.charts.delete_chart(name)
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import logging, os, time
|
|
2
|
-
import yaml
|
|
3
2
|
class ScriptInfo(object):
|
|
4
3
|
logger = logging.getLogger('happyscript')
|
|
5
|
-
def __init__(self, testlist):
|
|
4
|
+
def __init__(self, testlist, use_yaml:bool):
|
|
6
5
|
self.clear()
|
|
7
6
|
self.__dict__["xx_testlist"] = testlist
|
|
7
|
+
self.__dict__["xx_use_yaml"] = use_yaml
|
|
8
8
|
def clear(self):
|
|
9
9
|
self.__dict__["xx_info"] = dict()
|
|
10
10
|
self.__dict__["xx_serials"] = list()
|
|
@@ -33,14 +33,28 @@ class ScriptInfo(object):
|
|
|
33
33
|
fname = self.xx_filename
|
|
34
34
|
if fname is None:
|
|
35
35
|
return
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
36
|
+
if self.xx_use_yaml:
|
|
37
|
+
import yaml
|
|
38
|
+
fname = os.path.splitext(fname)[0] + ".yml"
|
|
39
|
+
with open(fname, "w") as file:
|
|
40
|
+
if len(self.serials)>0:
|
|
41
|
+
serials_dict = { 'serials': self.serials }
|
|
42
|
+
yaml.dump(serials_dict, file)
|
|
43
|
+
if len(self.xx_info)>0:
|
|
44
|
+
yaml.dump(self.xx_info, file)
|
|
45
|
+
else:
|
|
46
|
+
import json
|
|
47
|
+
fname = os.path.splitext(fname)[0] + ".json"
|
|
48
|
+
with open(fname, "w", encoding="utf-8") as file:
|
|
49
|
+
if len(self.serials)>0 and len(self.xx_info)>0:
|
|
50
|
+
self.xx_info["serials"] = self.serials
|
|
51
|
+
json.dump(self.xx_info, file, ensure_ascii=False, indent=4)
|
|
52
|
+
del self.xx_info["serials"]
|
|
53
|
+
elif len(self.serials)>0:
|
|
54
|
+
serials_dict = { 'serials': self.serials }
|
|
55
|
+
json.dump(serials_dict, file, ensure_ascii=False, indent=4)
|
|
56
|
+
elif len(self.xx_info)>0:
|
|
57
|
+
json.dump(self.xx_info, file, ensure_ascii=False, indent=4)
|
|
44
58
|
def update_file(self, force=False):
|
|
45
59
|
if len(self.xx_info)==0 and len(self.serials)==0:
|
|
46
60
|
return
|
|
@@ -34,7 +34,7 @@ class TestLogHandler(logging.FileHandler):
|
|
|
34
34
|
class ScriptManager(object):
|
|
35
35
|
dialog = None
|
|
36
36
|
logger = logging.getLogger("happyscript")
|
|
37
|
-
def __init__(self, title=None, colors = None):
|
|
37
|
+
def __init__(self, title=None, colors = None, use_yaml=False):
|
|
38
38
|
fixedcolors = [ (226, 239, 217), (222, 235, 246), (255, 242, 204), (237, 237, 237),
|
|
39
39
|
(251, 229, 213), (217, 226, 243) ]
|
|
40
40
|
self.on_batch_start = None
|
|
@@ -58,12 +58,12 @@ class ScriptManager(object):
|
|
|
58
58
|
self.ctrl = ScriptControl()
|
|
59
59
|
self.gui = ScriptGui(self)
|
|
60
60
|
self.dialog.on_gui_timer = self.gui.on_gui_timer
|
|
61
|
-
self.info = ScriptInfo( self.dialog.pnlTests )
|
|
61
|
+
self.info = ScriptInfo( self.dialog.pnlTests, use_yaml )
|
|
62
62
|
self._script_params = ScriptParams(self.gui)
|
|
63
63
|
self._script_params.on_add_object = self._on_add_object
|
|
64
64
|
self._script_readers = dict()
|
|
65
65
|
self._script_runner = ScriptRunner(self._script_params, self._script_readers, self.ctrl)
|
|
66
|
-
self.ctrl.
|
|
66
|
+
self.ctrl.set_script_runner( self._script_runner )
|
|
67
67
|
self._script_params.add_objects( ctrl=self.ctrl, gui=self.gui, info=self.info )
|
|
68
68
|
self.dialog.pnlTests.on_sequence_start_callback = self.handle_batch_start
|
|
69
69
|
self.dialog.pnlTests.on_sequence_end_callback = self.handle_batch_end
|
|
@@ -2,7 +2,7 @@ import datetime, logging, threading
|
|
|
2
2
|
from .scriptexceptions import ScriptUserAbortException
|
|
3
3
|
from .scriptexceptions import ScriptRecursiveAbortException
|
|
4
4
|
class ScriptThreadRunner:
|
|
5
|
-
logger = logging.getLogger("happyscript.
|
|
5
|
+
logger = logging.getLogger("happyscript.scriptrunner")
|
|
6
6
|
MARKER_LEVEL = 25
|
|
7
7
|
def __init__(self, ctrl):
|
|
8
8
|
self._ctrl = ctrl
|
|
@@ -56,6 +56,29 @@ class ScriptThreadRunner:
|
|
|
56
56
|
self.last_result = test_passed
|
|
57
57
|
self._ctrl.set_busy(False)
|
|
58
58
|
self.busy = False
|
|
59
|
+
class ScriptParallelThread(threading.Thread):
|
|
60
|
+
thread_counter = 0
|
|
61
|
+
def __init__(self, ctrl, func, arg_list):
|
|
62
|
+
thread_name = "Parallel" + str(ScriptParallelThread.thread_counter)
|
|
63
|
+
threading.Thread.__init__(self, name=thread_name)
|
|
64
|
+
ScriptParallelThread.thread_counter += 1
|
|
65
|
+
self._ctrl = ctrl
|
|
66
|
+
self.the_func = func
|
|
67
|
+
self.arg_list = arg_list
|
|
68
|
+
self.success = False
|
|
69
|
+
self.stopped_by_user = False
|
|
70
|
+
self.start()
|
|
71
|
+
def run(self):
|
|
72
|
+
try:
|
|
73
|
+
self.the_func( *self.arg_list )
|
|
74
|
+
self.success = True
|
|
75
|
+
except ScriptUserAbortException as _:
|
|
76
|
+
pass
|
|
77
|
+
except Exception as e:
|
|
78
|
+
if self._ctrl.m_stop_script:
|
|
79
|
+
self.stopped_by_user = True
|
|
80
|
+
else:
|
|
81
|
+
logging.error(str(e), exc_info = e)
|
|
59
82
|
class ScriptRunner:
|
|
60
83
|
logger = logging.getLogger("happyscript.runner")
|
|
61
84
|
def __init__(self, script_params, script_readers, script_control):
|
|
@@ -63,6 +86,7 @@ class ScriptRunner:
|
|
|
63
86
|
self._readers = script_readers
|
|
64
87
|
self._recurse_count = 0
|
|
65
88
|
self.start_ok = False
|
|
89
|
+
self._ctrl = script_control
|
|
66
90
|
self.thread_runner = ScriptThreadRunner(script_control)
|
|
67
91
|
@property
|
|
68
92
|
def test_passed(self):
|
|
@@ -70,29 +94,52 @@ class ScriptRunner:
|
|
|
70
94
|
@property
|
|
71
95
|
def busy(self):
|
|
72
96
|
return self.thread_runner.busy
|
|
73
|
-
def
|
|
97
|
+
def find_scriptfunct(self, script_name):
|
|
74
98
|
parts = script_name.split(".")
|
|
75
99
|
if len(parts) != 3:
|
|
76
100
|
self.logger.error("Must provide script name as dirname.filename.scriptname")
|
|
77
|
-
return
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
if not group_name in self._readers:
|
|
83
|
-
self.logger.error("Cannot start %s : group %s not found" % (scriptname, group_name))
|
|
84
|
-
return
|
|
85
|
-
func = self._readers[group_name].get_func(filename, funcname)
|
|
101
|
+
return None
|
|
102
|
+
if not parts[0] in self._readers:
|
|
103
|
+
self.logger.error("Cannot start %s : group %s not found", script_name, parts[0])
|
|
104
|
+
return None
|
|
105
|
+
func = self._readers[parts[0]].get_func(parts[1], parts[2])
|
|
86
106
|
if func is None:
|
|
87
|
-
self.logger.error("Cannot start %s : function not found"
|
|
107
|
+
self.logger.error("Cannot start %s : function not found", script_name)
|
|
108
|
+
return func
|
|
109
|
+
def run_script(self, script_name, **extra_params):
|
|
110
|
+
self.start_ok = False
|
|
111
|
+
if threading.currentThread().getName().startswith("Parallel"):
|
|
112
|
+
self.logger.error("You cannot start other scripts in a parallel thread.")
|
|
88
113
|
return
|
|
89
|
-
|
|
90
|
-
|
|
114
|
+
func = self.find_scriptfunct(script_name)
|
|
115
|
+
if func is None: return
|
|
91
116
|
(argvalues, missing) = self.script_params.get_parameters(func, extra_params)
|
|
92
117
|
if len(missing)>0:
|
|
93
118
|
self.logger.error( "Error : missing value for parameter(s) %s" % ("".join(missing) ) )
|
|
94
|
-
self.logger.error( " Make sure to use valid names as parameters for your function.")
|
|
95
|
-
self.logger.log(self.MARKER_LEVEL, "\\_________%s_________ ERROR ______/" % scriptname )
|
|
96
119
|
return
|
|
97
|
-
self.thread_runner.execute_script(
|
|
120
|
+
self.thread_runner.execute_script(script_name, func, argvalues)
|
|
98
121
|
self.start_ok = True
|
|
122
|
+
def run_parallel(self, func, parname, parvalues, **extra_params):
|
|
123
|
+
assert threading.currentThread().getName()=="ScriptThread", "run_parallel() can only be executed from within a (non-parallel) script function"
|
|
124
|
+
if not callable(func):
|
|
125
|
+
func = self.find_scriptfunct(func)
|
|
126
|
+
assert func is not None, f"Parameter 'func' of run_parallel is no function or script name."
|
|
127
|
+
threads = list()
|
|
128
|
+
for val in parvalues:
|
|
129
|
+
extra_params[parname] = val
|
|
130
|
+
(argvalues, missing) = self.script_params.get_parameters(func, extra_params)
|
|
131
|
+
if len(missing)>0:
|
|
132
|
+
self.logger.error( "Error : missing value for parameter(s) %s" % ("".join(missing) ) )
|
|
133
|
+
return
|
|
134
|
+
threads.append( ScriptParallelThread(self._ctrl, func, argvalues) )
|
|
135
|
+
fail_count = 0
|
|
136
|
+
stopped_by_user = 0
|
|
137
|
+
for thread in threads:
|
|
138
|
+
thread.join()
|
|
139
|
+
if not thread.success:
|
|
140
|
+
fail_count += 1
|
|
141
|
+
if thread.stopped_by_user:
|
|
142
|
+
stopped_by_user += 1
|
|
143
|
+
if stopped_by_user>0:
|
|
144
|
+
self.logger.error(f"{stopped_by_user} scripts stopped by user")
|
|
145
|
+
assert fail_count==0, f"Parallel executiong failed on {fail_count} threads"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|