Skip to content

Commit d21cd3e

Browse files
committed
Address review comments
1 parent 58bb304 commit d21cd3e

3 files changed

Lines changed: 18 additions & 5 deletions

File tree

dlclivegui/cameras/backends/gentl_backend.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,7 @@ def open(self) -> None:
372372
ns["cti_file"] = str(cti_files[0]) # best effort
373373

374374
if not loaded:
375+
self._harvester = None
375376
raise RuntimeError(
376377
"No GenTL producer (.cti) could be loaded.\n\n"
377378
f"Resolved CTIs: {cti_files}\n"
@@ -384,6 +385,7 @@ def open(self) -> None:
384385
self._harvester.update()
385386

386387
if not self._harvester.device_info_list:
388+
self._harvester = None
387389
raise RuntimeError(
388390
"No GenTL cameras detected via Harvesters after loading producers.\n\n"
389391
f"Loaded CTIs: {loaded}\n"

dlclivegui/cameras/backends/utils/gentl_discovery.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ def _add_candidate(path: str, reason_ctx: str) -> None:
174174
for entry in env_entries:
175175
norm_entry = _normalize_path(entry)
176176
p = Path(norm_entry)
177-
if p.is_file() and p.suffix.lower() == ".cti":
177+
if p.is_file(): # let _add_candidate check .cti extension and existence
178178
_add_candidate(norm_entry, "env:file")
179179
elif p.is_dir():
180180
for f in _iter_cti_files_in_dir(norm_entry, recursive=recursive_env_search):
@@ -227,7 +227,16 @@ def choose_cti_files(
227227
return []
228228

229229
if policy == GenTLDiscoveryPolicy.NEWEST:
230-
cand_sorted = sorted(cand, key=lambda p: Path(p).stat().st_mtime if Path(p).exists() else 0.0, reverse=True)
230+
231+
def _newest_mtime(p: str) -> float:
232+
try:
233+
if not Path(p).exists():
234+
return 0.0
235+
return Path(p).stat().st_mtime
236+
except OSError:
237+
return 0.0
238+
239+
cand_sorted = sorted(cand, key=_newest_mtime, reverse=True)
231240
return cand_sorted[:max_files]
232241

233242
if policy == GenTLDiscoveryPolicy.FIRST:

tests/cameras/backends/test_gentl_backend.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from __future__ import annotations
33

44
import os
5-
import time
65
import types
76
from pathlib import Path
87

@@ -655,9 +654,12 @@ def test_choose_cti_files_newest_policy(tmp_path):
655654
old = _make_cti(tmp_path, "Old.cti")
656655
new = _make_cti(tmp_path, "New.cti")
657656

658-
# Ensure distinct mtimes
659-
time.sleep(0.01)
657+
# Ensure distinct mtimes (platform agnostic)
660658
new.write_text("dummy2", encoding="utf-8")
659+
old_stat = old.stat()
660+
new_stat = new.stat()
661+
if new_stat.st_mtime <= old_stat.st_mtime:
662+
os.utime(new, (new_stat.st_atime, old_stat.st_mtime + 1))
661663

662664
selected = choose_cti_files([str(old), str(new)], policy=GenTLDiscoveryPolicy.NEWEST, max_files=1)
663665
assert len(selected) == 1

0 commit comments

Comments
 (0)