This commit is contained in:
2025-12-31 11:48:04 +13:00
parent fcbb5eafc1
commit bca6632809

View File

@@ -21,14 +21,10 @@ PCB_PDF_FILE_SUFFIX = "_pcb"
SCHEMATIC_OUTPUT_PATH = "docs/" SCHEMATIC_OUTPUT_PATH = "docs/"
SCHEMATIC_FILE_SUFFIX = "_schematic" SCHEMATIC_FILE_SUFFIX = "_schematic"
TEMP_DRC_REPORT_NAME = "_drc" TEMP_DRC_REPORT_NAME = "_drc"
TEMP_ERC_REPORT_NAME = "_erc" TEMP_ERC_REPORT_NAME = "_erc"
TEMP_BOM_REPORT_NAME = "_bom" TEMP_BOM_REPORT_NAME = "_bom"
class OutputReportType(Enum): class OutputReportType(Enum):
JSON = 1 JSON = 1
RPT = 2 RPT = 2
@@ -82,13 +78,13 @@ class KicadProject:
if format_type == OutputReportType.RPT: if format_type == OutputReportType.RPT:
return txt.read() return txt.read()
def process_bom(self, return_csv : bool = False) -> None: def process_bom(self, return_csv : bool = False) -> None | list[list[str]]:
sch_file_path = self.project_path / f"{self.project_name}.kicad_sch" sch_file_path = self.project_path / f"{self.project_name}.kicad_sch"
bom_output_path = Path(TEMP_FILE_PATH) / f"{self.project_name}{TEMP_DRC_REPORT_NAME}.csv" bom_output_path = Path(TEMP_FILE_PATH) / f"{self.project_name}{TEMP_DRC_REPORT_NAME}.csv"
subprocess.call( subprocess.call(
f'{KICAD_CLI_PATH} sch export bom {sch_file_path} --output {bom_output_path}', f'{KICAD_CLI_PATH} sch export bom {sch_file_path} --output {bom_output_path}',
shell=True, shell=True,
) )
if (return_csv): if (return_csv):
with open(bom_output_path, "r") as csvfile: with open(bom_output_path, "r") as csvfile:
bom_csv = csv.reader(csvfile, delimiter=',', quotechar='"') bom_csv = csv.reader(csvfile, delimiter=',', quotechar='"')
@@ -115,11 +111,6 @@ class KicadProject:
shell=True, shell=True,
) )
# look i dont know what you want to do
# but here you go
def create_3d_model(self) -> None:
...
# i am not giving you the pdf to output if you want to do that yourself go ahead # i am not giving you the pdf to output if you want to do that yourself go ahead
def create_schmatic_pdf(self) -> None: def create_schmatic_pdf(self) -> None:
sch_file_path = self.project_path / f"{self.project_name}.kicad_sch" sch_file_path = self.project_path / f"{self.project_name}.kicad_sch"
@@ -136,18 +127,6 @@ class KicadProject:
f'{KICAD_CLI_PATH} pcb export pdf {pcb_file_path} --output {pcb_report_path} --layers {",".join(layers)}', f'{KICAD_CLI_PATH} pcb export pdf {pcb_file_path} --output {pcb_report_path} --layers {",".join(layers)}',
shell=True, shell=True,
) )
def export_pcb(self) -> None:
...
def download_datasheets(self) -> None:
...
class Report:
def export() -> str:
...
def main() -> None: def main() -> None:
@@ -158,14 +137,11 @@ def main() -> None:
print(type(path.parent)) print(type(path.parent))
k = KicadProject(path) k = KicadProject(path)
k.drc_check() k.drc_check()
print(k.erc_check(return_report=True)) k.erc_check()
print(k.process_bom(return_csv=True)) k.process_bom()
k.create_schmatic_pdf() k.create_schmatic_pdf()
k.create_pcb_pdf() k.create_pcb_pdf()
k.get_image() k.get_image()
print("hello world"); print("hello world");