Files
cbb-refresh-verify-795/src/cbb_refresh_verify/icdb_ownership.py
T

47 lines
2.1 KiB
Python

"""Known native database owners touched by a CBB verification operation."""
from pathlib import Path
def session_resource_scope(job):
"""Persist declared targets; only fresh proof promotes them to observed scope."""
library = Path(job['library'])
project, pcb = job.get('project'), job.get('pcb')
projects = [str(Path(project))] if project else []
databases = [str(Path(p).parent/'database') for p in (project, pcb) if p]
shared = library.parent/'SymbolLibs/__ReusableBlocksSymb'
return {'scope_state': 'DECLARED' if project else 'RECHECK_REQUIRED',
'library': str(library), 'operation_id': job.get('operation_id'),
'block_name': job.get('block'), 'projects': projects,
'databases': list(dict.fromkeys(databases)), 'shared_dependencies': [str(shared)]}
def database_directories(lmc_file, project, pcb):
return tuple(dict.fromkeys((
Path(project).parent/'database',
Path(pcb).parent/'database',
Path(lmc_file).parent/'SymbolLibs/__ReusableBlocksSymb',
)))
def unreleased_addresses(lmc_file, project, pcb):
return [str(path/'cdbsvr/sAddress.adr')
for path in database_directories(lmc_file, project, pcb)
if (path/'cdbsvr/sAddress.adr').exists()]
def inspect_release_addresses(snapshot, *, stop=None):
"""An address is a reason for native inspection, never an occupancy verdict."""
import tempfile
from .native_repair import RepairTarget, run_native_repair
from .native_occupancy import confirmed_inspection
from .library_lock import LibraryBusy
results = []
for item in snapshot['inspection_targets']:
target = RepairTarget(Path(item['project']), Path(item['database']))
root = Path(tempfile.mkdtemp(prefix='cbb-release-inspection-'))
result = run_native_repair(target, root, inspection_only=True, stop=stop)
if not confirmed_inspection(target, result) or result['status'] != 'NOT_IN_USE':
raise LibraryBusy(f'目标数据库未确认释放:{target.database};检查证据:{root}')
results.append(result)
return results