Skip to content

Commit 6a5523e

Browse files
committed
Add fabrication output directory to search list for netlist/xml
Fixes #102
1 parent 97755c3 commit 6a5523e

File tree

5 files changed

+35
-10
lines changed

5 files changed

+35
-10
lines changed

InteractiveHtmlBom/core/ibom.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ def save_config(dialog_panel):
302302
)
303303
try:
304304
config.netlist_initial_directory = os.path.dirname(parser.file_name)
305-
extra_data_file = parser.latest_extra_data
305+
extra_data_file = parser.latest_extra_data()
306306
if extra_data_file is not None:
307307
dlg.set_extra_data_path(extra_data_file)
308308
config.transfer_to_dialog(dlg.panel)

InteractiveHtmlBom/dialog_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
class MyApp(wx.App):
55
def OnInit(self):
6-
frame = SettingsDialog(None, lambda x: None)
6+
frame = SettingsDialog(lambda: None, lambda x: None, "Hi")
77
if frame.ShowModal() == wx.ID_OK:
88
print("Should generate bom")
99
frame.Destroy()

InteractiveHtmlBom/ecad/common.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ def __init__(self, file_name, logger):
1313
self.file_name = file_name
1414
self.logger = logger
1515
self.extra_data_func = lambda f, b: ([], {})
16-
self.latest_extra_data = None
1716

1817
def parse(self):
1918
"""
@@ -25,6 +24,14 @@ def parse(self):
2524
"""
2625
pass
2726

27+
def latest_extra_data(self):
28+
"""
29+
Abstract method that may be overridden in implementations that support
30+
extra field data.
31+
:return: File name of most recent file with extra field data.
32+
"""
33+
return None
34+
2835

2936
class Component(object):
3037
"""Simple data object to store component data needed for bom table."""

InteractiveHtmlBom/ecad/kicad.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,22 @@ class PcbnewParser(EcadParser):
1515
def __init__(self, file_name, logger, board=None):
1616
super(PcbnewParser, self).__init__(file_name, logger)
1717
self.board = board
18+
if self.board is None:
19+
self.board = pcbnew.LoadBoard(self.file_name) # type: pcbnew.BOARD
1820
self.font_parser = FontParser()
1921
self.extra_data_func = parse_schematic_data
20-
self.latest_extra_data = find_latest_schematic_data(file_name)
22+
23+
def latest_extra_data(self):
24+
base_name = os.path.splitext(os.path.basename(self.file_name))[0]
25+
output_dir = self.board.GetPlotOptions().GetOutputDirectory()
26+
file_dir_name = os.path.dirname(self.file_name)
27+
if not os.path.isabs(output_dir):
28+
output_dir = os.path.join(file_dir_name, output_dir)
29+
directories = [
30+
file_dir_name,
31+
output_dir
32+
]
33+
return find_latest_schematic_data(base_name, directories)
2134

2235
@staticmethod
2336
def normalize(point):
@@ -344,8 +357,6 @@ def module_to_component(module):
344357
attr)
345358

346359
def parse(self):
347-
if self.board is None:
348-
self.board = pcbnew.LoadBoard(self.file_name)
349360
title_block = self.board.GetTitleBlock()
350361
file_date = title_block.GetDate()
351362
if not file_date:

InteractiveHtmlBom/ecad/kicad_extra/__init__.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,20 @@ def parse_schematic_data(file_name, normalize_case):
2020
return parser.parse(normalize_case)
2121

2222

23-
def find_latest_schematic_data(pcb_file):
23+
def find_latest_schematic_data(base_name, directories):
2424
"""
25-
:param pcb_file: path to the pcb file
25+
:param base_name: base name of pcb file
26+
:param directories: list of directories to search
2627
:return: last modified parsable file path or None if not found
2728
"""
28-
dir = os.path.dirname(pcb_file)
29+
for dir in directories:
30+
f = _find_in_dir(base_name, dir)
31+
if f:
32+
return f
33+
return None
34+
35+
36+
def _find_in_dir(base_name, dir):
2937
_, _, files = next(os.walk(dir), (None, None, []))
3038
# filter out files that we can not parse
3139
files = [f for f in files if os.path.splitext(f)[1] in PARSERS.keys()]
@@ -34,7 +42,6 @@ def find_latest_schematic_data(pcb_file):
3442
files = sorted(files, reverse=True)
3543
if files:
3644
# try to find first (last modified) file that has name matching pcb file
37-
base_name = os.path.splitext(os.path.basename(pcb_file))[0]
3845
for _, f in files:
3946
if os.path.splitext(f)[0] == base_name:
4047
return os.path.join(dir, f)

0 commit comments

Comments
 (0)