add fill_name arg (fill name with source pattern)

This commit is contained in:
Jan Petykiewicz 2024-02-27 22:04:46 -08:00
parent 72f24af117
commit 6c1bcc09d3

18
k2t.py
View File

@ -7,7 +7,11 @@ from dataclasses import dataclass, fields
from xml.etree import ElementTree from xml.etree import ElementTree
def k2t(kfile: str, tfile: str) -> None: def k2t(
kfile: str,
tfile: str,
fill_name: bool = False,
) -> None:
""" """
Convert from KLayout layer properties xml (.lyp) to TOML Convert from KLayout layer properties xml (.lyp) to TOML
@ -38,6 +42,18 @@ def k2t(kfile: str, tfile: str) -> None:
if name is not None: if name is not None:
print(f'Discarding tab name: {name}') print(f'Discarding tab name: {name}')
def add_names(entrs: list[Entry]) -> None:
for entry in entrs:
if entry.members:
add_names(entry.members)
if entry.name or not entry.source:
continue
entry.name = entry.source
if fill_name:
add_names(entries)
with open(tfile, 'wt') as ff: with open(tfile, 'wt') as ff:
for entry in entries: for entry in entries:
ff.write(entry.to_toml()) ff.write(entry.to_toml())