fix: bind UI jobs and recovery actions to captured scope

This commit is contained in:
阿白叔 committed 2026-11-16 22:11:17 +08:00
1 parent 601dd7b6b2
commit cd7a5e0ca1
20 files changed
+1570 -297

No files matched your search

+17 -12
View File
@@ -203,20 +203,22 @@ def filesystem_status_map(library: Path, names):
return {name: details['status'] for name, details in filesystem_evidence_map(library, names).items()}
def read_library_fast(path: Path, *, status_reader=None):
"""List CBBs from ReusableBlocksLP without touching COM or the .lmc.
Useful when Library Manager is unavailable or already running: the folder
is the same source the LM tree shows, and an optional status_reader can
supply each item's flag without a full COM session.
"""
"""Discover directories; this does not validate native format/registration."""
try:
path = Path(path)
if path.suffix.casefold() != '.lmc':
return LibraryReadResult((), 'INPUT_SUFFIX: 请选择 .lmc 中心库文件。')
if not path.is_file():
return LibraryReadResult((), f'中心库不存在: {path}')
return LibraryReadResult((), f'INPUT_MISSING: 中心库不存在或不是文件: {path}')
with path.open('rb') as stream:
if not stream.read(1):
return LibraryReadResult((), 'INPUT_EMPTY: 中心库文件为空。')
if any(lock.is_dir() for lock in (path.with_suffix('.lock'), path.with_name('.'+path.stem+'.cbb-upload.lock'))):
return LibraryReadResult((), 'INPUT_LOCK_DIRECTORY: 中心库锁路径是目录。')
folder = path.parent/'ReusableBlocksLP'
if not folder.is_dir():
return LibraryReadResult((), f'缺少 ReusableBlocksLP 目录: {folder}')
entries = [entry for entry in folder.iterdir() if entry.is_dir()]
if folder.exists() and not folder.is_dir():
return LibraryReadResult((), f'INPUT_DIRECTORY: ReusableBlocksLP 不是目录: {folder}')
entries = [entry for entry in folder.iterdir() if entry.is_dir()] if folder.is_dir() else []
names = tuple(sorted((entry.name for entry in entries), key=str.casefold))
statuses = {}
if status_reader is not None and names:
@@ -240,8 +242,11 @@ def read_library_fast(path: Path, *, status_reader=None):
status = str(statuses.get(entry.name, 'UNKNOWN') or 'UNKNOWN')
if status not in {'READY', 'PENDING', 'UNKNOWN', 'UNAVAILABLE', 'ERROR', 'TIMEOUT'}:
status = 'UNKNOWN'
records.append(CbbRecord(entry.name, 'Reusable Blocks', status=status))
return LibraryReadResult(tuple(sorted(records, key=lambda item: item.name)))
records.append(CbbRecord(entry.name, 'Reusable Blocks', status=status,
catalog_source='directory', status_source='status_reader' if status_reader else 'unknown'))
return LibraryReadResult(tuple(sorted(records, key=lambda item: item.name)), directory_count=len(entries))
except PermissionError as error:
return LibraryReadResult((), f'INPUT_PERMISSION: 无权读取中心库: {error}')
except Exception as error:
return LibraryReadResult((), str(error))