From 46378b992b097902c6441b317d9c2a9968c602e8 Mon Sep 17 00:00:00 2001 From: Diego Capusotto Date: Sat, 18 Dec 2021 11:13:58 -0300 Subject: [PATCH] Added some abstraction for the KiCad project file extension. --- kibot/__main__.py | 2 ++ kibot/gs.py | 1 + kibot/out_base_3d.py | 2 +- kibot/out_pdf_pcb_print.py | 5 ++--- kibot/out_pdf_sch_print.py | 2 +- tests/utils/context.py | 4 +++- 6 files changed, 10 insertions(+), 6 deletions(-) diff --git a/kibot/__main__.py b/kibot/__main__.py index 1acf1456..53c9d633 100644 --- a/kibot/__main__.py +++ b/kibot/__main__.py @@ -257,6 +257,7 @@ def detect_kicad(): # So we just patch it, as we patch the name of the binaries GS.kicad_conf_path = GS.kicad_conf_path.replace('/kicad/', '/kicadnightly/') GS.kicad_share_path = GS.kicad_share_path.replace('/kicad/', '/kicadnightly/') + GS.pro_ext = '.kicad_pro' else: # Bug in KiCad (#6989), prints to stderr: # `../src/common/stdpbase.cpp(62): assert "traits" failed in Get(test_dir): create wxApp before calling this` @@ -264,6 +265,7 @@ def detect_kicad(): # So we temporarily supress stderr with hide_stderr(): GS.kicad_conf_path = pcbnew.GetKicadConfigPath() + GS.pro_ext = '.pro' # Dirs to look for plugins GS.kicad_plugins_dirs = [] # /usr/share/kicad/* diff --git a/kibot/gs.py b/kibot/gs.py index d7dcd9da..2d4f64e2 100644 --- a/kibot/gs.py +++ b/kibot/gs.py @@ -40,6 +40,7 @@ class GS(object): kicad_conf_path = None kicad_share_path = None kicad_plugins_dirs = [] + pro_ext = '.pro' # KiCad version: major*1e6+minor*1e3+patch kicad_version_n = 0 kicad_version_major = 0 diff --git a/kibot/out_base_3d.py b/kibot/out_base_3d.py index 9aaff90b..86313f86 100644 --- a/kibot/out_base_3d.py +++ b/kibot/out_base_3d.py @@ -172,7 +172,7 @@ class Base3DOptions(VariantOptions): fname = f.name logger.debug('Storing modified PCB to `{}`'.format(fname)) GS.board.Save(fname) - with open(fname.replace('.kicad_pcb', '.pro'), 'wt') as f: + with open(fname.replace('.kicad_pcb', GS.pro_ext), 'wt') as f: pass return fname diff --git a/kibot/out_pdf_pcb_print.py b/kibot/out_pdf_pcb_print.py index c449ea5a..ed65e734 100644 --- a/kibot/out_pdf_pcb_print.py +++ b/kibot/out_pdf_pcb_print.py @@ -65,11 +65,10 @@ class PDF_Pcb_PrintOptions(VariantOptions): @staticmethod def _copy_project(fname): - pro_ext = '.kicad_pro' if GS.ki6() else '.pro' - pro_name = GS.pcb_file.replace('.kicad_pcb', pro_ext) + pro_name = GS.pcb_file.replace('.kicad_pcb', GS.pro_ext) if not os.path.isfile(pro_name): return None - pro_copy = fname.replace('.kicad_pcb', pro_ext) + pro_copy = fname.replace('.kicad_pcb', GS.pro_ext) logger.debug('Copying project `{}` to `{}`'.format(pro_name, pro_copy)) copy2(pro_name, pro_copy) return pro_copy diff --git a/kibot/out_pdf_sch_print.py b/kibot/out_pdf_sch_print.py index 34ea6bbe..1ba3946b 100644 --- a/kibot/out_pdf_sch_print.py +++ b/kibot/out_pdf_sch_print.py @@ -18,7 +18,7 @@ logger = log.get_logger(__name__) def copy_project(sch_dir): """ Copy the project file to the temporal dir """ - ext = '.pro' + ext = GS.pro_ext source = GS.sch_no_ext+ext prj_file = os.path.join(sch_dir, GS.sch_basename+ext) if os.path.isfile(source): diff --git a/tests/utils/context.py b/tests/utils/context.py index c7324368..e562eedd 100644 --- a/tests/utils/context.py +++ b/tests/utils/context.py @@ -48,6 +48,7 @@ if kicad_version >= KICAD_VERSION_5_99: DEF_DWGSU = 'User_Drawings' DEF_ECO1U = 'User_Eco1' DEF_ECO2U = 'User_Eco2' + PRO_EXT = '.kicad_pro' else: BOARDS_DIR = '../board_samples/kicad_5' KICAD_SCH_EXT = '.sch' @@ -63,6 +64,7 @@ else: REF_DIR = 'tests/reference/5_1_7' else: REF_DIR = 'tests/reference/5_1_6' + PRO_EXT = '.pro' logging.debug('Detected KiCad v{}.{}.{} ({})'.format(kicad_major, kicad_minor, kicad_patch, kicad_version)) @@ -162,7 +164,7 @@ class TestContext(object): logging.debug('Removing dir') shutil.rmtree(self.output_dir) # We don't have a project, and we don't want one - pro = os.path.join(self.get_board_dir(), self.board_name+'.pro') + pro = os.path.join(self.get_board_dir(), self.board_name+PRO_EXT) if os.path.isfile(pro) and not keep_project: os.remove(pro) # We don't have a footprint cache, and we don't want one