vsview-remote 0.2.0__tar.gz → 0.4.0__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.
- {vsview_remote-0.2.0 → vsview_remote-0.4.0}/.gitignore +1 -0
- {vsview_remote-0.2.0 → vsview_remote-0.4.0}/PKG-INFO +1 -1
- vsview_remote-0.4.0/src/vsview_remote/_secrets.py +49 -0
- {vsview_remote-0.2.0 → vsview_remote-0.4.0}/src/vsview_remote/dialog.py +185 -33
- vsview_remote-0.4.0/src/vsview_remote/exceptions.py +1 -0
- {vsview_remote-0.2.0 → vsview_remote-0.4.0}/src/vsview_remote/settings.py +21 -3
- vsview_remote-0.4.0/src/vsview_remote/workspace.py +312 -0
- vsview_remote-0.2.0/src/vsview_remote/workspace.py +0 -192
- {vsview_remote-0.2.0 → vsview_remote-0.4.0}/LICENSE +0 -0
- {vsview_remote-0.2.0 → vsview_remote-0.4.0}/README.md +0 -0
- {vsview_remote-0.2.0 → vsview_remote-0.4.0}/pyproject.toml +0 -0
- {vsview_remote-0.2.0 → vsview_remote-0.4.0}/src/vsview_remote/__init__.py +0 -0
- {vsview_remote-0.2.0 → vsview_remote-0.4.0}/src/vsview_remote/_metadata.py +0 -0
- {vsview_remote-0.2.0 → vsview_remote-0.4.0}/src/vsview_remote/py.typed +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: vsview-remote
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4.0
|
|
4
4
|
Summary: A VSView plugin that provides remote execution for VapourSynth, leveraging the vsremote library.
|
|
5
5
|
Project-URL: Documentation, https://jaded-encoding-thaumaturgy.github.io/vs-view/usage/workspaces/remote/
|
|
6
6
|
Project-URL: Source Code, https://github.com/Jaded-Encoding-Thaumaturgy/vs-view/tree/main/src/workspaces/remote/
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from collections.abc import Callable
|
|
4
|
+
from logging import getLogger
|
|
5
|
+
|
|
6
|
+
from vsview.api import PluginSecrets, SecretsError
|
|
7
|
+
|
|
8
|
+
logger = getLogger(__name__)
|
|
9
|
+
|
|
10
|
+
READ_ERROR_MESSAGE = "Could not read the saved secrets from the keyring. New values are kept for this session only."
|
|
11
|
+
WRITE_ERROR_MESSAGE = "Could not save the secrets to the keyring. They are kept for this session only."
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class SessionSecrets:
|
|
15
|
+
def __init__(self, secrets: PluginSecrets, on_error: Callable[[str], object]) -> None:
|
|
16
|
+
self._secrets = secrets
|
|
17
|
+
self._on_error = on_error
|
|
18
|
+
self._session = dict[tuple[str, str], str | None]()
|
|
19
|
+
self._unreadable = set[tuple[str, str]]()
|
|
20
|
+
|
|
21
|
+
def get(self, context: str, key: str) -> str | None:
|
|
22
|
+
if (context, key) in self._session:
|
|
23
|
+
return self._session[(context, key)]
|
|
24
|
+
|
|
25
|
+
try:
|
|
26
|
+
return self._secrets.get(context, key)
|
|
27
|
+
except SecretsError:
|
|
28
|
+
logger.warning("Could not read the %s/%s secret from the keyring", context, key, exc_info=True)
|
|
29
|
+
self._unreadable.add((context, key))
|
|
30
|
+
self._on_error(READ_ERROR_MESSAGE)
|
|
31
|
+
return None
|
|
32
|
+
|
|
33
|
+
def set(self, context: str, key: str, value: str | None) -> None:
|
|
34
|
+
# The field of an unreadable secret starts empty, so saving it could erase the stored secret.
|
|
35
|
+
if (context, key) in self._unreadable:
|
|
36
|
+
self._session[(context, key)] = value
|
|
37
|
+
return
|
|
38
|
+
|
|
39
|
+
try:
|
|
40
|
+
if value:
|
|
41
|
+
self._secrets.set(context, key, value)
|
|
42
|
+
else:
|
|
43
|
+
self._secrets.delete(context, key)
|
|
44
|
+
except SecretsError:
|
|
45
|
+
logger.warning("Could not save the %s/%s secret to the keyring", context, key, exc_info=True)
|
|
46
|
+
self._session[(context, key)] = value
|
|
47
|
+
self._on_error(WRITE_ERROR_MESSAGE)
|
|
48
|
+
else:
|
|
49
|
+
self._session.pop((context, key), None)
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
3
|
import logging
|
|
4
|
+
from ipaddress import ip_address
|
|
4
5
|
from typing import Any, Literal, NamedTuple, cast, override
|
|
5
6
|
|
|
6
7
|
from PySide6.QtCore import Qt, Slot
|
|
@@ -14,6 +15,7 @@ from PySide6.QtWidgets import (
|
|
|
14
15
|
QHBoxLayout,
|
|
15
16
|
QLabel,
|
|
16
17
|
QLineEdit,
|
|
18
|
+
QMessageBox,
|
|
17
19
|
QPushButton,
|
|
18
20
|
QSpinBox,
|
|
19
21
|
QVBoxLayout,
|
|
@@ -21,17 +23,19 @@ from PySide6.QtWidgets import (
|
|
|
21
23
|
)
|
|
22
24
|
from vsengine import UnifiedFuture
|
|
23
25
|
from vsremote import RemoteAuthenticationError, RemoteClient, RemoteTimeoutError, TransportError, VSRemoteError
|
|
26
|
+
from vsremote.protocol import validate_curve_key
|
|
24
27
|
|
|
25
|
-
from vsview.api import CustomSpinBox,
|
|
28
|
+
from vsview.api import CustomSpinBox, PluginSettings, run_in_background
|
|
26
29
|
|
|
27
30
|
from ._metadata import AUTH_CONTEXT, AUTH_KEY, CURVE_CONTEXT, CURVE_KEY
|
|
31
|
+
from ._secrets import SessionSecrets
|
|
28
32
|
from .settings import GlobalSettings
|
|
29
33
|
|
|
30
34
|
logger = logging.getLogger(__name__)
|
|
31
35
|
|
|
32
36
|
|
|
33
37
|
class RemoteConnectionDialog(QDialog):
|
|
34
|
-
def __init__(self, parent: QWidget, settings: PluginSettings[GlobalSettings], secrets:
|
|
38
|
+
def __init__(self, parent: QWidget, settings: PluginSettings[GlobalSettings], secrets: SessionSecrets) -> None:
|
|
35
39
|
super().__init__(parent)
|
|
36
40
|
|
|
37
41
|
self.setWindowTitle("VSRemote Connection")
|
|
@@ -41,6 +45,9 @@ class RemoteConnectionDialog(QDialog):
|
|
|
41
45
|
self.settings = settings
|
|
42
46
|
self.secrets = secrets
|
|
43
47
|
self._ping_worker: UnifiedFuture[None] | None = None
|
|
48
|
+
self._insecure_address_confirmed: str | None = None
|
|
49
|
+
self._secrets_ready = True
|
|
50
|
+
self._secrets_generation = 0
|
|
44
51
|
|
|
45
52
|
main_layout = QVBoxLayout(self)
|
|
46
53
|
main_layout.setSpacing(8)
|
|
@@ -74,7 +81,10 @@ class RemoteConnectionDialog(QDialog):
|
|
|
74
81
|
|
|
75
82
|
self.frame_timeout_spin = CustomSpinBox(form_frame, min_text="Default", custom_suffix=" s")
|
|
76
83
|
self.frame_timeout_spin.setRange(0, 120)
|
|
77
|
-
self.frame_timeout_spin.setToolTip(
|
|
84
|
+
self.frame_timeout_spin.setToolTip(
|
|
85
|
+
"Maximum seconds to wait for a frame before timing out " # no format
|
|
86
|
+
"(0 or Default to use the client timeout of 30 s)"
|
|
87
|
+
)
|
|
78
88
|
|
|
79
89
|
self.forward_logs_cb = QCheckBox(form_frame)
|
|
80
90
|
self.subscribe_streams_cb = QCheckBox(form_frame)
|
|
@@ -108,8 +118,6 @@ class RemoteConnectionDialog(QDialog):
|
|
|
108
118
|
self.curve_secret_key_edit = QLineEdit(form_frame2, echoMode=QLineEdit.EchoMode.PasswordEchoOnEdit)
|
|
109
119
|
self.curve_secret_key_edit.setPlaceholderText("Client secret key (optional)")
|
|
110
120
|
|
|
111
|
-
self.refresh_from_settings()
|
|
112
|
-
|
|
113
121
|
form_layout2.addRow("Enable CurveZMQ end-to-end encryption", self.use_curve_cb)
|
|
114
122
|
form_layout2.addRow("Server key", self.curve_server_key_edit)
|
|
115
123
|
form_layout2.addRow("Client public key", self.curve_public_key_edit)
|
|
@@ -143,19 +151,16 @@ class RemoteConnectionDialog(QDialog):
|
|
|
143
151
|
def refresh_from_settings(self) -> None:
|
|
144
152
|
sett = self.settings.global_
|
|
145
153
|
self.address_edit.setText(sett.address)
|
|
146
|
-
self.token_edit.setText(self.auth_token or "")
|
|
147
154
|
self.compression_combo.setCurrentText(sett.compression)
|
|
148
155
|
self.prefetch_spin.setValue(sett.prefetch)
|
|
149
156
|
self.backlog_spin.setValue(sett.backlog or 0)
|
|
150
157
|
self.frame_timeout_spin.setValue(int(sett.frame_timeout) if sett.frame_timeout is not None else 0)
|
|
151
158
|
self.forward_logs_cb.setChecked(sett.forward_logs)
|
|
152
159
|
self.subscribe_streams_cb.setChecked(sett.subscribe_streams)
|
|
153
|
-
|
|
154
|
-
self.use_curve_cb.setChecked(use_curve)
|
|
160
|
+
self.use_curve_cb.setChecked(sett.use_curve)
|
|
155
161
|
self.curve_server_key_edit.setText(sett.curve_server_key or "")
|
|
156
162
|
self.curve_public_key_edit.setText(sett.curve_public_key or "")
|
|
157
|
-
self.
|
|
158
|
-
self._on_curve_toggled(use_curve)
|
|
163
|
+
self._on_curve_toggled(sett.use_curve)
|
|
159
164
|
|
|
160
165
|
@property
|
|
161
166
|
def config(self) -> ConnectionConfig:
|
|
@@ -167,15 +172,20 @@ class RemoteConnectionDialog(QDialog):
|
|
|
167
172
|
backlog=self.backlog_spin.value() or None,
|
|
168
173
|
forward_logs=self.forward_logs_cb.isChecked(),
|
|
169
174
|
subscribe_streams=self.subscribe_streams_cb.isChecked(),
|
|
170
|
-
use_curve=
|
|
171
|
-
curve_server_key=self.curve_server_key_edit.text().strip() or None
|
|
172
|
-
curve_public_key=self.curve_public_key_edit.text().strip() or None
|
|
173
|
-
curve_secret_key=self.curve_secret_key_edit.text().strip() or None
|
|
175
|
+
use_curve=self.use_curve_cb.isChecked(),
|
|
176
|
+
curve_server_key=self.curve_server_key_edit.text().strip() or None,
|
|
177
|
+
curve_public_key=self.curve_public_key_edit.text().strip() or None,
|
|
178
|
+
curve_secret_key=self.curve_secret_key_edit.text().strip() or None,
|
|
174
179
|
frame_timeout=v if (v := self.frame_timeout_spin.value()) > 0 else None,
|
|
175
|
-
hwm=self.settings.global_.hwm
|
|
180
|
+
hwm=self.settings.global_.hwm,
|
|
176
181
|
tcp_keepalive=self.settings.global_.tcp_keepalive,
|
|
177
182
|
)
|
|
178
183
|
|
|
184
|
+
@property
|
|
185
|
+
def secrets_ready(self) -> bool:
|
|
186
|
+
"""Whether the saved auth token and client secret key have been read into the dialog."""
|
|
187
|
+
return self._secrets_ready
|
|
188
|
+
|
|
179
189
|
@property
|
|
180
190
|
def auth_token(self) -> str | None:
|
|
181
191
|
return self.secrets.get(AUTH_CONTEXT, AUTH_KEY)
|
|
@@ -184,10 +194,26 @@ class RemoteConnectionDialog(QDialog):
|
|
|
184
194
|
def curve_secret_key(self) -> str | None:
|
|
185
195
|
return self.secrets.get(CURVE_CONTEXT, CURVE_KEY)
|
|
186
196
|
|
|
197
|
+
@override
|
|
198
|
+
def accept(self) -> None:
|
|
199
|
+
if not self._secrets_ready:
|
|
200
|
+
return
|
|
201
|
+
|
|
202
|
+
cfg = self.config
|
|
203
|
+
|
|
204
|
+
if (problem := cfg.validate()) is not None:
|
|
205
|
+
self.set_status(problem, "#e74c3c")
|
|
206
|
+
return
|
|
207
|
+
|
|
208
|
+
if self._confirm_insecure_connection(cfg):
|
|
209
|
+
super().accept()
|
|
210
|
+
|
|
187
211
|
@override
|
|
188
212
|
def exec(self) -> int:
|
|
189
|
-
self.
|
|
213
|
+
self._insecure_address_confirmed = None
|
|
190
214
|
self.set_status()
|
|
215
|
+
self.refresh_from_settings()
|
|
216
|
+
self._load_secrets()
|
|
191
217
|
res = super().exec()
|
|
192
218
|
if self._ping_worker:
|
|
193
219
|
logger.debug("Cancelling ping task")
|
|
@@ -202,23 +228,81 @@ class RemoteConnectionDialog(QDialog):
|
|
|
202
228
|
self.status_label.setStyleSheet(style)
|
|
203
229
|
self.status_label.setText(text)
|
|
204
230
|
|
|
231
|
+
def _confirm_insecure_connection(self, cfg: ConnectionConfig) -> bool:
|
|
232
|
+
if cfg.active_curve_keys[0] is not None or is_local_address(cfg.address):
|
|
233
|
+
return True
|
|
234
|
+
if cfg.address == self._insecure_address_confirmed:
|
|
235
|
+
return True
|
|
236
|
+
|
|
237
|
+
box = QMessageBox(
|
|
238
|
+
QMessageBox.Icon.Warning,
|
|
239
|
+
"Unencrypted Connection",
|
|
240
|
+
f"CurveZMQ encryption is off for {cfg.address}. "
|
|
241
|
+
"Traffic, including your auth token, will be sent in plain text.\n\n"
|
|
242
|
+
"Continue anyway?",
|
|
243
|
+
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No,
|
|
244
|
+
self,
|
|
245
|
+
textFormat=Qt.TextFormat.PlainText,
|
|
246
|
+
)
|
|
247
|
+
box.setDefaultButton(QMessageBox.StandardButton.No)
|
|
248
|
+
|
|
249
|
+
if box.exec() != QMessageBox.StandardButton.Yes:
|
|
250
|
+
self.set_status("Not connected. Turn on CurveZMQ or use a local address.", "#e74c3c")
|
|
251
|
+
return False
|
|
252
|
+
|
|
253
|
+
self._insecure_address_confirmed = cfg.address
|
|
254
|
+
return True
|
|
255
|
+
|
|
256
|
+
def _load_secrets(self) -> None:
|
|
257
|
+
self._secrets_generation += 1
|
|
258
|
+
self.token_edit.clear()
|
|
259
|
+
self.curve_secret_key_edit.clear()
|
|
260
|
+
self._set_secrets_ready(False)
|
|
261
|
+
|
|
262
|
+
def on_secrets_read(secrets: tuple[str | None, str | None], generation: int) -> None:
|
|
263
|
+
if generation != self._secrets_generation:
|
|
264
|
+
return
|
|
265
|
+
auth_token, curve_secret_key = secrets
|
|
266
|
+
self.token_edit.setText(auth_token or "")
|
|
267
|
+
self.curve_secret_key_edit.setText(curve_secret_key or "")
|
|
268
|
+
self._set_secrets_ready(True)
|
|
269
|
+
|
|
270
|
+
self._read_secrets().map(lambda secrets: on_secrets_read(secrets, self._secrets_generation), on_loop=True)
|
|
271
|
+
|
|
272
|
+
def _set_secrets_ready(self, ready: bool) -> None:
|
|
273
|
+
self._secrets_ready = ready
|
|
274
|
+
self.token_edit.setEnabled(ready)
|
|
275
|
+
self.curve_secret_key_edit.setEnabled(ready and self.use_curve_cb.isChecked())
|
|
276
|
+
self.button_box.button(QDialogButtonBox.StandardButton.Ok).setEnabled(ready)
|
|
277
|
+
self.test_btn.setEnabled(ready)
|
|
278
|
+
|
|
279
|
+
@run_in_background(name="ReadRemoteSecrets")
|
|
280
|
+
def _read_secrets(self) -> tuple[str | None, str | None]:
|
|
281
|
+
return self.auth_token, self.curve_secret_key
|
|
282
|
+
|
|
205
283
|
@Slot(bool)
|
|
206
284
|
def _on_curve_toggled(self, checked: bool) -> None:
|
|
207
285
|
self.curve_server_key_edit.setEnabled(checked)
|
|
208
286
|
self.curve_public_key_edit.setEnabled(checked)
|
|
209
|
-
self.curve_secret_key_edit.setEnabled(checked)
|
|
287
|
+
self.curve_secret_key_edit.setEnabled(checked and self._secrets_ready)
|
|
210
288
|
|
|
211
289
|
@Slot()
|
|
212
290
|
def _on_test_connection_clicked(self) -> None:
|
|
291
|
+
cfg = self.config
|
|
292
|
+
|
|
293
|
+
if (problem := cfg.validate()) is not None:
|
|
294
|
+
self.set_status(problem, "#e74c3c")
|
|
295
|
+
return
|
|
296
|
+
|
|
297
|
+
if not self._confirm_insecure_connection(cfg):
|
|
298
|
+
return
|
|
299
|
+
|
|
213
300
|
self.set_status("Connecting...")
|
|
214
301
|
self.test_btn.setDisabled(True)
|
|
215
302
|
self.button_box.button(QDialogButtonBox.StandardButton.Ok).setDisabled(True)
|
|
216
303
|
|
|
217
|
-
def on_success(
|
|
218
|
-
|
|
219
|
-
self.set_status("Connected successfully!", "#2ecc71", bold=True)
|
|
220
|
-
else:
|
|
221
|
-
self.set_status("Server did not respond to ping.", "#e74c3c")
|
|
304
|
+
def on_success(_: None) -> None:
|
|
305
|
+
self.set_status("Connected successfully!", "#2ecc71", bold=True)
|
|
222
306
|
|
|
223
307
|
def on_error(e: BaseException) -> None:
|
|
224
308
|
match e:
|
|
@@ -234,33 +318,32 @@ class RemoteConnectionDialog(QDialog):
|
|
|
234
318
|
self.set_status(f"Connection failed: {e}", "#e74c3c")
|
|
235
319
|
|
|
236
320
|
def restore_state(*_: Any) -> None:
|
|
237
|
-
self.test_btn.setEnabled(
|
|
238
|
-
self.button_box.button(QDialogButtonBox.StandardButton.Ok).setEnabled(
|
|
321
|
+
self.test_btn.setEnabled(self._secrets_ready)
|
|
322
|
+
self.button_box.button(QDialogButtonBox.StandardButton.Ok).setEnabled(self._secrets_ready)
|
|
239
323
|
self._ping_worker = None
|
|
240
324
|
|
|
241
|
-
cfg = self.config
|
|
242
|
-
|
|
243
325
|
self._ping_worker = (
|
|
244
|
-
self.
|
|
326
|
+
self.check_connection(cfg)
|
|
245
327
|
.then(on_success, on_error, cancel_cb=restore_state, on_loop=True)
|
|
246
328
|
.add_loop_callback(restore_state)
|
|
247
329
|
)
|
|
248
330
|
|
|
249
331
|
@run_in_background(name="PingServer")
|
|
250
|
-
def
|
|
332
|
+
def check_connection(self, cfg: ConnectionConfig) -> None:
|
|
333
|
+
curve_server_key, curve_public_key, curve_secret_key = cfg.active_curve_keys
|
|
251
334
|
with RemoteClient(
|
|
252
335
|
cfg.address,
|
|
253
336
|
compression=cfg.compression,
|
|
254
337
|
auth_token=cfg.auth_token,
|
|
255
|
-
curve_server_key=
|
|
256
|
-
curve_public_key=
|
|
257
|
-
curve_secret_key=
|
|
338
|
+
curve_server_key=curve_server_key,
|
|
339
|
+
curve_public_key=curve_public_key,
|
|
340
|
+
curve_secret_key=curve_secret_key,
|
|
258
341
|
subscribe_streams=False,
|
|
259
342
|
forward_logs=False,
|
|
260
|
-
hwm=cfg.
|
|
343
|
+
hwm=cfg.effective_hwm,
|
|
261
344
|
tcp_keepalive=cfg.tcp_keepalive,
|
|
262
345
|
) as client:
|
|
263
|
-
|
|
346
|
+
client.get_stats().result(timeout=5.0)
|
|
264
347
|
|
|
265
348
|
|
|
266
349
|
class ConnectionConfig(NamedTuple):
|
|
@@ -278,3 +361,72 @@ class ConnectionConfig(NamedTuple):
|
|
|
278
361
|
frame_timeout: float | None = None
|
|
279
362
|
hwm: int | None = None
|
|
280
363
|
tcp_keepalive: bool = True
|
|
364
|
+
|
|
365
|
+
@property
|
|
366
|
+
def effective_hwm(self) -> int:
|
|
367
|
+
"""The ZeroMQ high water mark to connect with: the set value, or twice the frame backlog when it is Auto."""
|
|
368
|
+
if self.hwm is not None:
|
|
369
|
+
return self.hwm
|
|
370
|
+
backlog = self.prefetch * 3 if self.backlog is None else max(self.backlog, self.prefetch)
|
|
371
|
+
return max(backlog * 2, 16)
|
|
372
|
+
|
|
373
|
+
@property
|
|
374
|
+
def active_curve_keys(self) -> tuple[str | None, str | None, str | None]:
|
|
375
|
+
"""The server, public and secret CurveZMQ keys to connect with: all None when CurveZMQ is disabled."""
|
|
376
|
+
if not self.use_curve:
|
|
377
|
+
return None, None, None
|
|
378
|
+
return self.curve_server_key, self.curve_public_key, self.curve_secret_key
|
|
379
|
+
|
|
380
|
+
def validate(self) -> str | None:
|
|
381
|
+
"""
|
|
382
|
+
Check the address and the CurveZMQ keys before they are saved.
|
|
383
|
+
Returns the problem, or None.
|
|
384
|
+
"""
|
|
385
|
+
scheme, sep, rest = self.address.partition("://")
|
|
386
|
+
if not sep or not scheme:
|
|
387
|
+
return "Enter a ZeroMQ address with a scheme, for example tcp://127.0.0.1:5555."
|
|
388
|
+
|
|
389
|
+
if scheme == "tcp":
|
|
390
|
+
# The part before ";" is an optional local source address; only the destination is checked.
|
|
391
|
+
destination = rest.rpartition(";")[2]
|
|
392
|
+
host, colon, port = destination.rpartition(":")
|
|
393
|
+
if not destination or (colon and not host):
|
|
394
|
+
return "The tcp address needs a host, for example tcp://127.0.0.1:5555."
|
|
395
|
+
if not colon or not port.isdigit() or not 1 <= int(port) <= 65535:
|
|
396
|
+
return "The tcp address needs a port from 1 to 65535, for example tcp://127.0.0.1:5555."
|
|
397
|
+
|
|
398
|
+
server_key, public_key, secret_key = self.active_curve_keys
|
|
399
|
+
for label, name, key in (
|
|
400
|
+
("Server key", "curve_server_key", server_key),
|
|
401
|
+
("Client public key", "curve_public_key", public_key),
|
|
402
|
+
("Client secret key", "curve_secret_key", secret_key),
|
|
403
|
+
):
|
|
404
|
+
try:
|
|
405
|
+
validate_curve_key(key, name)
|
|
406
|
+
except ValueError as e:
|
|
407
|
+
return f"{label}: {e}"
|
|
408
|
+
|
|
409
|
+
if (public_key is None) != (secret_key is None):
|
|
410
|
+
return "Set both the client public key and the client secret key, or neither."
|
|
411
|
+
if public_key is not None and server_key is None:
|
|
412
|
+
return "The client keys need the server key."
|
|
413
|
+
|
|
414
|
+
return None
|
|
415
|
+
|
|
416
|
+
|
|
417
|
+
def is_local_address(address: str) -> bool:
|
|
418
|
+
scheme, sep, rest = address.partition("://")
|
|
419
|
+
if not sep:
|
|
420
|
+
return False
|
|
421
|
+
if scheme in ("ipc", "inproc"):
|
|
422
|
+
return True
|
|
423
|
+
if scheme != "tcp":
|
|
424
|
+
return False
|
|
425
|
+
|
|
426
|
+
host = rest.rpartition(";")[2].rpartition(":")[0].removeprefix("[").removesuffix("]")
|
|
427
|
+
if host.lower() == "localhost":
|
|
428
|
+
return True
|
|
429
|
+
try:
|
|
430
|
+
return ip_address(host).is_loopback
|
|
431
|
+
except ValueError:
|
|
432
|
+
return False
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
class ConnectionNotConfiguredError(RuntimeError): ...
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
-
from typing import Annotated, Literal
|
|
3
|
+
from typing import Annotated, Any, Literal
|
|
4
4
|
|
|
5
|
-
from pydantic import BaseModel
|
|
5
|
+
from pydantic import BaseModel, field_validator
|
|
6
6
|
|
|
7
7
|
from vsview.api import Checkbox, Dropdown, LineEdit, SecretLineEdit, Spin
|
|
8
8
|
|
|
@@ -60,12 +60,25 @@ class GlobalSettings(BaseModel):
|
|
|
60
60
|
suffix=" s",
|
|
61
61
|
tooltip=(
|
|
62
62
|
"Maximum seconds to wait for remote frame rendering before timing out "
|
|
63
|
-
"(0 or Default to use
|
|
63
|
+
"(0 or Default to use the client timeout of 30 s)"
|
|
64
64
|
),
|
|
65
65
|
to_ui=lambda v: 0 if v is None else v,
|
|
66
66
|
from_ui=lambda v: None if v == 0 else v,
|
|
67
67
|
),
|
|
68
68
|
] = None
|
|
69
|
+
load_timeout: Annotated[
|
|
70
|
+
int | None,
|
|
71
|
+
Spin(
|
|
72
|
+
label="Script Load Timeout",
|
|
73
|
+
min=0,
|
|
74
|
+
max=3600,
|
|
75
|
+
suffix=" s",
|
|
76
|
+
tooltip="Maximum seconds to wait for the remote server to run the script (0 or No limit to wait forever)",
|
|
77
|
+
min_text="No limit",
|
|
78
|
+
to_ui=lambda v: 0 if v is None else v,
|
|
79
|
+
from_ui=lambda v: None if v == 0 else v,
|
|
80
|
+
),
|
|
81
|
+
] = None
|
|
69
82
|
hwm: Annotated[
|
|
70
83
|
int | None,
|
|
71
84
|
Spin(
|
|
@@ -129,3 +142,8 @@ class GlobalSettings(BaseModel):
|
|
|
129
142
|
tooltip="Client secret key for CurveZMQ encryption",
|
|
130
143
|
),
|
|
131
144
|
] = None
|
|
145
|
+
|
|
146
|
+
@field_validator("backlog", "hwm", mode="before")
|
|
147
|
+
@classmethod
|
|
148
|
+
def _zero_means_auto(cls, value: Any) -> Any:
|
|
149
|
+
return None if value == 0 else value
|
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import threading
|
|
4
|
+
from collections.abc import Sequence
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
from logging import getLogger
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
from typing import ClassVar, override
|
|
9
|
+
|
|
10
|
+
from PySide6.QtCore import QTimer, Slot
|
|
11
|
+
from PySide6.QtGui import QDropEvent
|
|
12
|
+
from PySide6.QtWidgets import QDialog, QWidget
|
|
13
|
+
from vsremote import (
|
|
14
|
+
RemoteAuthenticationError,
|
|
15
|
+
RemoteClient,
|
|
16
|
+
RemoteError,
|
|
17
|
+
RemoteExecutionError,
|
|
18
|
+
RemotePermissionError,
|
|
19
|
+
TransportError,
|
|
20
|
+
UnsupportedFormatError,
|
|
21
|
+
VSRemoteError,
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
from vsview.api import ActionDefinition, IconName, run_in_loop
|
|
25
|
+
from vsview.api.workspace import PluginWorkspace
|
|
26
|
+
from vsview.app.error import StackFrame, show_error
|
|
27
|
+
from vsview.app.outputs import VideoMetadata
|
|
28
|
+
from vsview.app.workspace import PythonScriptWorkspace
|
|
29
|
+
|
|
30
|
+
from ._metadata import AUTH_CONTEXT, AUTH_KEY, CURVE_CONTEXT, CURVE_KEY, WORKSPACE_ID
|
|
31
|
+
from ._secrets import SessionSecrets
|
|
32
|
+
from .dialog import ConnectionConfig, RemoteConnectionDialog
|
|
33
|
+
from .exceptions import ConnectionNotConfiguredError
|
|
34
|
+
from .settings import GlobalSettings
|
|
35
|
+
|
|
36
|
+
logger = getLogger(__name__)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class RemoteWorkspace(PythonScriptWorkspace, PluginWorkspace[GlobalSettings, None]):
|
|
40
|
+
title = "Remote"
|
|
41
|
+
icon = IconName.MONITOR_UP
|
|
42
|
+
caption = "Open VapourSynth Script (Remote)"
|
|
43
|
+
|
|
44
|
+
content_type = "script"
|
|
45
|
+
|
|
46
|
+
identifier = WORKSPACE_ID
|
|
47
|
+
display_name = "Remote"
|
|
48
|
+
|
|
49
|
+
CONFIGURE_CONNECTION: ClassVar[ActionDefinition] = ActionDefinition(
|
|
50
|
+
"jet_vsview_remote.configure_connection",
|
|
51
|
+
"Configure Remote Connection...",
|
|
52
|
+
default_key="Ctrl+Alt+R",
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
shortcuts = (CONFIGURE_CONNECTION,)
|
|
56
|
+
|
|
57
|
+
def __init__(self, parent: QWidget | None = None) -> None:
|
|
58
|
+
super().__init__(parent)
|
|
59
|
+
self._client: RemoteClient | None = None
|
|
60
|
+
self._client_config: ConnectionConfig | None = None
|
|
61
|
+
self._client_lock = threading.RLock()
|
|
62
|
+
self._config: ConnectionConfig | None = None
|
|
63
|
+
self._output_metadata = dict[int, VideoMetadata]()
|
|
64
|
+
self._session_secrets = SessionSecrets(self.secrets, self._on_secrets_error)
|
|
65
|
+
self.dialog = RemoteConnectionDialog(self, self.settings, self._session_secrets)
|
|
66
|
+
|
|
67
|
+
self.api.register_shortcut(self.CONFIGURE_CONNECTION, self._on_configure_connection, self)
|
|
68
|
+
|
|
69
|
+
@property
|
|
70
|
+
def auth_token(self) -> str | None:
|
|
71
|
+
return self._session_secrets.get(AUTH_CONTEXT, AUTH_KEY)
|
|
72
|
+
|
|
73
|
+
@auth_token.setter
|
|
74
|
+
def auth_token(self, value: str | None) -> None:
|
|
75
|
+
self._session_secrets.set(AUTH_CONTEXT, AUTH_KEY, value)
|
|
76
|
+
|
|
77
|
+
@property
|
|
78
|
+
def curve_secret_key(self) -> str | None:
|
|
79
|
+
return self._session_secrets.get(CURVE_CONTEXT, CURVE_KEY)
|
|
80
|
+
|
|
81
|
+
@curve_secret_key.setter
|
|
82
|
+
def curve_secret_key(self, value: str | None) -> None:
|
|
83
|
+
self._session_secrets.set(CURVE_CONTEXT, CURVE_KEY, value)
|
|
84
|
+
|
|
85
|
+
@property
|
|
86
|
+
def client(self) -> RemoteClient:
|
|
87
|
+
with self._client_lock:
|
|
88
|
+
if (config := self._config) is None:
|
|
89
|
+
raise RuntimeError("This shouldn't happen")
|
|
90
|
+
|
|
91
|
+
if self._client and not self._client.is_running:
|
|
92
|
+
logger.warning("Remote client transport is not running; resetting client.")
|
|
93
|
+
self._discard_client()
|
|
94
|
+
elif self._client and self._client_config != config:
|
|
95
|
+
self._discard_client()
|
|
96
|
+
|
|
97
|
+
if self._client:
|
|
98
|
+
return self._client
|
|
99
|
+
|
|
100
|
+
logger.info("Connecting to vsremote server at %s...", config.address)
|
|
101
|
+
curve_server_key, curve_public_key, curve_secret_key = config.active_curve_keys
|
|
102
|
+
self._client = RemoteClient(
|
|
103
|
+
config.address,
|
|
104
|
+
compression=config.compression,
|
|
105
|
+
auth_token=config.auth_token,
|
|
106
|
+
curve_server_key=curve_server_key,
|
|
107
|
+
curve_public_key=curve_public_key,
|
|
108
|
+
curve_secret_key=curve_secret_key,
|
|
109
|
+
forward_logs=config.forward_logs,
|
|
110
|
+
subscribe_streams=config.subscribe_streams,
|
|
111
|
+
replay_history=False,
|
|
112
|
+
hwm=config.effective_hwm,
|
|
113
|
+
tcp_keepalive=config.tcp_keepalive,
|
|
114
|
+
)
|
|
115
|
+
self._client_config = config
|
|
116
|
+
return self._client.start()
|
|
117
|
+
|
|
118
|
+
@override
|
|
119
|
+
def dropEvent(self, event: QDropEvent) -> None:
|
|
120
|
+
if self._config is not None or (dropped_file := self._get_supported_drop_file(event)) is None:
|
|
121
|
+
super().dropEvent(event)
|
|
122
|
+
return
|
|
123
|
+
|
|
124
|
+
event.acceptProposedAction()
|
|
125
|
+
QTimer.singleShot(0, self, lambda: self._connect_and_load(dropped_file))
|
|
126
|
+
|
|
127
|
+
@override
|
|
128
|
+
def on_teardown_started(self) -> None:
|
|
129
|
+
self._discard_client()
|
|
130
|
+
super().on_teardown_started()
|
|
131
|
+
|
|
132
|
+
@override
|
|
133
|
+
def _release_content(self) -> None:
|
|
134
|
+
self._output_metadata.clear()
|
|
135
|
+
super()._release_content()
|
|
136
|
+
|
|
137
|
+
@override
|
|
138
|
+
def get_output_metadata(self) -> dict[int, VideoMetadata]:
|
|
139
|
+
return self._output_metadata
|
|
140
|
+
|
|
141
|
+
@override
|
|
142
|
+
def loader(self) -> None:
|
|
143
|
+
if not self.content.exists():
|
|
144
|
+
logger.error("File not found: %s", self.content)
|
|
145
|
+
raise FileNotFoundError(f"File not found: {self.content}")
|
|
146
|
+
|
|
147
|
+
try:
|
|
148
|
+
if (config := self._config) is None:
|
|
149
|
+
raise ConnectionNotConfiguredError("Remote connection not configured")
|
|
150
|
+
|
|
151
|
+
code = self.content.read_text(encoding="utf-8")
|
|
152
|
+
client = self.client
|
|
153
|
+
output_items = client.load_code(code, filename=str(self.content)).result(
|
|
154
|
+
timeout=self.settings.global_.load_timeout
|
|
155
|
+
)
|
|
156
|
+
logger.info("Remote script execution completed successfully (%d outputs)", len(output_items))
|
|
157
|
+
|
|
158
|
+
for idx, clip in client.get_outputs(
|
|
159
|
+
config.prefetch,
|
|
160
|
+
config.backlog,
|
|
161
|
+
frame_timeout=config.frame_timeout,
|
|
162
|
+
).items():
|
|
163
|
+
clip.set_output(idx)
|
|
164
|
+
|
|
165
|
+
self._output_metadata = {item.index: VideoMetadata(item.name) for item in output_items if item.name}
|
|
166
|
+
except (RemoteExecutionError, UnsupportedFormatError) as err:
|
|
167
|
+
self.statusLoadingErrored.emit("Script error")
|
|
168
|
+
show_error(
|
|
169
|
+
_strip_local_paths(err, str(self.content)) if isinstance(err, RemoteError) else err,
|
|
170
|
+
self,
|
|
171
|
+
user_script_path=str(self.content),
|
|
172
|
+
header_suffix=" on the remote server",
|
|
173
|
+
)
|
|
174
|
+
err.__traceback__ = None
|
|
175
|
+
raise RuntimeError(err) from None
|
|
176
|
+
except (ConnectionNotConfiguredError, UnicodeDecodeError, VSRemoteError, TimeoutError) as err:
|
|
177
|
+
logger.debug("Full traceback:", exc_info=True)
|
|
178
|
+
self.statusLoadingErrored.emit(_failure_status(err))
|
|
179
|
+
|
|
180
|
+
err.__traceback__ = None
|
|
181
|
+
show_error(
|
|
182
|
+
_strip_local_paths(err, str(self.content)) if isinstance(err, RemoteError) else err,
|
|
183
|
+
self,
|
|
184
|
+
user_script_path=str(self.content),
|
|
185
|
+
phase="loading",
|
|
186
|
+
)
|
|
187
|
+
raise err from None
|
|
188
|
+
except Exception as err:
|
|
189
|
+
logger.exception("Remote Error:")
|
|
190
|
+
err.__traceback__ = None
|
|
191
|
+
raise err from None
|
|
192
|
+
|
|
193
|
+
def prompt_connection_dialog(self) -> ConnectionConfig | None:
|
|
194
|
+
if self.dialog.exec() != QDialog.DialogCode.Accepted:
|
|
195
|
+
return None
|
|
196
|
+
|
|
197
|
+
res = self.dialog.config
|
|
198
|
+
# Persist non-sensitive configuration to global plugin settings
|
|
199
|
+
self.settings.global_.address = res.address
|
|
200
|
+
self.settings.global_.compression = res.compression
|
|
201
|
+
self.settings.global_.prefetch = res.prefetch
|
|
202
|
+
self.settings.global_.backlog = res.backlog
|
|
203
|
+
self.settings.global_.frame_timeout = res.frame_timeout
|
|
204
|
+
self.settings.global_.hwm = res.hwm
|
|
205
|
+
self.settings.global_.tcp_keepalive = res.tcp_keepalive
|
|
206
|
+
self.settings.global_.forward_logs = res.forward_logs
|
|
207
|
+
self.settings.global_.subscribe_streams = res.subscribe_streams
|
|
208
|
+
self.settings.global_.use_curve = res.use_curve
|
|
209
|
+
self.settings.global_.curve_server_key = res.curve_server_key
|
|
210
|
+
self.settings.global_.curve_public_key = res.curve_public_key
|
|
211
|
+
# Persist sensitive secrets
|
|
212
|
+
self.auth_token = res.auth_token
|
|
213
|
+
self.curve_secret_key = res.curve_secret_key
|
|
214
|
+
|
|
215
|
+
return res
|
|
216
|
+
|
|
217
|
+
@run_in_loop
|
|
218
|
+
def _on_secrets_error(self, message: str) -> None:
|
|
219
|
+
self.api.statusMessage.emit(message)
|
|
220
|
+
self.dialog.set_status(message, "#e74c3c")
|
|
221
|
+
|
|
222
|
+
def _connect_and_load(self, path: Path) -> None:
|
|
223
|
+
if (config := self.prompt_connection_dialog()) is None:
|
|
224
|
+
return
|
|
225
|
+
|
|
226
|
+
self._config = config
|
|
227
|
+
self.load_content(path)
|
|
228
|
+
|
|
229
|
+
def _discard_client(self) -> None:
|
|
230
|
+
with self._client_lock:
|
|
231
|
+
client, self._client = self._client, None
|
|
232
|
+
|
|
233
|
+
if client is None:
|
|
234
|
+
return
|
|
235
|
+
|
|
236
|
+
# Closes the client in a fire and forget background task so the GUI thread does not wait for it
|
|
237
|
+
threading.Thread(target=client.close, name="CloseRemoteClient", daemon=True).start()
|
|
238
|
+
|
|
239
|
+
@Slot()
|
|
240
|
+
@override
|
|
241
|
+
def _on_open_file_button_clicked(self) -> None:
|
|
242
|
+
if (config := self.prompt_connection_dialog()) is None:
|
|
243
|
+
return
|
|
244
|
+
|
|
245
|
+
self._config = config
|
|
246
|
+
super()._on_open_file_button_clicked()
|
|
247
|
+
|
|
248
|
+
@Slot()
|
|
249
|
+
def _on_configure_connection(self) -> None:
|
|
250
|
+
if (config := self.prompt_connection_dialog()) is None:
|
|
251
|
+
return
|
|
252
|
+
|
|
253
|
+
self._config = config
|
|
254
|
+
if not getattr(self, "content", None):
|
|
255
|
+
return
|
|
256
|
+
|
|
257
|
+
if self.stack.currentWidget() is self.error_page:
|
|
258
|
+
self.load_content(self.content)
|
|
259
|
+
else:
|
|
260
|
+
self.reload_content()
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
@dataclass
|
|
264
|
+
class RemoteStackFrame:
|
|
265
|
+
filename: str
|
|
266
|
+
lineno: int | None
|
|
267
|
+
func_name: str | None = None
|
|
268
|
+
code: str | None = None
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
@dataclass
|
|
272
|
+
class RemoteErrorView:
|
|
273
|
+
exc_type: str
|
|
274
|
+
exc_msg: str
|
|
275
|
+
filename: str | None
|
|
276
|
+
lineno: int | None
|
|
277
|
+
code_line: str | None = None
|
|
278
|
+
formatted_traceback: str | None = None
|
|
279
|
+
frames: Sequence[StackFrame] | None = None
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
def _strip_local_paths(err: RemoteError, script_path: str) -> RemoteErrorView:
|
|
283
|
+
def rename(filename: str) -> str:
|
|
284
|
+
return filename if filename == script_path else f"<remote:{filename}>"
|
|
285
|
+
|
|
286
|
+
return RemoteErrorView(
|
|
287
|
+
exc_type=err.exc_type,
|
|
288
|
+
exc_msg=err.exc_msg,
|
|
289
|
+
filename=rename(err.filename) if err.filename is not None else None,
|
|
290
|
+
lineno=err.lineno,
|
|
291
|
+
code_line=err.code_line,
|
|
292
|
+
formatted_traceback=err.formatted_traceback,
|
|
293
|
+
frames=[RemoteStackFrame(rename(f.filename), f.lineno, f.func_name, f.code) for f in err.frames],
|
|
294
|
+
)
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
def _failure_status(err: BaseException) -> str:
|
|
298
|
+
match err:
|
|
299
|
+
case ConnectionNotConfiguredError():
|
|
300
|
+
return "Remote connection not configured"
|
|
301
|
+
case UnicodeDecodeError():
|
|
302
|
+
return "Script is not valid UTF-8"
|
|
303
|
+
case RemoteAuthenticationError():
|
|
304
|
+
return "Authentication failed"
|
|
305
|
+
case RemotePermissionError():
|
|
306
|
+
return "Permission denied by the server"
|
|
307
|
+
case TimeoutError():
|
|
308
|
+
return "Remote server timed out"
|
|
309
|
+
case TransportError():
|
|
310
|
+
return "Connection error"
|
|
311
|
+
case _:
|
|
312
|
+
return "Remote error"
|
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
from logging import getLogger
|
|
4
|
-
from typing import ClassVar, override
|
|
5
|
-
|
|
6
|
-
from PySide6.QtCore import Slot
|
|
7
|
-
from PySide6.QtWidgets import QDialog, QWidget
|
|
8
|
-
from vsremote import RemoteClient, RemoteExecutionError, UnsupportedFormatError
|
|
9
|
-
|
|
10
|
-
from vsview.api import ActionDefinition, IconName
|
|
11
|
-
from vsview.api.workspace import PluginWorkspace
|
|
12
|
-
from vsview.app.error import show_error
|
|
13
|
-
from vsview.app.outputs import VideoMetadata
|
|
14
|
-
from vsview.app.workspace import PythonScriptWorkspace
|
|
15
|
-
|
|
16
|
-
from ._metadata import AUTH_CONTEXT, AUTH_KEY, CURVE_CONTEXT, CURVE_KEY, WORKSPACE_ID
|
|
17
|
-
from .dialog import ConnectionConfig, RemoteConnectionDialog
|
|
18
|
-
from .settings import GlobalSettings
|
|
19
|
-
|
|
20
|
-
logger = getLogger(__name__)
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
class RemoteWorkspace(PythonScriptWorkspace, PluginWorkspace[GlobalSettings, None]):
|
|
24
|
-
title = "Remote"
|
|
25
|
-
icon = IconName.MONITOR_UP
|
|
26
|
-
caption = "Open VapourSynth Script (Remote)"
|
|
27
|
-
|
|
28
|
-
content_type = "script"
|
|
29
|
-
|
|
30
|
-
identifier = WORKSPACE_ID
|
|
31
|
-
display_name = "Remote"
|
|
32
|
-
|
|
33
|
-
CONFIGURE_CONNECTION: ClassVar[ActionDefinition] = ActionDefinition(
|
|
34
|
-
"jet_vsview_remote.configure_connection",
|
|
35
|
-
"Configure Remote Connection...",
|
|
36
|
-
default_key="Ctrl+Alt+R",
|
|
37
|
-
)
|
|
38
|
-
|
|
39
|
-
shortcuts = (CONFIGURE_CONNECTION,)
|
|
40
|
-
|
|
41
|
-
def __init__(self, parent: QWidget | None = None) -> None:
|
|
42
|
-
super().__init__(parent)
|
|
43
|
-
self._client: RemoteClient | None = None
|
|
44
|
-
self._config: ConnectionConfig | None = None
|
|
45
|
-
self._output_metadata = dict[int, VideoMetadata]()
|
|
46
|
-
|
|
47
|
-
self.dialog = RemoteConnectionDialog(self, self.settings, self.secrets)
|
|
48
|
-
|
|
49
|
-
self.api.register_shortcut(self.CONFIGURE_CONNECTION, self._on_configure_connection, self)
|
|
50
|
-
self.api.register_on_destroy(self._output_metadata.clear)
|
|
51
|
-
|
|
52
|
-
@property
|
|
53
|
-
def auth_token(self) -> str | None:
|
|
54
|
-
return self.secrets.get(AUTH_CONTEXT, AUTH_KEY)
|
|
55
|
-
|
|
56
|
-
@auth_token.setter
|
|
57
|
-
def auth_token(self, value: str | None) -> None:
|
|
58
|
-
if value:
|
|
59
|
-
self.secrets.set(AUTH_CONTEXT, AUTH_KEY, value)
|
|
60
|
-
else:
|
|
61
|
-
self.secrets.delete(AUTH_CONTEXT, AUTH_KEY)
|
|
62
|
-
|
|
63
|
-
@property
|
|
64
|
-
def curve_secret_key(self) -> str | None:
|
|
65
|
-
return self.secrets.get(CURVE_CONTEXT, CURVE_KEY)
|
|
66
|
-
|
|
67
|
-
@curve_secret_key.setter
|
|
68
|
-
def curve_secret_key(self, value: str | None) -> None:
|
|
69
|
-
if value:
|
|
70
|
-
self.secrets.set(CURVE_CONTEXT, CURVE_KEY, value)
|
|
71
|
-
else:
|
|
72
|
-
self.secrets.delete(CURVE_CONTEXT, CURVE_KEY)
|
|
73
|
-
|
|
74
|
-
@property
|
|
75
|
-
def client(self) -> RemoteClient:
|
|
76
|
-
if self._config is None:
|
|
77
|
-
raise RuntimeError("This shouldn't happen")
|
|
78
|
-
|
|
79
|
-
if self._client and not self._client.is_running:
|
|
80
|
-
logger.warning("Remote client transport is not running; resetting client.")
|
|
81
|
-
self._client.close()
|
|
82
|
-
self._client = None
|
|
83
|
-
|
|
84
|
-
if self._client:
|
|
85
|
-
return self._client
|
|
86
|
-
|
|
87
|
-
logger.info("Connecting to vsremote server at %s...", self._config.address)
|
|
88
|
-
self._client = RemoteClient(
|
|
89
|
-
self._config.address,
|
|
90
|
-
compression=self._config.compression,
|
|
91
|
-
auth_token=self._config.auth_token,
|
|
92
|
-
curve_server_key=self._config.curve_server_key,
|
|
93
|
-
curve_public_key=self._config.curve_public_key,
|
|
94
|
-
curve_secret_key=self._config.curve_secret_key,
|
|
95
|
-
forward_logs=self._config.forward_logs,
|
|
96
|
-
subscribe_streams=self._config.subscribe_streams,
|
|
97
|
-
replay_history=False,
|
|
98
|
-
hwm=self._config.hwm if self._config.hwm is not None else 64,
|
|
99
|
-
tcp_keepalive=self._config.tcp_keepalive,
|
|
100
|
-
)
|
|
101
|
-
return self._client.start()
|
|
102
|
-
|
|
103
|
-
@override
|
|
104
|
-
def deleteLater(self) -> None:
|
|
105
|
-
if self._client:
|
|
106
|
-
self._client.close()
|
|
107
|
-
self._client = None
|
|
108
|
-
super().deleteLater()
|
|
109
|
-
|
|
110
|
-
@override
|
|
111
|
-
def clear_environment(self) -> None:
|
|
112
|
-
self._output_metadata.clear()
|
|
113
|
-
super().clear_environment()
|
|
114
|
-
|
|
115
|
-
@override
|
|
116
|
-
def get_output_metadata(self) -> dict[int, VideoMetadata]:
|
|
117
|
-
return self._output_metadata
|
|
118
|
-
|
|
119
|
-
@override
|
|
120
|
-
def loader(self) -> None:
|
|
121
|
-
if not self.content.exists():
|
|
122
|
-
logger.error("File not found: %s", self.content)
|
|
123
|
-
raise FileNotFoundError(f"File not found: {self.content}")
|
|
124
|
-
|
|
125
|
-
if self._config is None:
|
|
126
|
-
raise RuntimeError("Remote connection not configured")
|
|
127
|
-
|
|
128
|
-
code = self.content.read_text(encoding="utf-8")
|
|
129
|
-
try:
|
|
130
|
-
output_items = self.client.load_code(code, filename=str(self.content)).result(timeout=30.0)
|
|
131
|
-
logger.info("Remote script execution completed successfully (%d outputs)", len(output_items))
|
|
132
|
-
|
|
133
|
-
for idx, clip in self.client.get_outputs(
|
|
134
|
-
self._config.prefetch,
|
|
135
|
-
self._config.backlog,
|
|
136
|
-
frame_timeout=self._config.frame_timeout,
|
|
137
|
-
).items():
|
|
138
|
-
clip.set_output(idx)
|
|
139
|
-
|
|
140
|
-
self._output_metadata = {item.index: VideoMetadata(item.name) for item in output_items if item.name}
|
|
141
|
-
except (RemoteExecutionError, UnsupportedFormatError) as err:
|
|
142
|
-
self.statusLoadingErrored.emit("Script error")
|
|
143
|
-
show_error(err, self, user_script_path=str(self.content), header_suffix=" on the remote server")
|
|
144
|
-
err.__traceback__ = None
|
|
145
|
-
raise RuntimeError(err) from None
|
|
146
|
-
except Exception as err:
|
|
147
|
-
logger.exception("Remote Error:")
|
|
148
|
-
err.__traceback__ = None
|
|
149
|
-
raise err from None
|
|
150
|
-
|
|
151
|
-
def prompt_connection_dialog(self) -> ConnectionConfig | None:
|
|
152
|
-
if self.dialog.exec() != QDialog.DialogCode.Accepted:
|
|
153
|
-
return None
|
|
154
|
-
|
|
155
|
-
res = self.dialog.config
|
|
156
|
-
# Persist non-sensitive configuration to global plugin settings
|
|
157
|
-
self.settings.global_.address = res.address
|
|
158
|
-
self.settings.global_.compression = res.compression
|
|
159
|
-
self.settings.global_.prefetch = res.prefetch
|
|
160
|
-
self.settings.global_.backlog = res.backlog if res.backlog is not None else max(res.prefetch * 3, 12)
|
|
161
|
-
self.settings.global_.frame_timeout = res.frame_timeout
|
|
162
|
-
self.settings.global_.hwm = res.hwm
|
|
163
|
-
self.settings.global_.tcp_keepalive = res.tcp_keepalive
|
|
164
|
-
self.settings.global_.forward_logs = res.forward_logs
|
|
165
|
-
self.settings.global_.subscribe_streams = res.subscribe_streams
|
|
166
|
-
self.settings.global_.use_curve = res.use_curve
|
|
167
|
-
self.settings.global_.curve_server_key = res.curve_server_key
|
|
168
|
-
self.settings.global_.curve_public_key = res.curve_public_key
|
|
169
|
-
# Persist sensitive secrets
|
|
170
|
-
self.auth_token = res.auth_token
|
|
171
|
-
self.curve_secret_key = res.curve_secret_key
|
|
172
|
-
|
|
173
|
-
return res
|
|
174
|
-
|
|
175
|
-
@Slot()
|
|
176
|
-
@override
|
|
177
|
-
def _on_open_file_button_clicked(self) -> None:
|
|
178
|
-
self._config = self.prompt_connection_dialog()
|
|
179
|
-
if self._config is None:
|
|
180
|
-
return
|
|
181
|
-
|
|
182
|
-
super()._on_open_file_button_clicked()
|
|
183
|
-
|
|
184
|
-
@Slot()
|
|
185
|
-
def _on_configure_connection(self) -> None:
|
|
186
|
-
if (new_config := self.prompt_connection_dialog()) is not None:
|
|
187
|
-
self._config = new_config
|
|
188
|
-
if self._client is not None:
|
|
189
|
-
self._client.close()
|
|
190
|
-
self._client = None
|
|
191
|
-
if hasattr(self, "content") and self.content:
|
|
192
|
-
self.reload_content()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|