ivoryos 1.0.9__py3-none-any.whl → 1.2.0b1__py3-none-any.whl
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.
Potentially problematic release.
This version of ivoryos might be problematic. Click here for more details.
- ivoryos/__init__.py +26 -7
- ivoryos/routes/api/api.py +56 -0
- ivoryos/routes/auth/auth.py +5 -5
- ivoryos/routes/control/control.py +77 -372
- ivoryos/routes/control/control_file.py +36 -0
- ivoryos/routes/control/control_new_device.py +142 -0
- ivoryos/routes/control/templates/controllers.html +166 -0
- ivoryos/routes/control/templates/controllers_new.html +112 -0
- ivoryos/routes/control/utils.py +38 -0
- ivoryos/routes/data/data.py +129 -0
- ivoryos/routes/data/templates/components/step_card.html +13 -0
- ivoryos/routes/{database/templates/database → data/templates}/workflow_database.html +14 -8
- ivoryos/routes/{database/templates/database → data/templates}/workflow_view.html +3 -3
- ivoryos/routes/design/__init__.py +4 -0
- ivoryos/routes/design/design.py +298 -656
- ivoryos/routes/design/design_file.py +68 -0
- ivoryos/routes/design/design_step.py +145 -0
- ivoryos/routes/design/templates/components/action_form.html +53 -0
- ivoryos/routes/design/templates/components/actions_panel.html +25 -0
- ivoryos/routes/design/templates/components/autofill_toggle.html +10 -0
- ivoryos/routes/design/templates/components/canvas.html +5 -0
- ivoryos/routes/design/templates/components/canvas_footer.html +9 -0
- ivoryos/routes/design/templates/components/canvas_header.html +75 -0
- ivoryos/routes/design/templates/components/canvas_main.html +34 -0
- ivoryos/routes/design/templates/components/deck_selector.html +10 -0
- ivoryos/routes/design/templates/components/edit_action_form.html +38 -0
- ivoryos/routes/design/templates/components/instruments_panel.html +66 -0
- ivoryos/routes/design/templates/components/modals/drop_modal.html +17 -0
- ivoryos/routes/design/templates/components/modals/json_modal.html +22 -0
- ivoryos/routes/design/templates/components/modals/new_script_modal.html +17 -0
- ivoryos/routes/design/templates/components/modals/rename_modal.html +23 -0
- ivoryos/routes/design/templates/components/modals/saveas_modal.html +27 -0
- ivoryos/routes/design/templates/components/modals.html +6 -0
- ivoryos/routes/design/templates/components/python_code_overlay.html +39 -0
- ivoryos/routes/design/templates/components/sidebar.html +15 -0
- ivoryos/routes/design/templates/components/text_to_code_panel.html +20 -0
- ivoryos/routes/design/templates/experiment_builder.html +41 -0
- ivoryos/routes/execute/__init__.py +0 -0
- ivoryos/routes/execute/execute.py +317 -0
- ivoryos/routes/execute/execute_file.py +78 -0
- ivoryos/routes/execute/templates/components/error_modal.html +20 -0
- ivoryos/routes/execute/templates/components/logging_panel.html +31 -0
- ivoryos/routes/execute/templates/components/progress_panel.html +27 -0
- ivoryos/routes/execute/templates/components/run_panel.html +9 -0
- ivoryos/routes/execute/templates/components/run_tabs.html +17 -0
- ivoryos/routes/execute/templates/components/tab_bayesian.html +399 -0
- ivoryos/routes/execute/templates/components/tab_configuration.html +98 -0
- ivoryos/routes/execute/templates/components/tab_repeat.html +14 -0
- ivoryos/routes/execute/templates/experiment_run.html +294 -0
- ivoryos/routes/library/__init__.py +0 -0
- ivoryos/routes/library/library.py +159 -0
- ivoryos/routes/{database/templates/database/scripts_database.html → library/templates/library.html} +30 -22
- ivoryos/routes/main/main.py +1 -1
- ivoryos/routes/main/templates/{main/home.html → home.html} +4 -4
- ivoryos/socket_handlers.py +52 -0
- ivoryos/static/js/action_handlers.js +213 -0
- ivoryos/static/js/db_delete.js +23 -0
- ivoryos/static/js/script_metadata.js +39 -0
- ivoryos/static/js/sortable_design.js +89 -56
- ivoryos/static/js/ui_state.js +113 -0
- ivoryos/templates/base.html +4 -4
- ivoryos/utils/bo_campaign.py +179 -3
- ivoryos/utils/db_models.py +14 -5
- ivoryos/utils/form.py +5 -9
- ivoryos/utils/global_config.py +13 -1
- ivoryos/utils/py_to_json.py +225 -0
- ivoryos/utils/script_runner.py +49 -7
- ivoryos/utils/serilize.py +203 -0
- ivoryos/utils/task_runner.py +4 -1
- ivoryos/version.py +1 -1
- {ivoryos-1.0.9.dist-info → ivoryos-1.2.0b1.dist-info}/METADATA +5 -8
- ivoryos-1.2.0b1.dist-info/RECORD +105 -0
- ivoryos/routes/control/templates/control/controllers.html +0 -78
- ivoryos/routes/control/templates/control/controllers_home.html +0 -55
- ivoryos/routes/control/templates/control/controllers_new.html +0 -89
- ivoryos/routes/database/database.py +0 -306
- ivoryos/routes/database/templates/database/step_card.html +0 -7
- ivoryos/routes/design/templates/design/experiment_builder.html +0 -521
- ivoryos/routes/design/templates/design/experiment_run.html +0 -558
- ivoryos-1.0.9.dist-info/RECORD +0 -61
- /ivoryos/routes/auth/templates/{auth/login.html → login.html} +0 -0
- /ivoryos/routes/auth/templates/{auth/signup.html → signup.html} +0 -0
- /ivoryos/routes/{database → data}/__init__.py +0 -0
- /ivoryos/routes/main/templates/{main/help.html → help.html} +0 -0
- {ivoryos-1.0.9.dist-info → ivoryos-1.2.0b1.dist-info}/LICENSE +0 -0
- {ivoryos-1.0.9.dist-info → ivoryos-1.2.0b1.dist-info}/WHEEL +0 -0
- {ivoryos-1.0.9.dist-info → ivoryos-1.2.0b1.dist-info}/top_level.txt +0 -0
|
@@ -1,350 +1,97 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
from flask import Blueprint, redirect, url_for, flash, request, render_template, session, current_app, jsonify, \
|
|
4
|
-
send_file
|
|
1
|
+
from flask import Blueprint, redirect, flash, request, render_template, session, current_app, jsonify
|
|
5
2
|
from flask_login import login_required
|
|
6
3
|
|
|
7
|
-
from ivoryos.
|
|
4
|
+
from ivoryos.routes.control.control_file import control_file
|
|
5
|
+
from ivoryos.routes.control.control_new_device import control_temp
|
|
6
|
+
from ivoryos.routes.control.utils import post_session_by_instrument, get_session_by_instrument, find_instrument_by_name
|
|
8
7
|
from ivoryos.utils.global_config import GlobalConfig
|
|
9
|
-
from ivoryos.utils import
|
|
10
|
-
from ivoryos.utils.form import create_form_from_module, format_name
|
|
8
|
+
from ivoryos.utils.form import create_form_from_module
|
|
11
9
|
from ivoryos.utils.task_runner import TaskRunner
|
|
12
10
|
|
|
13
11
|
global_config = GlobalConfig()
|
|
14
12
|
runner = TaskRunner()
|
|
15
13
|
|
|
16
|
-
control = Blueprint('control', __name__, template_folder='templates
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
@control.route("/control/home/deck", strict_slashes=False)
|
|
20
|
-
@login_required
|
|
21
|
-
def deck_controllers():
|
|
22
|
-
"""
|
|
23
|
-
.. :quickref: Direct Control; controls home interface
|
|
24
|
-
|
|
25
|
-
deck control home interface for listing all deck instruments
|
|
26
|
-
|
|
27
|
-
.. http:get:: /control/home/deck
|
|
28
|
-
"""
|
|
29
|
-
deck_variables = global_config.deck_snapshot.keys()
|
|
30
|
-
deck_list = utils.import_history(os.path.join(current_app.config["OUTPUT_FOLDER"], 'deck_history.txt'))
|
|
31
|
-
return render_template('controllers_home.html', defined_variables=deck_variables, deck=True, history=deck_list)
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
@control.route("/control/new/", strict_slashes=False)
|
|
35
|
-
@control.route("/control/new/<instrument>", methods=['GET', 'POST'])
|
|
36
|
-
@login_required
|
|
37
|
-
def new_controller(instrument=None):
|
|
38
|
-
"""
|
|
39
|
-
.. :quickref: Direct Control; connect to a new device
|
|
40
|
-
|
|
41
|
-
interface for connecting a new <instrument>
|
|
42
|
-
|
|
43
|
-
.. http:get:: /control/new/
|
|
44
|
-
|
|
45
|
-
:param instrument: instrument name
|
|
46
|
-
:type instrument: str
|
|
47
|
-
|
|
48
|
-
.. http:post:: /control/new/
|
|
49
|
-
|
|
50
|
-
:form device_name: module instance name (e.g. my_instance = MyClass())
|
|
51
|
-
:form kwargs: dynamic module initialization kwargs fields
|
|
52
|
-
|
|
53
|
-
"""
|
|
54
|
-
device = None
|
|
55
|
-
args = None
|
|
56
|
-
if instrument:
|
|
57
|
-
|
|
58
|
-
device = find_instrument_by_name(instrument)
|
|
59
|
-
args = utils.inspect.signature(device.__init__)
|
|
14
|
+
control = Blueprint('control', __name__, template_folder='templates')
|
|
60
15
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
if device_name and device_name in globals():
|
|
64
|
-
flash("Device name is defined. Try another name, or leave it as blank to auto-configure")
|
|
65
|
-
return render_template('controllers_new.html', instrument=instrument,
|
|
66
|
-
api_variables=global_config.api_variables,
|
|
67
|
-
device=device, args=args, defined_variables=global_config.defined_variables)
|
|
68
|
-
if device_name == "":
|
|
69
|
-
device_name = device.__name__.lower() + "_"
|
|
70
|
-
num = 1
|
|
71
|
-
while device_name + str(num) in global_config.defined_variables:
|
|
72
|
-
num += 1
|
|
73
|
-
device_name = device_name + str(num)
|
|
74
|
-
kwargs = request.form.to_dict()
|
|
75
|
-
kwargs.pop("device_name")
|
|
76
|
-
for i in kwargs:
|
|
77
|
-
if kwargs[i] in global_config.defined_variables:
|
|
78
|
-
kwargs[i] = global_config.defined_variables[kwargs[i]]
|
|
79
|
-
try:
|
|
80
|
-
utils.convert_config_type(kwargs, device.__init__.__annotations__, is_class=True)
|
|
81
|
-
except Exception as e:
|
|
82
|
-
flash(e)
|
|
83
|
-
try:
|
|
84
|
-
global_config.defined_variables[device_name] = device(**kwargs)
|
|
85
|
-
# global_config.defined_variables.add(device_name)
|
|
86
|
-
return redirect(url_for('control.controllers_home'))
|
|
87
|
-
except Exception as e:
|
|
88
|
-
flash(e)
|
|
89
|
-
return render_template('controllers_new.html', instrument=instrument, api_variables=global_config.api_variables,
|
|
90
|
-
device=device, args=args, defined_variables=global_config.defined_variables)
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
@control.route("/control/home/temp", strict_slashes=False)
|
|
94
|
-
@login_required
|
|
95
|
-
def controllers_home():
|
|
96
|
-
"""
|
|
97
|
-
.. :quickref: Direct Control; temp control home interface
|
|
98
|
-
|
|
99
|
-
temporarily connected devices home interface for listing all instruments
|
|
16
|
+
control.register_blueprint(control_file)
|
|
17
|
+
control.register_blueprint(control_temp)
|
|
100
18
|
|
|
101
|
-
.. http:get:: /control/home/temp
|
|
102
|
-
|
|
103
|
-
"""
|
|
104
|
-
# defined_variables = parse_deck(deck)
|
|
105
|
-
defined_variables = global_config.defined_variables.keys()
|
|
106
|
-
return render_template('controllers_home.html', defined_variables=defined_variables)
|
|
107
19
|
|
|
108
20
|
|
|
109
|
-
@control.route("/
|
|
21
|
+
@control.route("/", strict_slashes=False, methods=["GET", "POST"])
|
|
22
|
+
@control.route("/<string:instrument>", strict_slashes=False, methods=["GET", "POST"])
|
|
110
23
|
@login_required
|
|
111
|
-
def
|
|
112
|
-
"""
|
|
113
|
-
.. :quickref: Direct Control; control interface
|
|
114
|
-
|
|
115
|
-
control interface for selected <instrument>
|
|
116
|
-
|
|
117
|
-
.. http:get:: /control/<instrument>/methods
|
|
118
|
-
|
|
119
|
-
:param instrument: instrument name
|
|
120
|
-
:type instrument: str
|
|
121
|
-
|
|
122
|
-
.. http:post:: /control/<instrument>/methods
|
|
123
|
-
|
|
124
|
-
:form hidden_name: function name (hidden field)
|
|
125
|
-
:form kwargs: dynamic kwargs field
|
|
126
|
-
|
|
24
|
+
def deck_controllers():
|
|
127
25
|
"""
|
|
128
|
-
|
|
129
|
-
_forms = create_form_from_module(sdl_module=inst_object, autofill=False, design=False)
|
|
130
|
-
functions = list(_forms.keys())
|
|
131
|
-
|
|
132
|
-
order = get_session_by_instrument('card_order', instrument)
|
|
133
|
-
hidden_functions = get_session_by_instrument('hide_function', instrument)
|
|
26
|
+
.. :quickref: Direct Control; device (instruments) and methods
|
|
134
27
|
|
|
135
|
-
for
|
|
136
|
-
if function not in hidden_functions and function not in order:
|
|
137
|
-
order.append(function)
|
|
138
|
-
post_session_by_instrument('card_order', instrument, order)
|
|
139
|
-
forms = {name: _forms[name] for name in order if name in _forms}
|
|
140
|
-
if request.method == 'POST':
|
|
141
|
-
all_kwargs = request.form.copy()
|
|
142
|
-
method_name = all_kwargs.pop("hidden_name", None)
|
|
143
|
-
# if method_name is not None:
|
|
144
|
-
form = forms.get(method_name)
|
|
145
|
-
kwargs = {field.name: field.data for field in form if field.name != 'csrf_token'}
|
|
146
|
-
function_executable = getattr(inst_object, method_name)
|
|
147
|
-
if form and form.validate_on_submit():
|
|
148
|
-
try:
|
|
149
|
-
kwargs.pop("hidden_name")
|
|
150
|
-
output = runner.run_single_step(instrument, method_name, kwargs, wait=True,
|
|
151
|
-
current_app=current_app._get_current_object())
|
|
152
|
-
# output = function_executable(**kwargs)
|
|
153
|
-
flash(f"\nRun Success! Output value: {output}.")
|
|
154
|
-
except Exception as e:
|
|
155
|
-
flash(e.__str__())
|
|
156
|
-
else:
|
|
157
|
-
flash(form.errors)
|
|
158
|
-
return render_template('controllers.html', instrument=instrument, forms=forms, format_name=format_name)
|
|
28
|
+
device home interface for listing all instruments and methods, selecting an instrument to run its methods
|
|
159
29
|
|
|
160
|
-
|
|
161
|
-
@login_required
|
|
162
|
-
def download_proxy():
|
|
163
|
-
"""
|
|
164
|
-
.. :quickref: Direct Control; download proxy interface
|
|
30
|
+
.. http:get:: /instruments
|
|
165
31
|
|
|
166
|
-
|
|
32
|
+
get all instruments for home page
|
|
167
33
|
|
|
168
|
-
.. http:get:: /
|
|
169
|
-
"""
|
|
170
|
-
snapshot = global_config.deck_snapshot.copy()
|
|
171
|
-
class_definitions = {}
|
|
172
|
-
# Iterate through each instrument in the snapshot
|
|
173
|
-
for instrument_key, instrument_data in snapshot.items():
|
|
174
|
-
# Iterate through each function associated with the current instrument
|
|
175
|
-
for function_key, function_data in instrument_data.items():
|
|
176
|
-
# Convert the function signature to a string representation
|
|
177
|
-
function_data['signature'] = str(function_data['signature'])
|
|
178
|
-
class_name = instrument_key.split('.')[-1] # Extracting the class name from the path
|
|
179
|
-
class_definitions[class_name.capitalize()] = create_function(request.url_root, class_name, instrument_data)
|
|
180
|
-
# Export the generated class definitions to a .py script
|
|
181
|
-
export_to_python(class_definitions, current_app.config["OUTPUT_FOLDER"])
|
|
182
|
-
filepath = os.path.join(current_app.config["OUTPUT_FOLDER"], "generated_proxy.py")
|
|
183
|
-
return send_file(os.path.abspath(filepath), as_attachment=True)
|
|
34
|
+
.. http:get:: /instruments/<string:instrument>
|
|
184
35
|
|
|
185
|
-
|
|
186
|
-
@control.route("/api/control/<instrument>", methods=['POST'])
|
|
187
|
-
def backend_control(instrument: str=None):
|
|
188
|
-
"""
|
|
189
|
-
.. :quickref: Backend Control; backend control
|
|
36
|
+
get all methods of the given <instrument>
|
|
190
37
|
|
|
191
|
-
|
|
38
|
+
.. http:post:: /instruments/<string:instrument>
|
|
192
39
|
|
|
193
|
-
|
|
40
|
+
send POST request to run a method of the given <instrument>
|
|
194
41
|
|
|
195
|
-
:param instrument: instrument name
|
|
42
|
+
:param instrument: instrument name, if not provided, list all instruments
|
|
196
43
|
:type instrument: str
|
|
197
|
-
|
|
198
|
-
.. http:post:: /api/control/
|
|
44
|
+
:status 200: render template with instruments and methods
|
|
199
45
|
|
|
200
46
|
"""
|
|
47
|
+
deck_variables = global_config.deck_snapshot.keys()
|
|
48
|
+
temp_variables = global_config.defined_variables.keys()
|
|
49
|
+
instrument = request.args.get('instrument')
|
|
50
|
+
forms = None
|
|
201
51
|
if instrument:
|
|
202
52
|
inst_object = find_instrument_by_name(instrument)
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
# # Convert the function signature to a string representation
|
|
241
|
-
# function_data['signature'] = str(function_data['signature'])
|
|
242
|
-
# return jsonify(snapshot), 200
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
@control.route("/control/import/module", methods=['POST'])
|
|
246
|
-
def import_api():
|
|
247
|
-
"""
|
|
248
|
-
.. :quickref: Advanced Features; Manually import API module(s)
|
|
249
|
-
|
|
250
|
-
importing other Python modules
|
|
251
|
-
|
|
252
|
-
.. http:post:: /control/import/module
|
|
253
|
-
|
|
254
|
-
:form filepath: API (Python class) module filepath
|
|
255
|
-
|
|
256
|
-
import the module and redirect to :http:get:`/ivoryos/control/new/`
|
|
257
|
-
|
|
258
|
-
"""
|
|
259
|
-
filepath = request.form.get('filepath')
|
|
260
|
-
# filepath.replace('\\', '/')
|
|
261
|
-
name = os.path.split(filepath)[-1].split('.')[0]
|
|
262
|
-
try:
|
|
263
|
-
spec = utils.importlib.util.spec_from_file_location(name, filepath)
|
|
264
|
-
module = utils.importlib.util.module_from_spec(spec)
|
|
265
|
-
spec.loader.exec_module(module)
|
|
266
|
-
classes = utils.inspect.getmembers(module, utils.inspect.isclass)
|
|
267
|
-
if len(classes) == 0:
|
|
268
|
-
flash("Invalid import: no class found in the path")
|
|
269
|
-
return redirect(url_for("control.controllers_home"))
|
|
270
|
-
for i in classes:
|
|
271
|
-
globals()[i[0]] = i[1]
|
|
272
|
-
global_config.api_variables.add(i[0])
|
|
273
|
-
# should handle path error and file type error
|
|
274
|
-
except Exception as e:
|
|
275
|
-
flash(e.__str__())
|
|
276
|
-
return redirect(url_for("control.new_controller"))
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
# @control.route("/disconnect", methods=["GET"])
|
|
280
|
-
# @control.route("/disconnect/<device_name>", methods=["GET"])
|
|
281
|
-
# def disconnect(device_name=None):
|
|
282
|
-
# """TODO handle disconnect device"""
|
|
283
|
-
# if device_name:
|
|
284
|
-
# try:
|
|
285
|
-
# exec(device_name + ".disconnect()")
|
|
286
|
-
# except Exception:
|
|
287
|
-
# pass
|
|
288
|
-
# global_config.defined_variables.remove(device_name)
|
|
289
|
-
# globals().pop(device_name)
|
|
290
|
-
# return redirect(url_for('control.controllers_home'))
|
|
291
|
-
#
|
|
292
|
-
# deck_variables = ["deck." + var for var in set(dir(deck))
|
|
293
|
-
# if not (var.startswith("_") or var[0].isupper() or var.startswith("repackage"))
|
|
294
|
-
# and not type(eval("deck." + var)).__module__ == 'builtins']
|
|
295
|
-
# for i in deck_variables:
|
|
296
|
-
# try:
|
|
297
|
-
# exec(i + ".disconnect()")
|
|
298
|
-
# except Exception:
|
|
299
|
-
# pass
|
|
300
|
-
# globals()["deck"] = None
|
|
301
|
-
# return redirect(url_for('control.deck_controllers'))
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
@control.route("/control/import/deck", methods=['POST'])
|
|
305
|
-
def import_deck():
|
|
306
|
-
"""
|
|
307
|
-
.. :quickref: Advanced Features; Manually import a deck
|
|
308
|
-
|
|
309
|
-
.. http:post:: /control/import_deck
|
|
310
|
-
|
|
311
|
-
:form filepath: deck module filepath
|
|
312
|
-
|
|
313
|
-
import the module and redirect to the previous page
|
|
314
|
-
|
|
315
|
-
"""
|
|
316
|
-
script = utils.get_script_file()
|
|
317
|
-
filepath = request.form.get('filepath')
|
|
318
|
-
session['dismiss'] = request.form.get('dismiss')
|
|
319
|
-
update = request.form.get('update')
|
|
320
|
-
back = request.referrer
|
|
321
|
-
if session['dismiss']:
|
|
322
|
-
return redirect(back)
|
|
323
|
-
name = os.path.split(filepath)[-1].split('.')[0]
|
|
324
|
-
try:
|
|
325
|
-
module = utils.import_module_by_filepath(filepath=filepath, name=name)
|
|
326
|
-
utils.save_to_history(filepath, current_app.config["DECK_HISTORY"])
|
|
327
|
-
module_sigs = utils.create_deck_snapshot(module, save=update, output_path=current_app.config["DUMMY_DECK"])
|
|
328
|
-
if not len(module_sigs) > 0:
|
|
329
|
-
flash("Invalid hardware deck, connect instruments in deck script", "error")
|
|
330
|
-
return redirect(url_for("control.deck_controllers"))
|
|
331
|
-
global_config.deck = module
|
|
332
|
-
global_config.deck_snapshot = module_sigs
|
|
333
|
-
|
|
334
|
-
if script.deck is None:
|
|
335
|
-
script.deck = module.__name__
|
|
336
|
-
# file path error exception
|
|
337
|
-
except Exception as e:
|
|
338
|
-
flash(e.__str__())
|
|
339
|
-
return redirect(back)
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
@control.route('/control/<instrument>/save-order', methods=['POST'])
|
|
53
|
+
_forms = create_form_from_module(sdl_module=inst_object, autofill=False, design=False)
|
|
54
|
+
order = get_session_by_instrument('card_order', instrument)
|
|
55
|
+
hidden_functions = get_session_by_instrument('hidden_functions', instrument)
|
|
56
|
+
functions = list(_forms.keys())
|
|
57
|
+
for function in functions:
|
|
58
|
+
if function not in hidden_functions and function not in order:
|
|
59
|
+
order.append(function)
|
|
60
|
+
post_session_by_instrument('card_order', instrument, order)
|
|
61
|
+
forms = {name: _forms[name] for name in order if name in _forms}
|
|
62
|
+
# Handle POST for method execution
|
|
63
|
+
if request.method == 'POST':
|
|
64
|
+
all_kwargs = request.form.copy()
|
|
65
|
+
method_name = all_kwargs.pop("hidden_name", None)
|
|
66
|
+
form = forms.get(method_name)
|
|
67
|
+
kwargs = {field.name: field.data for field in form if field.name != 'csrf_token'} if form else {}
|
|
68
|
+
if form and form.validate_on_submit():
|
|
69
|
+
kwargs.pop("hidden_name", None)
|
|
70
|
+
output = runner.run_single_step(instrument, method_name, kwargs, wait=True, current_app=current_app._get_current_object())
|
|
71
|
+
if output["success"]:
|
|
72
|
+
flash(f"\nRun Success! Output value: {output.get('output', 'None')}.")
|
|
73
|
+
else:
|
|
74
|
+
flash(f"\nRun Error! {output.get('output', 'Unknown error occurred.')}", "error")
|
|
75
|
+
else:
|
|
76
|
+
if form:
|
|
77
|
+
flash(form.errors)
|
|
78
|
+
else:
|
|
79
|
+
flash("Invalid method selected.")
|
|
80
|
+
return render_template(
|
|
81
|
+
'controllers.html',
|
|
82
|
+
defined_variables=deck_variables,
|
|
83
|
+
temp_variables=temp_variables,
|
|
84
|
+
instrument=instrument,
|
|
85
|
+
forms=forms,
|
|
86
|
+
session=session
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
@control.route('/<string:instrument>/actions/order', methods=['POST'])
|
|
343
90
|
def save_order(instrument: str):
|
|
344
91
|
"""
|
|
345
92
|
.. :quickref: Control Customization; Save functions' order
|
|
346
93
|
|
|
347
|
-
.. http:post:: /
|
|
94
|
+
.. http:post:: instruments/<string:instrument>/actions/order
|
|
348
95
|
|
|
349
96
|
save function drag and drop order for the given <instrument>
|
|
350
97
|
|
|
@@ -354,76 +101,34 @@ def save_order(instrument: str):
|
|
|
354
101
|
post_session_by_instrument('card_order', instrument, data['order'])
|
|
355
102
|
return '', 204
|
|
356
103
|
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
def hide_function(instrument, function):
|
|
104
|
+
@control.route('/<string:instrument>/actions/<string:function>', methods=["PATCH"])
|
|
105
|
+
def hide_function(instrument: str, function: str):
|
|
360
106
|
"""
|
|
361
|
-
.. :quickref: Control Customization;
|
|
107
|
+
.. :quickref: Control Customization; Toggle function visibility
|
|
362
108
|
|
|
363
|
-
.. http:
|
|
109
|
+
.. http:patch:: /instruments/<instrument>/actions/<function>
|
|
364
110
|
|
|
365
|
-
|
|
111
|
+
Toggle visibility for the given <instrument> and <function>
|
|
366
112
|
|
|
367
113
|
"""
|
|
368
114
|
back = request.referrer
|
|
115
|
+
data = request.get_json()
|
|
116
|
+
hidden = data.get('hidden', True)
|
|
369
117
|
functions = get_session_by_instrument("hidden_functions", instrument)
|
|
370
118
|
order = get_session_by_instrument("card_order", instrument)
|
|
371
|
-
if function not in functions:
|
|
119
|
+
if hidden and function not in functions:
|
|
372
120
|
functions.append(function)
|
|
373
|
-
order
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
return redirect(back)
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
@control.route('/control/<instrument>/<function>/unhide')
|
|
380
|
-
def remove_hidden(instrument: str, function: str):
|
|
381
|
-
"""
|
|
382
|
-
.. :quickref: Control Customization; Remove a hidden function
|
|
383
|
-
|
|
384
|
-
.. http:get:: /control/<instrument>/<function>/unhide
|
|
385
|
-
|
|
386
|
-
Un-hide the given <instrument> and <function>
|
|
387
|
-
|
|
388
|
-
"""
|
|
389
|
-
back = request.referrer
|
|
390
|
-
functions = get_session_by_instrument("hidden_functions", instrument)
|
|
391
|
-
order = get_session_by_instrument("card_order", instrument)
|
|
392
|
-
if function in functions:
|
|
121
|
+
if function in order:
|
|
122
|
+
order.remove(function)
|
|
123
|
+
elif not hidden and function in functions:
|
|
393
124
|
functions.remove(function)
|
|
394
|
-
order
|
|
125
|
+
if function not in order:
|
|
126
|
+
order.append(function)
|
|
395
127
|
post_session_by_instrument('hidden_functions', instrument, functions)
|
|
396
128
|
post_session_by_instrument('card_order', instrument, order)
|
|
397
|
-
return
|
|
398
|
-
|
|
129
|
+
return jsonify(success=True, message="Visibility updated")
|
|
399
130
|
|
|
400
|
-
def get_session_by_instrument(session_name, instrument):
|
|
401
|
-
"""get data from session by instrument"""
|
|
402
|
-
session_object = session.get(session_name, {})
|
|
403
|
-
functions = session_object.get(instrument, [])
|
|
404
|
-
return functions
|
|
405
131
|
|
|
406
132
|
|
|
407
|
-
def post_session_by_instrument(session_name, instrument, data):
|
|
408
|
-
"""
|
|
409
|
-
save new data to session by instrument
|
|
410
|
-
:param session_name: "card_order" or "hidden_functions"
|
|
411
|
-
:param instrument: function name of class object
|
|
412
|
-
:param data: order list or hidden function list
|
|
413
|
-
"""
|
|
414
|
-
session_object = session.get(session_name, {})
|
|
415
|
-
session_object[instrument] = data
|
|
416
|
-
session[session_name] = session_object
|
|
417
133
|
|
|
418
134
|
|
|
419
|
-
def find_instrument_by_name(name: str):
|
|
420
|
-
"""
|
|
421
|
-
find instrument class object by instance name
|
|
422
|
-
"""
|
|
423
|
-
if name.startswith("deck"):
|
|
424
|
-
name = name.replace("deck.", "")
|
|
425
|
-
return getattr(global_config.deck, name)
|
|
426
|
-
elif name in global_config.defined_variables:
|
|
427
|
-
return global_config.defined_variables[name]
|
|
428
|
-
elif name in globals():
|
|
429
|
-
return globals()[name]
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import os
|
|
2
|
+
from flask import Blueprint, request,current_app, send_file
|
|
3
|
+
from flask_login import login_required
|
|
4
|
+
|
|
5
|
+
from ivoryos.utils.client_proxy import export_to_python, create_function
|
|
6
|
+
from ivoryos.utils.global_config import GlobalConfig
|
|
7
|
+
|
|
8
|
+
global_config = GlobalConfig()
|
|
9
|
+
|
|
10
|
+
control_file = Blueprint('file', __name__)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@control_file.route("/files/proxy", strict_slashes=False)
|
|
14
|
+
@login_required
|
|
15
|
+
def download_proxy():
|
|
16
|
+
"""
|
|
17
|
+
.. :quickref: Direct Control Files; download proxy interface
|
|
18
|
+
|
|
19
|
+
download proxy Python interface
|
|
20
|
+
|
|
21
|
+
.. http:get:: /files/proxy
|
|
22
|
+
"""
|
|
23
|
+
snapshot = global_config.deck_snapshot.copy()
|
|
24
|
+
class_definitions = {}
|
|
25
|
+
# Iterate through each instrument in the snapshot
|
|
26
|
+
for instrument_key, instrument_data in snapshot.items():
|
|
27
|
+
# Iterate through each function associated with the current instrument
|
|
28
|
+
for function_key, function_data in instrument_data.items():
|
|
29
|
+
# Convert the function signature to a string representation
|
|
30
|
+
function_data['signature'] = str(function_data['signature'])
|
|
31
|
+
class_name = instrument_key.split('.')[-1] # Extracting the class name from the path
|
|
32
|
+
class_definitions[class_name.capitalize()] = create_function(request.url_root, class_name, instrument_data)
|
|
33
|
+
# Export the generated class definitions to a .py script
|
|
34
|
+
export_to_python(class_definitions, current_app.config["OUTPUT_FOLDER"])
|
|
35
|
+
filepath = os.path.join(current_app.config["OUTPUT_FOLDER"], "generated_proxy.py")
|
|
36
|
+
return send_file(os.path.abspath(filepath), as_attachment=True)
|