Skip to content

Commit 81618dc

Browse files
committed
Prioritize files with matching names when picking netlist/xml
1 parent 335444a commit 81618dc

File tree

3 files changed

+20
-15
lines changed

3 files changed

+20
-15
lines changed

InteractiveHtmlBom/dialog/settings_dialog.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ def SetSizeHints(self, sz1, sz2):
2626
self.SetSizeHintsSz(sz1, sz2)
2727

2828
def set_extra_data_path(self, extra_data_file):
29-
print extra_data_file
3029
self.panel.extra.netlistFilePicker.Path = extra_data_file
3130
wx.CallAfter(self.panel.extra.OnNetlistFileChanged, None)
3231

InteractiveHtmlBom/generate_interactive_bom.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -529,10 +529,6 @@ def get_file_content(file_name):
529529
def main(pcb, config):
530530
# type: (pcbnew.BOARD, Config) -> None
531531
pcb_file_name = pcb.GetFileName()
532-
if not pcb_file_name:
533-
logerror('Please save the board file before generating BOM.')
534-
return
535-
536532
# Get extra field data
537533
extra_fields = None
538534
if config.netlist_file and os.path.isfile(config.netlist_file):
@@ -620,12 +616,15 @@ def defaults(self):
620616

621617
def Run(self):
622618
config = Config()
619+
pcb_file_name = pcbnew.GetBoard().GetFileName()
620+
if not pcb_file_name:
621+
logerror('Please save the board file before generating BOM.')
622+
return
623+
623624
dlg = dialog.SettingsDialog(None, extra_data_func=parse_schematic_data)
624625
try:
625-
config.netlist_initial_directory = os.path.dirname(
626-
pcbnew.GetBoard().GetFileName())
627-
extra_data_file = find_latest_schematic_data(
628-
config.netlist_initial_directory)
626+
config.netlist_initial_directory = os.path.dirname(pcb_file_name)
627+
extra_data_file = find_latest_schematic_data(pcb_file_name)
629628
if extra_data_file is not None:
630629
dlg.set_extra_data_path(extra_data_file)
631630
config.transfer_to_dialog(dlg.panel)

InteractiveHtmlBom/schematic_data/__init__.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,25 @@ def parse_schematic_data(file_name):
2020
return parser.get_extra_field_data()
2121

2222

23-
def find_latest_schematic_data(dir):
23+
def find_latest_schematic_data(pcb_file):
2424
"""
25-
:param dir: directory of the pcb file
25+
:param pcb_file: path to the pcb file
2626
:return: last modified parsable file path or None if not found
2727
"""
28+
dir = os.path.dirname(pcb_file)
2829
_, _, files = next(os.walk(dir), (None, None, []))
29-
# filter out files that we can parse
30+
# filter out files that we can not parse
3031
files = [f for f in files if os.path.splitext(f)[1] in PARSERS.keys()]
31-
# get their mtime and pick the latest one
32+
# get their modification time and sort in descending order
3233
files = [(os.path.getmtime(os.path.join(dir, f)), f) for f in files]
33-
print files
34+
files = sorted(files, reverse=True)
3435
if files:
35-
return os.path.join(dir, sorted(files, reverse=True)[0][1])
36+
# 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]
38+
for _, f in files:
39+
if os.path.splitext(f)[0] == base_name:
40+
return os.path.join(dir, f)
41+
# if no such file is found just return last modified
42+
return os.path.join(dir, files[0][1])
3643
else:
3744
return None

0 commit comments

Comments
 (0)