fixed generation for the .rpt plain text format

This commit is contained in:
2025-12-31 14:50:42 +13:00
parent 9cd18828eb
commit b1d4a80a2f

View File

@@ -28,14 +28,21 @@ TEMP_DRC_REPORT_NAME = "_drc"
TEMP_ERC_REPORT_NAME = "_erc"
# quiet
STDOUT=subprocess.DEVNULL
KICAD_CLI_STDOUT=subprocess.DEVNULL
# verbose
# STDOUT=subprocess.STDOUT
# KICAD_CLI_STDOUT=subprocess.STDOUT
class OutputReportType(Enum):
JSON = 1
REPORT = 2
def get_file_extension(self) -> str:
if (self == OutputReportType.JSON):
return "json"
if (self == OutputReportType.REPORT):
return "rpt"
return "txt"
# this is a thin vale on the kicad cli tool
class KicadProject:
@@ -53,12 +60,12 @@ class KicadProject:
) -> None | dict | str:
format_type = report_format.name.lower()
pcb_file_path = self.project_path / f"{self.project_name}.kicad_sch"
erc_report_path = Path(TEMP_FILE_PATH) / f"{self.project_name}{TEMP_ERC_REPORT_NAME}.{format_type}"
erc_report_path = Path(TEMP_FILE_PATH) / f"{self.project_name}{TEMP_ERC_REPORT_NAME}.{report_format.get_file_extension()}"
retcode = subprocess.call(
f'{KICAD_CLI_PATH} sch erc {pcb_file_path} --output {erc_report_path} --format {format_type}',
shell=True,
stdout=STDOUT
stdout=KICAD_CLI_STDOUT
)
if (retcode != 0):
@@ -81,13 +88,14 @@ class KicadProject:
) -> None | dict | str:
format_type = report_format.name.lower()
pcb_file_path = self.project_path / f"{self.project_name}.kicad_pcb"
drc_report_path = Path(TEMP_FILE_PATH) / f"{self.project_name}{TEMP_DRC_REPORT_NAME}.{format_type}"
drc_report_path = Path(TEMP_FILE_PATH) / f"{self.project_name}{TEMP_DRC_REPORT_NAME}.{report_format.get_file_extension()}"
print(f"{format_type=}, {drc_report_path=}")
retcode = subprocess.call(
f'{KICAD_CLI_PATH} pcb drc {pcb_file_path} --output {drc_report_path} --format {format_type}',
shell=True,
stdout=STDOUT
stdout=KICAD_CLI_STDOUT
)
print(f"{retcode=}")
if (retcode != 0):
print(f"drc check failed return code {retcode}")
exit(1)
@@ -110,7 +118,7 @@ class KicadProject:
retcode = subprocess.call(
f'{KICAD_CLI_PATH} sch export bom {sch_file_path} --output {bom_output_path}',
shell=True,
stdout=STDOUT
stdout=KICAD_CLI_STDOUT
)
if (retcode != 0):
@@ -142,7 +150,7 @@ class KicadProject:
retcode = subprocess.call(
f'{KICAD_CLI_PATH} pcb render {pcb_file_path} --output {render_output_path} --preset {preset} --zoom {zoom} ',
shell=True,
stdout=STDOUT
stdout=KICAD_CLI_STDOUT
)
if (retcode != 0):
@@ -158,7 +166,7 @@ class KicadProject:
retcode = subprocess.call(
f'{KICAD_CLI_PATH} sch export pdf {sch_file_path} --output {sch_report_path}',
shell=True,
stdout=STDOUT
stdout=KICAD_CLI_STDOUT
)
if (retcode != 0):
@@ -173,7 +181,7 @@ class KicadProject:
retcode = subprocess.call(
f'{KICAD_CLI_PATH} pcb export pdf {pcb_file_path} --output {pcb_report_path} --layers {",".join(layers)}',
shell=True,
stdout=STDOUT
stdout=KICAD_CLI_STDOUT
)
if (retcode != 0):
@@ -189,13 +197,12 @@ def commit_files(files: list[Path], commit_message : str) -> None:
ret_add = subprocess.call(f"git add {file}", shell=True)
ret_commit = subprocess.call(f"git commit -m \"{commit_message}\"", shell=True)
def main() -> None:
# find all kicad project files to operate on
for path in Path(".").rglob('*.kicad_pro'):
k = KicadProject(path)
k.drc_check(report_format=OutputReportType.RPT)
k.erc_check(report_format=OutputReportType.RPT)
k.drc_check(report_format= OutputReportType.REPORT)
k.erc_check(report_format= OutputReportType.REPORT)
k.process_bom()
k.create_schmatic_pdf()
k.get_image()