plesty-server 0.4.3__tar.gz → 0.4.4__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.
- {plesty_server-0.4.3 → plesty_server-0.4.4}/PKG-INFO +2 -2
- {plesty_server-0.4.3 → plesty_server-0.4.4}/plesty/server/model/job.py +65 -0
- {plesty_server-0.4.3 → plesty_server-0.4.4}/plesty/server/presenter/bench.py +63 -15
- plesty_server-0.4.4/plesty/server/view/app.py +205 -0
- {plesty_server-0.4.3 → plesty_server-0.4.4}/plesty/server/view/window.py +127 -22
- {plesty_server-0.4.3 → plesty_server-0.4.4}/plesty/server/view/workers.py +52 -0
- {plesty_server-0.4.3 → plesty_server-0.4.4}/pyproject.toml +2 -2
- plesty_server-0.4.3/plesty/server/view/app.py +0 -97
- {plesty_server-0.4.3 → plesty_server-0.4.4}/LICENSE +0 -0
- {plesty_server-0.4.3 → plesty_server-0.4.4}/LICENSES/LGPL-3.0-or-later.txt +0 -0
- {plesty_server-0.4.3 → plesty_server-0.4.4}/README.md +0 -0
- {plesty_server-0.4.3 → plesty_server-0.4.4}/plesty/server/__init__.py +0 -0
- {plesty_server-0.4.3 → plesty_server-0.4.4}/plesty/server/__main__.py +0 -0
- {plesty_server-0.4.3 → plesty_server-0.4.4}/plesty/server/assets/console.qss +0 -0
- {plesty_server-0.4.3 → plesty_server-0.4.4}/plesty/server/assets/env.example +0 -0
- {plesty_server-0.4.3 → plesty_server-0.4.4}/plesty/server/assets/fleet.example.yaml +0 -0
- {plesty_server-0.4.3 → plesty_server-0.4.4}/plesty/server/assets/plesty-mark.svg +0 -0
- {plesty_server-0.4.3 → plesty_server-0.4.4}/plesty/server/assets/report.css +0 -0
- {plesty_server-0.4.3 → plesty_server-0.4.4}/plesty/server/assets/report.html +0 -0
- {plesty_server-0.4.3 → plesty_server-0.4.4}/plesty/server/cli/__init__.py +0 -0
- {plesty_server-0.4.3 → plesty_server-0.4.4}/plesty/server/cli/main.py +0 -0
- {plesty_server-0.4.3 → plesty_server-0.4.4}/plesty/server/config.yaml +0 -0
- {plesty_server-0.4.3 → plesty_server-0.4.4}/plesty/server/host.py +0 -0
- {plesty_server-0.4.3 → plesty_server-0.4.4}/plesty/server/model/__init__.py +0 -0
- {plesty_server-0.4.3 → plesty_server-0.4.4}/plesty/server/model/agent.py +0 -0
- {plesty_server-0.4.3 → plesty_server-0.4.4}/plesty/server/model/catalogue.py +0 -0
- {plesty_server-0.4.3 → plesty_server-0.4.4}/plesty/server/model/device.py +0 -0
- {plesty_server-0.4.3 → plesty_server-0.4.4}/plesty/server/model/device_manager.py +0 -0
- {plesty_server-0.4.3 → plesty_server-0.4.4}/plesty/server/model/envfile.py +0 -0
- {plesty_server-0.4.3 → plesty_server-0.4.4}/plesty/server/model/errors.py +0 -0
- {plesty_server-0.4.3 → plesty_server-0.4.4}/plesty/server/model/experiment.py +0 -0
- {plesty_server-0.4.3 → plesty_server-0.4.4}/plesty/server/model/field_test.py +0 -0
- {plesty_server-0.4.3 → plesty_server-0.4.4}/plesty/server/model/fleet.py +0 -0
- {plesty_server-0.4.3 → plesty_server-0.4.4}/plesty/server/model/home.py +0 -0
- {plesty_server-0.4.3 → plesty_server-0.4.4}/plesty/server/model/peer.py +0 -0
- {plesty_server-0.4.3 → plesty_server-0.4.4}/plesty/server/model/ports.py +0 -0
- {plesty_server-0.4.3 → plesty_server-0.4.4}/plesty/server/model/process.py +0 -0
- {plesty_server-0.4.3 → plesty_server-0.4.4}/plesty/server/model/purge.py +0 -0
- {plesty_server-0.4.3 → plesty_server-0.4.4}/plesty/server/model/traffic.py +0 -0
- {plesty_server-0.4.3 → plesty_server-0.4.4}/plesty/server/presenter/__init__.py +0 -0
- {plesty_server-0.4.3 → plesty_server-0.4.4}/plesty/server/reexec.py +0 -0
- {plesty_server-0.4.3 → plesty_server-0.4.4}/plesty/server/services/__init__.py +0 -0
- {plesty_server-0.4.3 → plesty_server-0.4.4}/plesty/server/services/agent.py +0 -0
- {plesty_server-0.4.3 → plesty_server-0.4.4}/plesty/server/services/catalogue.py +0 -0
- {plesty_server-0.4.3 → plesty_server-0.4.4}/plesty/server/services/control.py +0 -0
- {plesty_server-0.4.3 → plesty_server-0.4.4}/plesty/server/services/experiments.py +0 -0
- {plesty_server-0.4.3 → plesty_server-0.4.4}/plesty/server/services/gitbin.py +0 -0
- {plesty_server-0.4.3 → plesty_server-0.4.4}/plesty/server/services/installer.py +0 -0
- {plesty_server-0.4.3 → plesty_server-0.4.4}/plesty/server/services/jobs.py +0 -0
- {plesty_server-0.4.3 → plesty_server-0.4.4}/plesty/server/services/launch.py +0 -0
- {plesty_server-0.4.3 → plesty_server-0.4.4}/plesty/server/services/nodes.py +0 -0
- {plesty_server-0.4.3 → plesty_server-0.4.4}/plesty/server/services/problem_report.py +0 -0
- {plesty_server-0.4.3 → plesty_server-0.4.4}/plesty/server/services/run_report.py +0 -0
- {plesty_server-0.4.3 → plesty_server-0.4.4}/plesty/server/services/supervisor.py +0 -0
- {plesty_server-0.4.3 → plesty_server-0.4.4}/plesty/server/view/__init__.py +0 -0
- {plesty_server-0.4.3 → plesty_server-0.4.4}/plesty/server/view/control.py +0 -0
- {plesty_server-0.4.3 → plesty_server-0.4.4}/plesty/server/view/dialogs.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: plesty-server
|
|
3
|
-
Version: 0.4.
|
|
3
|
+
Version: 0.4.4
|
|
4
4
|
Summary: The PLESTY bench application: installs, runs and field-tests device servers.
|
|
5
5
|
Project-URL: Homepage, https://gitlab.com/plesty/core/plesty-bench
|
|
6
6
|
Project-URL: Documentation, https://plesty.gitlab.io/core/plesty-bench/
|
|
@@ -11,7 +11,7 @@ License-File: LICENSE
|
|
|
11
11
|
License-File: LICENSES/LGPL-3.0-or-later.txt
|
|
12
12
|
Requires-Python: >=3.12
|
|
13
13
|
Requires-Dist: click>=8.1
|
|
14
|
-
Requires-Dist: plesty-bench==0.4.
|
|
14
|
+
Requires-Dist: plesty-bench==0.4.4
|
|
15
15
|
Requires-Dist: plesty-lib[report]>=0.5.2
|
|
16
16
|
Requires-Dist: pyyaml>=6.0
|
|
17
17
|
Requires-Dist: pyzmq>=26
|
|
@@ -32,6 +32,10 @@ from plesty.server.model.home import Home
|
|
|
32
32
|
#: Bytes one :meth:`JobStore.log` call returns at most.
|
|
33
33
|
LOG_CHUNK = 65536
|
|
34
34
|
|
|
35
|
+
#: Bytes a log view opens on, and loads at a time as it is scrolled up: many
|
|
36
|
+
#: screens of lines, and still one quick read and paint.
|
|
37
|
+
LOG_END = 262144
|
|
38
|
+
|
|
35
39
|
#: Exit code recorded when the process vanished without leaving one.
|
|
36
40
|
LOST_EXIT = -1
|
|
37
41
|
|
|
@@ -248,6 +252,53 @@ class JobStore:
|
|
|
248
252
|
data = fh.read(limit)
|
|
249
253
|
return data.decode("utf-8", errors="replace"), offset + len(data)
|
|
250
254
|
|
|
255
|
+
def log_end(self, job_id: str, limit: int = LOG_END) -> tuple[str, int, int]:
|
|
256
|
+
"""The end of the job log: at most its last *limit* bytes, from a line start.
|
|
257
|
+
|
|
258
|
+
What a log view opens on, so a long log is not read and painted from
|
|
259
|
+
its first byte to reach the last (#28).
|
|
260
|
+
|
|
261
|
+
Args:
|
|
262
|
+
job_id: The job.
|
|
263
|
+
limit: Most bytes to return.
|
|
264
|
+
|
|
265
|
+
Returns:
|
|
266
|
+
The text, the byte it starts at (``0`` when it is the whole log),
|
|
267
|
+
and the byte it ends at — where reading on continues.
|
|
268
|
+
"""
|
|
269
|
+
path = Path(self.require(job_id).log)
|
|
270
|
+
if not path.is_file():
|
|
271
|
+
return "", 0, 0
|
|
272
|
+
with path.open("rb") as fh:
|
|
273
|
+
fh.seek(0, os.SEEK_END)
|
|
274
|
+
end = fh.tell()
|
|
275
|
+
start = max(0, end - limit)
|
|
276
|
+
fh.seek(start)
|
|
277
|
+
data = fh.read(end - start)
|
|
278
|
+
start, data = _from_line_start(start, data)
|
|
279
|
+
return data.decode("utf-8", errors="replace"), start, end
|
|
280
|
+
|
|
281
|
+
def log_before(self, job_id: str, end: int, limit: int = LOG_END) -> tuple[str, int]:
|
|
282
|
+
"""The part of the job log before byte *end*: at most *limit* bytes, from a line start.
|
|
283
|
+
|
|
284
|
+
Args:
|
|
285
|
+
job_id: The job.
|
|
286
|
+
end: Where the part already shown begins.
|
|
287
|
+
limit: Most bytes to return.
|
|
288
|
+
|
|
289
|
+
Returns:
|
|
290
|
+
The text and the byte it starts at; ``("", 0)`` at the top.
|
|
291
|
+
"""
|
|
292
|
+
path = Path(self.require(job_id).log)
|
|
293
|
+
if end <= 0 or not path.is_file():
|
|
294
|
+
return "", 0
|
|
295
|
+
start = max(0, end - limit)
|
|
296
|
+
with path.open("rb") as fh:
|
|
297
|
+
fh.seek(start)
|
|
298
|
+
data = fh.read(end - start)
|
|
299
|
+
start, data = _from_line_start(start, data)
|
|
300
|
+
return data.decode("utf-8", errors="replace"), start
|
|
301
|
+
|
|
251
302
|
def tail(self, job_id: str, lines: int = 50) -> str:
|
|
252
303
|
"""The last *lines* lines of the job log (empty when there is none yet)."""
|
|
253
304
|
job = self.require(job_id)
|
|
@@ -279,5 +330,19 @@ def tail_file(path: Path, lines: int, limit: int = TAIL_LIMIT) -> str:
|
|
|
279
330
|
return "\n".join(text.splitlines()[-lines:])
|
|
280
331
|
|
|
281
332
|
|
|
333
|
+
def _from_line_start(start: int, data: bytes) -> tuple[int, bytes]:
|
|
334
|
+
"""Drop the partial line a read from the middle of a file begins with.
|
|
335
|
+
|
|
336
|
+
A read from byte 0 starts on a line already. One whose span holds no line
|
|
337
|
+
break at all is kept whole: a line longer than the span still shows.
|
|
338
|
+
"""
|
|
339
|
+
if start == 0:
|
|
340
|
+
return start, data
|
|
341
|
+
cut = data.find(b"\n") + 1
|
|
342
|
+
if cut == 0:
|
|
343
|
+
return start, data
|
|
344
|
+
return start + cut, data[cut:]
|
|
345
|
+
|
|
346
|
+
|
|
282
347
|
def _now() -> str:
|
|
283
348
|
return datetime.now(UTC).isoformat(timespec="seconds")
|
|
@@ -18,6 +18,7 @@ from __future__ import annotations
|
|
|
18
18
|
|
|
19
19
|
import json
|
|
20
20
|
import os
|
|
21
|
+
import re
|
|
21
22
|
import shutil
|
|
22
23
|
import sys
|
|
23
24
|
import threading
|
|
@@ -195,14 +196,46 @@ def _planned_config(run_dir: Path) -> dict[str, Any] | None:
|
|
|
195
196
|
return planned if isinstance(planned, dict) else None
|
|
196
197
|
|
|
197
198
|
|
|
198
|
-
|
|
199
|
-
|
|
199
|
+
#: The Source of a run that has started but recorded no versions: one written
|
|
200
|
+
#: before runs journaled their provenance. Said as unknown, never filled in
|
|
201
|
+
#: with today's install, which is the one answer certain to be wrong.
|
|
202
|
+
UNKNOWN_SOURCE = "unknown — the run recorded no version"
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
def _run_source(status: dict[str, Any], package: str, installed: str) -> str:
|
|
206
|
+
"""What a run's Source cell says: the version that measured it.
|
|
207
|
+
|
|
208
|
+
Args:
|
|
209
|
+
status: The run's status, with the ``provenance`` its start journaled.
|
|
210
|
+
package: The experiment's distribution.
|
|
211
|
+
installed: The current install's line (:meth:`Bench.experiment_source`).
|
|
212
|
+
|
|
213
|
+
Returns:
|
|
214
|
+
``<package>==<version>`` from the run's own provenance once it has
|
|
215
|
+
started; the current install marked as what it will run on while it
|
|
216
|
+
waits; :data:`UNKNOWN_SOURCE` for a started run that recorded none.
|
|
217
|
+
"""
|
|
218
|
+
if status.get("state") in ("created", "not_started"):
|
|
219
|
+
return f"{installed} (will run on)" if installed else ""
|
|
220
|
+
versions = (status.get("provenance") or {}).get("versions") or {}
|
|
221
|
+
wanted = _canonical(package)
|
|
222
|
+
version = next((v for n, v in versions.items() if _canonical(str(n)) == wanted), None)
|
|
223
|
+
return f"{package}=={version}" if version else UNKNOWN_SOURCE
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
def _canonical(name: str) -> str:
|
|
227
|
+
"""A distribution name as PyPI compares them: case and ``_``/``.``/``-`` alike."""
|
|
228
|
+
return re.sub(r"[-_.]+", "-", name).lower()
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
def _waiting_runs_first(rows: list[dict[str, Any]]) -> list[dict[str, Any]]:
|
|
232
|
+
"""Order runs with the ones not yet started on top, the newest created first.
|
|
200
233
|
|
|
201
234
|
A created run has no start time, so by name alone it lands wherever its
|
|
202
|
-
name happens to sort
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
235
|
+
name happens to sort. Put at the bottom, under every measurement, the run
|
|
236
|
+
just created was out of sight, and creating it read as having failed — an
|
|
237
|
+
operator duplicated a run three times and saw none of them (#31). The run
|
|
238
|
+
just created is the one the next *Run* is meant for, so it leads.
|
|
206
239
|
|
|
207
240
|
Args:
|
|
208
241
|
rows: The runs, newest first by name.
|
|
@@ -212,8 +245,11 @@ def _waiting_runs_last(rows: list[dict[str, Any]]) -> list[dict[str, Any]]:
|
|
|
212
245
|
"""
|
|
213
246
|
started = [row for row in rows if row["status"].get("state") != "created"]
|
|
214
247
|
waiting = [row for row in rows if row["status"].get("state") == "created"]
|
|
215
|
-
waiting.sort(
|
|
216
|
-
|
|
248
|
+
waiting.sort(
|
|
249
|
+
key=lambda row: str((row["status"].get("created") or {}).get("created_at") or ""),
|
|
250
|
+
reverse=True,
|
|
251
|
+
)
|
|
252
|
+
return waiting + started
|
|
217
253
|
|
|
218
254
|
|
|
219
255
|
def control_blocked(status: ProcessStatus) -> str | None:
|
|
@@ -1691,17 +1727,21 @@ class Bench:
|
|
|
1691
1727
|
Returns:
|
|
1692
1728
|
One ``{"name", "status"}`` per run, or a single not-started row.
|
|
1693
1729
|
"""
|
|
1694
|
-
#
|
|
1695
|
-
#
|
|
1730
|
+
# The install is read once per experiment, and it is only what a run
|
|
1731
|
+
# *will* execute: a run measured before an update was made by another
|
|
1732
|
+
# version, which its own provenance records (#32).
|
|
1696
1733
|
source = self.experiment_source(name)
|
|
1697
1734
|
runs = self.experiment_runs(name)
|
|
1698
1735
|
if not runs:
|
|
1699
1736
|
return [{"name": name, "status": self.experiment_status(name), "source": source}]
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1737
|
+
package = self.experiment(name).package
|
|
1738
|
+
rows = []
|
|
1739
|
+
for run in runs:
|
|
1740
|
+
status = self.experiment_status(name, run.name)
|
|
1741
|
+
rows.append(
|
|
1742
|
+
{"name": name, "status": status, "source": _run_source(status, package, source)}
|
|
1743
|
+
)
|
|
1744
|
+
return _waiting_runs_first(rows)
|
|
1705
1745
|
|
|
1706
1746
|
def read_run(self, run_dir: str | Path) -> dict[str, Any]:
|
|
1707
1747
|
"""Read a run directory that is not one of this bench's own.
|
|
@@ -3254,6 +3294,14 @@ class Bench:
|
|
|
3254
3294
|
"""Job log from byte *offset*; returns text and the next offset."""
|
|
3255
3295
|
return self.jobs.store.log(job_id, offset)
|
|
3256
3296
|
|
|
3297
|
+
def job_log_end(self, job_id: str) -> tuple[str, int, int]:
|
|
3298
|
+
"""The end of a job's log: text, the byte it starts at, the byte it ends at."""
|
|
3299
|
+
return self.jobs.store.log_end(job_id)
|
|
3300
|
+
|
|
3301
|
+
def job_log_before(self, job_id: str, end: int) -> tuple[str, int]:
|
|
3302
|
+
"""The part of a job's log before byte *end*: text and the byte it starts at."""
|
|
3303
|
+
return self.jobs.store.log_before(job_id, end)
|
|
3304
|
+
|
|
3257
3305
|
def cancel(self, job_id: str) -> bool:
|
|
3258
3306
|
"""Cancel a running job."""
|
|
3259
3307
|
return self.jobs.cancel(job_id)
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 Yunshuang Yuan
|
|
2
|
+
# SPDX-License-Identifier: LGPL-3.0-or-later
|
|
3
|
+
|
|
4
|
+
"""Open the console: Qt application, plesty-lib theme, our stylesheet, the window."""
|
|
5
|
+
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
import hashlib
|
|
9
|
+
from collections.abc import Callable
|
|
10
|
+
from importlib import metadata, resources
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
|
|
13
|
+
from PySide6.QtCore import QLockFile, Qt
|
|
14
|
+
from PySide6.QtGui import QIcon
|
|
15
|
+
from PySide6.QtNetwork import QLocalServer, QLocalSocket
|
|
16
|
+
from PySide6.QtWidgets import QApplication, QMessageBox
|
|
17
|
+
|
|
18
|
+
from plesty.lib.ui.theme import Theme
|
|
19
|
+
from plesty.server.presenter import Bench
|
|
20
|
+
from plesty.server.view.window import MainWindow
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
#: Preferred UI and monospace families, first available wins (plesty.net's
|
|
24
|
+
#: Inter where installed, else the platform's own face).
|
|
25
|
+
UI_FONTS = ("Inter", "SF Pro Text", "Segoe UI", "Helvetica Neue", "Arial")
|
|
26
|
+
MONO_FONTS = ("SF Mono", "Menlo", "Consolas", "DejaVu Sans Mono", "Courier New")
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def pick_font(candidates: tuple[str, ...], fallback: str) -> str:
|
|
30
|
+
"""The first of *candidates* the host has, else *fallback* — quoted for QSS.
|
|
31
|
+
|
|
32
|
+
Asked rather than listed: Qt warns at start-up for every stylesheet
|
|
33
|
+
family that is missing on the host, and the answer differs per bench.
|
|
34
|
+
"""
|
|
35
|
+
try:
|
|
36
|
+
from PySide6.QtGui import QFontDatabase
|
|
37
|
+
|
|
38
|
+
installed = set(QFontDatabase.families())
|
|
39
|
+
except Exception: # noqa: BLE001 — no QApplication yet, or no font database
|
|
40
|
+
installed = set()
|
|
41
|
+
for name in candidates:
|
|
42
|
+
if name in installed:
|
|
43
|
+
return f'"{name}", {fallback}'
|
|
44
|
+
return fallback
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def stylesheet(theme: Theme | None = None) -> str:
|
|
48
|
+
"""The console stylesheet: ``assets/console.qss`` with the palette and fonts substituted."""
|
|
49
|
+
theme = theme or Theme.load()
|
|
50
|
+
with resources.as_file(
|
|
51
|
+
resources.files("plesty.server").joinpath("assets/console.qss")
|
|
52
|
+
) as path:
|
|
53
|
+
text = theme.stylesheet(path)
|
|
54
|
+
return text.replace("{{ui_font}}", pick_font(UI_FONTS, "sans-serif")).replace(
|
|
55
|
+
"{{mono_font}}", pick_font(MONO_FONTS, "monospace")
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def mark_icon() -> QIcon:
|
|
60
|
+
"""The PLESTY mark (``assets/plesty-mark.svg``, the static version) as a window icon."""
|
|
61
|
+
with resources.as_file(
|
|
62
|
+
resources.files("plesty.server").joinpath("assets/plesty-mark.svg")
|
|
63
|
+
) as path:
|
|
64
|
+
return QIcon(str(path))
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def application() -> QApplication:
|
|
68
|
+
"""The running Qt application, created, themed and branded when there is none."""
|
|
69
|
+
existing = QApplication.instance()
|
|
70
|
+
if isinstance(existing, QApplication):
|
|
71
|
+
return existing
|
|
72
|
+
app = QApplication([])
|
|
73
|
+
app.setApplicationName("plesty-server")
|
|
74
|
+
app.setApplicationDisplayName("PLESTY bench")
|
|
75
|
+
app.setWindowIcon(mark_icon())
|
|
76
|
+
app.setStyleSheet(stylesheet())
|
|
77
|
+
return app
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def build_window(bench: Bench, title: str | None = None) -> MainWindow:
|
|
81
|
+
"""A themed main window on *bench* (the application must exist)."""
|
|
82
|
+
theme = Theme.load()
|
|
83
|
+
window = MainWindow(bench, title or f"PLESTY bench — {bench.home.root}", version=_version())
|
|
84
|
+
window.theme = theme # type: ignore[attr-defined] # read by the state brushes
|
|
85
|
+
window.setWindowIcon(mark_icon())
|
|
86
|
+
bench.remember_fleet()
|
|
87
|
+
return window
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
class ConsoleGuard:
|
|
91
|
+
"""The claim one console holds on its bench home.
|
|
92
|
+
|
|
93
|
+
Two consoles on one home share its jobs, runs and remembered fleet, and
|
|
94
|
+
each acts on a state the other changes underneath it: a second copy,
|
|
95
|
+
started by clicking the shortcut again while the first sat minimised,
|
|
96
|
+
rewrote the remembered fleet and left the run table of both out of date
|
|
97
|
+
(#28). So a home has one console. A lock file says which, and the holder
|
|
98
|
+
listens on a local socket, so a second launch can bring its window
|
|
99
|
+
forward instead of opening another.
|
|
100
|
+
"""
|
|
101
|
+
|
|
102
|
+
def __init__(self, lock: QLockFile, server: QLocalServer) -> None:
|
|
103
|
+
"""Hold *lock* on the home and answer bring-forward requests on *server*."""
|
|
104
|
+
self._lock = lock
|
|
105
|
+
self.server = server
|
|
106
|
+
|
|
107
|
+
def on_raise(self, callback: Callable[[], None]) -> None:
|
|
108
|
+
"""Call *callback* whenever another launch asks this console to come forward."""
|
|
109
|
+
|
|
110
|
+
def _accepted() -> None:
|
|
111
|
+
while self.server.hasPendingConnections():
|
|
112
|
+
connection = self.server.nextPendingConnection()
|
|
113
|
+
connection.disconnected.connect(connection.deleteLater)
|
|
114
|
+
callback()
|
|
115
|
+
|
|
116
|
+
self.server.newConnection.connect(_accepted)
|
|
117
|
+
|
|
118
|
+
def release(self) -> None:
|
|
119
|
+
"""Give the home up: the lock and the socket."""
|
|
120
|
+
self.server.close()
|
|
121
|
+
self._lock.unlock()
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def claim_console(root: Path) -> ConsoleGuard | None:
|
|
125
|
+
"""Become the one console of the bench home at *root*, or wake the one there is.
|
|
126
|
+
|
|
127
|
+
Args:
|
|
128
|
+
root: The bench home.
|
|
129
|
+
|
|
130
|
+
Returns:
|
|
131
|
+
The guard to keep for as long as the console is open, or ``None``
|
|
132
|
+
when another console holds the home.
|
|
133
|
+
"""
|
|
134
|
+
run = root / "run"
|
|
135
|
+
run.mkdir(parents=True, exist_ok=True)
|
|
136
|
+
lock = QLockFile(str(run / "console.lock"))
|
|
137
|
+
# Never stale by age: a console open for a week still holds it. One left
|
|
138
|
+
# by a console that crashed is taken over, since its process is gone.
|
|
139
|
+
lock.setStaleLockTime(0)
|
|
140
|
+
if not lock.tryLock(500):
|
|
141
|
+
return None
|
|
142
|
+
name = _socket_name(root)
|
|
143
|
+
QLocalServer.removeServer(name) # a socket file a crashed console left (POSIX)
|
|
144
|
+
server = QLocalServer()
|
|
145
|
+
server.listen(name) # not listening costs only the bring-forward, never the console
|
|
146
|
+
return ConsoleGuard(lock, server)
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
def _socket_name(root: Path) -> str:
|
|
150
|
+
"""The local socket of *root*'s console: one per home, short enough for every OS."""
|
|
151
|
+
digest = hashlib.sha1(str(root.resolve()).encode("utf-8")).hexdigest()[:16]
|
|
152
|
+
return f"plesty-bench-{digest}"
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
def ask_forward(root: Path) -> bool:
|
|
156
|
+
"""Ask the console of the home at *root* to come forward; ``False`` when none answers."""
|
|
157
|
+
socket = QLocalSocket()
|
|
158
|
+
socket.connectToServer(_socket_name(root))
|
|
159
|
+
if not socket.waitForConnected(1000):
|
|
160
|
+
return False
|
|
161
|
+
socket.write(b"raise\n")
|
|
162
|
+
socket.waitForBytesWritten(1000)
|
|
163
|
+
socket.disconnectFromServer()
|
|
164
|
+
return True
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
def _come_forward(window: MainWindow) -> None:
|
|
168
|
+
"""Show *window* in front, from minimised or behind other windows."""
|
|
169
|
+
window.setWindowState(window.windowState() & ~Qt.WindowState.WindowMinimized)
|
|
170
|
+
window.show()
|
|
171
|
+
window.raise_()
|
|
172
|
+
window.activateWindow()
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
def run_gui(bench: Bench, title: str | None = None) -> int:
|
|
176
|
+
"""Open the console on *bench* and run until the window closes; returns the exit code.
|
|
177
|
+
|
|
178
|
+
A home that already has a console open is not given a second one: that
|
|
179
|
+
console is brought forward instead, and this launch ends.
|
|
180
|
+
"""
|
|
181
|
+
app = application()
|
|
182
|
+
guard = claim_console(bench.home.root)
|
|
183
|
+
if guard is None:
|
|
184
|
+
if not ask_forward(bench.home.root):
|
|
185
|
+
QMessageBox.information(
|
|
186
|
+
None,
|
|
187
|
+
"PLESTY Bench is already open",
|
|
188
|
+
f"PLESTY Bench is already open for {bench.home.root}.\n\n"
|
|
189
|
+
"Use the window that is open; a second one would share its runs and jobs.",
|
|
190
|
+
)
|
|
191
|
+
return 0
|
|
192
|
+
window = build_window(bench, title)
|
|
193
|
+
guard.on_raise(lambda: _come_forward(window))
|
|
194
|
+
window.show()
|
|
195
|
+
try:
|
|
196
|
+
return int(app.exec())
|
|
197
|
+
finally:
|
|
198
|
+
guard.release()
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
def _version() -> str:
|
|
202
|
+
try:
|
|
203
|
+
return metadata.version("plesty-server")
|
|
204
|
+
except metadata.PackageNotFoundError: # pragma: no cover — source checkout without install
|
|
205
|
+
return "dev"
|
|
@@ -376,6 +376,7 @@ class MainWindow(QMainWindow):
|
|
|
376
376
|
self.exp_title.setObjectName("cardTitle")
|
|
377
377
|
self.exp_log = QPlainTextEdit()
|
|
378
378
|
self.exp_log.setReadOnly(True)
|
|
379
|
+
self.exp_log.verticalScrollBar().valueChanged.connect(self._log_scrolled)
|
|
379
380
|
self.exp_tabs = QTabWidget()
|
|
380
381
|
panes = (
|
|
381
382
|
self.exp_log,
|
|
@@ -429,8 +430,19 @@ class MainWindow(QMainWindow):
|
|
|
429
430
|
splitter.setStretchFactor(1, 3)
|
|
430
431
|
#: The run shown in the detail card; None follows the newest.
|
|
431
432
|
self._exp_run: str | None = None
|
|
433
|
+
#: The log on screen: (experiment, run, job) it belongs to, the job,
|
|
434
|
+
#: the byte its first shown line starts at, the byte reading goes on
|
|
435
|
+
#: from, whether its end has been read, and whether it is all read —
|
|
436
|
+
#: an ended run's log, which nothing writes to any more.
|
|
437
|
+
self._exp_log_key: tuple[str, str, str] | None = None
|
|
438
|
+
self._exp_log_job = ""
|
|
439
|
+
self._exp_log_start = 0
|
|
432
440
|
self._exp_offset = 0
|
|
441
|
+
self._exp_log_loaded = False
|
|
442
|
+
self._exp_log_done = False
|
|
433
443
|
self._exp_views: list[Any] = []
|
|
444
|
+
#: A run just created, to select once a repaint holds its row.
|
|
445
|
+
self._select_next: tuple[str, str | None] | None = None
|
|
434
446
|
#: Runs read from elsewhere, which this bench holds but does not own.
|
|
435
447
|
self._loaded_runs: list[dict[str, Any]] = []
|
|
436
448
|
return splitter
|
|
@@ -767,8 +779,10 @@ class MainWindow(QMainWindow):
|
|
|
767
779
|
|
|
768
780
|
def refresh(self) -> None:
|
|
769
781
|
"""Re-read the devices — this bench's and its nodes' — and repaint them."""
|
|
770
|
-
self.worker.
|
|
771
|
-
|
|
782
|
+
self.worker.run_once(
|
|
783
|
+
"devices",
|
|
784
|
+
lambda: self.bench.devices(probe=True, nodes=True),
|
|
785
|
+
on_done=self._show_devices,
|
|
772
786
|
)
|
|
773
787
|
self.refresh_experiments()
|
|
774
788
|
|
|
@@ -784,7 +798,7 @@ class MainWindow(QMainWindow):
|
|
|
784
798
|
if not self.bench.fleet.experiments:
|
|
785
799
|
self._show_experiments([])
|
|
786
800
|
return
|
|
787
|
-
self.worker.
|
|
801
|
+
self.worker.run_once("experiments", self._read_experiments, on_done=self._show_experiments)
|
|
788
802
|
|
|
789
803
|
def _read_experiments(self) -> list[dict[str, Any]]:
|
|
790
804
|
"""Read every run of every declared experiment, off the GUI thread."""
|
|
@@ -796,8 +810,19 @@ class MainWindow(QMainWindow):
|
|
|
796
810
|
return rows + list(self._loaded_runs)
|
|
797
811
|
|
|
798
812
|
def _show_experiments(self, rows: list[dict[str, Any]]) -> None:
|
|
799
|
-
"""Repaint the run table, keeping the selection where it was.
|
|
813
|
+
"""Repaint the run table, keeping the selection where it was.
|
|
814
|
+
|
|
815
|
+
A run just created takes the selection instead, once a repaint that
|
|
816
|
+
holds it lands: selecting it straight after asking for the refresh
|
|
817
|
+
looked for a row that was not drawn yet (#31).
|
|
818
|
+
"""
|
|
800
819
|
selected = self.selected_run
|
|
820
|
+
if self._select_next is not None and any(
|
|
821
|
+
row["name"] == self._select_next[0]
|
|
822
|
+
and row["status"].get("run") == self._select_next[1]
|
|
823
|
+
for row in rows
|
|
824
|
+
):
|
|
825
|
+
selected, self._select_next = self._select_next, None
|
|
801
826
|
self._exp_views = rows
|
|
802
827
|
self.exp_table.setRowCount(len(rows))
|
|
803
828
|
for index, row in enumerate(rows):
|
|
@@ -874,8 +899,10 @@ class MainWindow(QMainWindow):
|
|
|
874
899
|
"""A different run was picked: the panes follow it."""
|
|
875
900
|
chosen = self.selected_run
|
|
876
901
|
self._exp_run = chosen[1] if chosen is not None else None
|
|
877
|
-
|
|
878
|
-
|
|
902
|
+
# The log is not cleared here: the selection signal also fires for the
|
|
903
|
+
# run already shown, and starting its log over each time is what kept
|
|
904
|
+
# an ended run's log scrolling past (#28). The log pane resets itself
|
|
905
|
+
# when the run it shows is a different one.
|
|
879
906
|
self._update_experiment_buttons()
|
|
880
907
|
self._refresh_experiment_detail()
|
|
881
908
|
|
|
@@ -999,7 +1026,7 @@ class MainWindow(QMainWindow):
|
|
|
999
1026
|
self._clear_embedded_views()
|
|
1000
1027
|
self.viz_caption.setText(waiting)
|
|
1001
1028
|
self.viz_button.setEnabled(False)
|
|
1002
|
-
self.
|
|
1029
|
+
self._exp_log_key = None
|
|
1003
1030
|
|
|
1004
1031
|
def _tail_experiment_log(self, name: str) -> None:
|
|
1005
1032
|
"""Follow the log of the job that ran the *selected* run.
|
|
@@ -1011,6 +1038,9 @@ class MainWindow(QMainWindow):
|
|
|
1011
1038
|
"""
|
|
1012
1039
|
status = self.selected_experiment_status
|
|
1013
1040
|
run = str(status.get("run") or "")
|
|
1041
|
+
shown = self._exp_log_key
|
|
1042
|
+
if self._exp_log_done and shown is not None and shown[:2] == (name, run):
|
|
1043
|
+
return # an ended run's log, read to its end: nothing more is coming
|
|
1014
1044
|
jobs = self.bench.experiment_jobs(name)
|
|
1015
1045
|
job = next(
|
|
1016
1046
|
(
|
|
@@ -1028,26 +1058,101 @@ class MainWindow(QMainWindow):
|
|
|
1028
1058
|
if jobs and newest and newest[0].name == run:
|
|
1029
1059
|
job = jobs[0]
|
|
1030
1060
|
else:
|
|
1061
|
+
self._exp_log_key = None
|
|
1031
1062
|
self.exp_log.setPlainText(
|
|
1032
1063
|
f"No log on this bench for {run}." if run else "No run has been started yet."
|
|
1033
1064
|
)
|
|
1034
1065
|
return
|
|
1035
|
-
|
|
1036
|
-
self.
|
|
1037
|
-
|
|
1038
|
-
|
|
1066
|
+
key = (name, run, job.id)
|
|
1067
|
+
if key != self._exp_log_key:
|
|
1068
|
+
# Another run, or another job of it (a resume): its log from its end.
|
|
1069
|
+
self._exp_log_key, self._exp_log_job = key, job.id
|
|
1070
|
+
self._exp_log_start = self._exp_offset = 0
|
|
1071
|
+
self._exp_log_loaded = self._exp_log_done = False
|
|
1072
|
+
self.exp_log.clear()
|
|
1073
|
+
ended = str(status.get("state", "")) not in LIVE_STATES
|
|
1074
|
+
# One read in flight: two from the same offset appended the same part
|
|
1075
|
+
# of the log twice, which on a backed-up worker was the log replaying.
|
|
1076
|
+
self.worker.run_once(
|
|
1077
|
+
"experiment-log",
|
|
1078
|
+
lambda: self._read_experiment_log(key, ended),
|
|
1079
|
+
on_done=self._show_experiment_log,
|
|
1039
1080
|
)
|
|
1040
1081
|
|
|
1041
|
-
def
|
|
1042
|
-
"""
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1082
|
+
def _read_experiment_log(self, key: tuple[str, str, str], ended: bool) -> Any:
|
|
1083
|
+
"""Read the next part of the shown log, off the GUI thread.
|
|
1084
|
+
|
|
1085
|
+
Reads what the pane is at when the read *runs*, not when it was asked
|
|
1086
|
+
for: a read asked for during the last one starts where that one ended.
|
|
1087
|
+
|
|
1088
|
+
Returns:
|
|
1089
|
+
``("end", key, text, start, end)`` for the first read of a log,
|
|
1090
|
+
``("more", key, text, offset, ended)`` after it, or ``None`` when
|
|
1091
|
+
the pane has moved to another log meanwhile.
|
|
1092
|
+
"""
|
|
1093
|
+
if key != self._exp_log_key:
|
|
1094
|
+
return None
|
|
1095
|
+
if not self._exp_log_loaded:
|
|
1096
|
+
return ("end", key, *self.bench.job_log_end(key[2]))
|
|
1097
|
+
text, offset = self.bench.job_log(key[2], self._exp_offset)
|
|
1098
|
+
return ("more", key, text, offset, ended)
|
|
1099
|
+
|
|
1100
|
+
def _show_experiment_log(self, read: Any) -> None:
|
|
1101
|
+
"""Put a read of the log on screen, without moving what is being read.
|
|
1102
|
+
|
|
1103
|
+
The first read opens on the end of the log, as it stood when the run
|
|
1104
|
+
finished or as far as a running one has got. After it, what a running
|
|
1105
|
+
run adds is appended, and the view follows only when it was already at
|
|
1106
|
+
the end. An ended run, once read to its end, is not read again (#28).
|
|
1107
|
+
"""
|
|
1108
|
+
if read is None or read[1] != self._exp_log_key:
|
|
1109
|
+
return
|
|
1110
|
+
bar = self.exp_log.verticalScrollBar()
|
|
1111
|
+
if read[0] == "end":
|
|
1112
|
+
_, _, text, start, end = read
|
|
1113
|
+
self.exp_log.setPlainText(text)
|
|
1114
|
+
bar.setValue(bar.maximum())
|
|
1115
|
+
self._exp_log_start, self._exp_offset = start, end
|
|
1116
|
+
self._exp_log_loaded = True
|
|
1117
|
+
return
|
|
1118
|
+
_, _, text, offset, ended = read
|
|
1046
1119
|
self._exp_offset = offset
|
|
1047
|
-
if text:
|
|
1048
|
-
|
|
1049
|
-
self.
|
|
1050
|
-
|
|
1120
|
+
if not text:
|
|
1121
|
+
# Read to the end: an ended run writes nothing more.
|
|
1122
|
+
self._exp_log_done = ended
|
|
1123
|
+
return
|
|
1124
|
+
following = bar.value() >= bar.maximum()
|
|
1125
|
+
cursor = QTextCursor(self.exp_log.document())
|
|
1126
|
+
cursor.movePosition(QTextCursor.MoveOperation.End)
|
|
1127
|
+
cursor.insertText(text)
|
|
1128
|
+
if following:
|
|
1129
|
+
bar.setValue(bar.maximum())
|
|
1130
|
+
|
|
1131
|
+
def _log_scrolled(self, value: int) -> None:
|
|
1132
|
+
"""At the top of the shown part of a long log: load the part before it."""
|
|
1133
|
+
if value > self.exp_log.verticalScrollBar().minimum():
|
|
1134
|
+
return
|
|
1135
|
+
if self._exp_log_key is None or not self._exp_log_loaded or self._exp_log_start <= 0:
|
|
1136
|
+
return
|
|
1137
|
+
key, job, start = self._exp_log_key, self._exp_log_job, self._exp_log_start
|
|
1138
|
+
self.worker.run_once(
|
|
1139
|
+
"experiment-log-earlier",
|
|
1140
|
+
lambda: (key, *self.bench.job_log_before(job, start)),
|
|
1141
|
+
on_done=self._prepend_experiment_log,
|
|
1142
|
+
)
|
|
1143
|
+
|
|
1144
|
+
def _prepend_experiment_log(self, read: tuple[tuple[str, str, str], str, int]) -> None:
|
|
1145
|
+
"""Put an earlier part of the log above the shown one, keeping the view still."""
|
|
1146
|
+
key, text, start = read
|
|
1147
|
+
if key != self._exp_log_key or not text or start >= self._exp_log_start:
|
|
1148
|
+
return
|
|
1149
|
+
bar = self.exp_log.verticalScrollBar()
|
|
1150
|
+
before = bar.maximum() - bar.value()
|
|
1151
|
+
cursor = QTextCursor(self.exp_log.document())
|
|
1152
|
+
cursor.movePosition(QTextCursor.MoveOperation.Start)
|
|
1153
|
+
cursor.insertText(text)
|
|
1154
|
+
self._exp_log_start = start
|
|
1155
|
+
bar.setValue(bar.maximum() - before)
|
|
1051
1156
|
|
|
1052
1157
|
def _show_experiment_data(self, name: str) -> None:
|
|
1053
1158
|
"""Show the newest committed records — the raw data the run has produced."""
|
|
@@ -1332,7 +1437,7 @@ class MainWindow(QMainWindow):
|
|
|
1332
1437
|
def _experiment_started(self, name: str, job: Job) -> None:
|
|
1333
1438
|
"""Note the run and follow its log."""
|
|
1334
1439
|
self.notice.emit(f"{name}: run started as job {job.id}")
|
|
1335
|
-
self.
|
|
1440
|
+
self._exp_log_key = None
|
|
1336
1441
|
self.exp_log.clear()
|
|
1337
1442
|
self.refresh_experiments()
|
|
1338
1443
|
|
|
@@ -1499,8 +1604,8 @@ class MainWindow(QMainWindow):
|
|
|
1499
1604
|
"""Repaint, and put the selection on the run that was just named."""
|
|
1500
1605
|
name, run = row["name"], row["status"].get("run")
|
|
1501
1606
|
self.notice.emit(f"{name}: created {run}")
|
|
1607
|
+
self._select_next = (name, run)
|
|
1502
1608
|
self.refresh_experiments()
|
|
1503
|
-
self._select_run(name, run)
|
|
1504
1609
|
|
|
1505
1610
|
def load_run(self) -> None:
|
|
1506
1611
|
"""Read a run measured elsewhere, from the directory it was written to.
|
|
@@ -59,6 +59,9 @@ class Worker(QObject):
|
|
|
59
59
|
self._pool = QThreadPool(self)
|
|
60
60
|
self._pool.setMaxThreadCount(threads)
|
|
61
61
|
self._live: list[_Signals] = []
|
|
62
|
+
#: Keys of :meth:`run_once` calls in flight, each with the call asked
|
|
63
|
+
#: for while it ran (``None`` when none was).
|
|
64
|
+
self._once: dict[str, tuple[Any, ...] | None] = {}
|
|
62
65
|
|
|
63
66
|
def run(
|
|
64
67
|
self,
|
|
@@ -82,6 +85,55 @@ class Worker(QObject):
|
|
|
82
85
|
signals.failed.connect(lambda _m: _release())
|
|
83
86
|
self._pool.start(_Task(action, signals))
|
|
84
87
|
|
|
88
|
+
def run_once(
|
|
89
|
+
self,
|
|
90
|
+
key: str,
|
|
91
|
+
action: Callable[[], Any],
|
|
92
|
+
on_done: Callable[[Any], None] | None = None,
|
|
93
|
+
on_error: Callable[[str], None] | None = None,
|
|
94
|
+
) -> None:
|
|
95
|
+
"""Like :meth:`run`, but never a second *key* while one is in flight.
|
|
96
|
+
|
|
97
|
+
The refresh timer asks for the same reads every second. When one takes
|
|
98
|
+
longer than that — a probe of a node that does not answer — each tick
|
|
99
|
+
queued another behind it, the queue grew without end, and every table
|
|
100
|
+
showed an older state the longer the console ran: a deleted run stayed
|
|
101
|
+
on screen, a created one never appeared (#31). Asked for while it runs,
|
|
102
|
+
the call is kept and made once, as soon as the running one is back, so
|
|
103
|
+
what was asked last is what is shown.
|
|
104
|
+
|
|
105
|
+
Args:
|
|
106
|
+
key: What the call reads; one in flight per key.
|
|
107
|
+
action: As for :meth:`run`.
|
|
108
|
+
on_done: As for :meth:`run`.
|
|
109
|
+
on_error: As for :meth:`run`.
|
|
110
|
+
"""
|
|
111
|
+
if key in self._once:
|
|
112
|
+
self._once[key] = (action, on_done, on_error)
|
|
113
|
+
return
|
|
114
|
+
self._once[key] = None
|
|
115
|
+
|
|
116
|
+
def _next() -> None:
|
|
117
|
+
waiting = self._once.pop(key, None)
|
|
118
|
+
if waiting is not None:
|
|
119
|
+
self.run_once(key, *waiting)
|
|
120
|
+
|
|
121
|
+
def _done(result: Any) -> None:
|
|
122
|
+
try:
|
|
123
|
+
if on_done is not None:
|
|
124
|
+
on_done(result)
|
|
125
|
+
finally:
|
|
126
|
+
_next()
|
|
127
|
+
|
|
128
|
+
def _failed(message: str) -> None:
|
|
129
|
+
try:
|
|
130
|
+
if on_error is not None:
|
|
131
|
+
on_error(message)
|
|
132
|
+
finally:
|
|
133
|
+
_next()
|
|
134
|
+
|
|
135
|
+
self.run(action, on_done=_done, on_error=_failed)
|
|
136
|
+
|
|
85
137
|
def wait(self, timeout_ms: int = 30000) -> bool:
|
|
86
138
|
"""Block until every task finished (tests); ``True`` when none is left."""
|
|
87
139
|
return self._pool.waitForDone(timeout_ms)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "plesty-server"
|
|
3
|
-
version = "0.4.
|
|
3
|
+
version = "0.4.4"
|
|
4
4
|
license = "LGPL-3.0-or-later"
|
|
5
5
|
license-files = ["LICENSE", "LICENSES/*"]
|
|
6
6
|
description = "The PLESTY bench application: installs, runs and field-tests device servers."
|
|
@@ -9,7 +9,7 @@ maintainers = [{ name = "Plesty Development Team", email = "plesty.dev@example.c
|
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.12"
|
|
11
11
|
dependencies = [
|
|
12
|
-
"plesty-bench==0.4.
|
|
12
|
+
"plesty-bench==0.4.4",
|
|
13
13
|
"plesty-lib[report]>=0.5.2",
|
|
14
14
|
"pyyaml>=6.0",
|
|
15
15
|
"pyzmq>=26",
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
# SPDX-FileCopyrightText: 2026 Yunshuang Yuan
|
|
2
|
-
# SPDX-License-Identifier: LGPL-3.0-or-later
|
|
3
|
-
|
|
4
|
-
"""Open the console: Qt application, plesty-lib theme, our stylesheet, the window."""
|
|
5
|
-
|
|
6
|
-
from __future__ import annotations
|
|
7
|
-
|
|
8
|
-
from importlib import metadata, resources
|
|
9
|
-
|
|
10
|
-
from PySide6.QtGui import QIcon
|
|
11
|
-
from PySide6.QtWidgets import QApplication
|
|
12
|
-
|
|
13
|
-
from plesty.lib.ui.theme import Theme
|
|
14
|
-
from plesty.server.presenter import Bench
|
|
15
|
-
from plesty.server.view.window import MainWindow
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
#: Preferred UI and monospace families, first available wins (plesty.net's
|
|
19
|
-
#: Inter where installed, else the platform's own face).
|
|
20
|
-
UI_FONTS = ("Inter", "SF Pro Text", "Segoe UI", "Helvetica Neue", "Arial")
|
|
21
|
-
MONO_FONTS = ("SF Mono", "Menlo", "Consolas", "DejaVu Sans Mono", "Courier New")
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
def pick_font(candidates: tuple[str, ...], fallback: str) -> str:
|
|
25
|
-
"""The first of *candidates* the host has, else *fallback* — quoted for QSS.
|
|
26
|
-
|
|
27
|
-
Asked rather than listed: Qt warns at start-up for every stylesheet
|
|
28
|
-
family that is missing on the host, and the answer differs per bench.
|
|
29
|
-
"""
|
|
30
|
-
try:
|
|
31
|
-
from PySide6.QtGui import QFontDatabase
|
|
32
|
-
|
|
33
|
-
installed = set(QFontDatabase.families())
|
|
34
|
-
except Exception: # noqa: BLE001 — no QApplication yet, or no font database
|
|
35
|
-
installed = set()
|
|
36
|
-
for name in candidates:
|
|
37
|
-
if name in installed:
|
|
38
|
-
return f'"{name}", {fallback}'
|
|
39
|
-
return fallback
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
def stylesheet(theme: Theme | None = None) -> str:
|
|
43
|
-
"""The console stylesheet: ``assets/console.qss`` with the palette and fonts substituted."""
|
|
44
|
-
theme = theme or Theme.load()
|
|
45
|
-
with resources.as_file(
|
|
46
|
-
resources.files("plesty.server").joinpath("assets/console.qss")
|
|
47
|
-
) as path:
|
|
48
|
-
text = theme.stylesheet(path)
|
|
49
|
-
return text.replace("{{ui_font}}", pick_font(UI_FONTS, "sans-serif")).replace(
|
|
50
|
-
"{{mono_font}}", pick_font(MONO_FONTS, "monospace")
|
|
51
|
-
)
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
def mark_icon() -> QIcon:
|
|
55
|
-
"""The PLESTY mark (``assets/plesty-mark.svg``, the static version) as a window icon."""
|
|
56
|
-
with resources.as_file(
|
|
57
|
-
resources.files("plesty.server").joinpath("assets/plesty-mark.svg")
|
|
58
|
-
) as path:
|
|
59
|
-
return QIcon(str(path))
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
def application() -> QApplication:
|
|
63
|
-
"""The running Qt application, created, themed and branded when there is none."""
|
|
64
|
-
existing = QApplication.instance()
|
|
65
|
-
if isinstance(existing, QApplication):
|
|
66
|
-
return existing
|
|
67
|
-
app = QApplication([])
|
|
68
|
-
app.setApplicationName("plesty-server")
|
|
69
|
-
app.setApplicationDisplayName("PLESTY bench")
|
|
70
|
-
app.setWindowIcon(mark_icon())
|
|
71
|
-
app.setStyleSheet(stylesheet())
|
|
72
|
-
return app
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
def build_window(bench: Bench, title: str | None = None) -> MainWindow:
|
|
76
|
-
"""A themed main window on *bench* (the application must exist)."""
|
|
77
|
-
theme = Theme.load()
|
|
78
|
-
window = MainWindow(bench, title or f"PLESTY bench — {bench.home.root}", version=_version())
|
|
79
|
-
window.theme = theme # type: ignore[attr-defined] # read by the state brushes
|
|
80
|
-
window.setWindowIcon(mark_icon())
|
|
81
|
-
bench.remember_fleet()
|
|
82
|
-
return window
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
def run_gui(bench: Bench, title: str | None = None) -> int:
|
|
86
|
-
"""Open the console on *bench* and run until the window closes; returns the exit code."""
|
|
87
|
-
app = application()
|
|
88
|
-
window = build_window(bench, title)
|
|
89
|
-
window.show()
|
|
90
|
-
return int(app.exec())
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
def _version() -> str:
|
|
94
|
-
try:
|
|
95
|
-
return metadata.version("plesty-server")
|
|
96
|
-
except metadata.PackageNotFoundError: # pragma: no cover — source checkout without install
|
|
97
|
-
return "dev"
|
|
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
|
|
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
|