Prefer CN device matches

This commit is contained in:
2026-04-24 10:15:55 +08:00
parent c9a2d13945
commit d36669103e
7 changed files with 42441 additions and 44883 deletions
+25 -1
View File
@@ -299,6 +299,22 @@ def normalize_alias_list(*groups: object) -> List[str]:
return aliases
def is_preferred_cn_source_file(source_file: str) -> bool:
source = str(source_file or "").strip().lower()
if not source:
return False
if source == MANUAL_SOURCE_FILE:
return True
return not (source.endswith("_en.md") or source.endswith("_global_en.md"))
def first_preferred_match(records: List[DeviceRecord]) -> List[DeviceRecord]:
if not records:
return []
cn_records = [record for record in records if is_preferred_cn_source_file(record.source_file)]
return [(cn_records or records)[0]]
def load_manual_catalog(repo_root: Path) -> dict[str, object]:
path = repo_root / MANUAL_SOURCE_FILE
if not path.exists():
@@ -719,7 +735,15 @@ class DeviceMapper:
}
matched_records = [r for r in [self.records_by_id[rid] for rid in candidate_ids] if self._brand_match(fallback_filter, r)]
matched_records.sort(key=lambda r: (r.device_name, r.source_file, r.id))
matched_records.sort(
key=lambda r: (
0 if is_preferred_cn_source_file(r.source_file) else 1,
r.device_name,
r.source_file,
r.id,
)
)
matched_records = first_preferred_match(matched_records)
if matched_records:
best = matched_records[0]