Skip to content

Commit b0da3ec

Browse files
authored
Improve .BRD library package lookup (fix #351) (#352)
* Handle multiple libraries with duplicate names (#351) * Eliminate f-strings for kicad 5.1 compatibility
1 parent da654eb commit b0da3ec

File tree

1 file changed

+26
-9
lines changed

1 file changed

+26
-9
lines changed

InteractiveHtmlBom/ecad/fusion_eagle.py

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,9 @@ def __init__(self, rot_string):
111111
if d in string.digits + '.'))
112112

113113
def __str__(self):
114-
return f"Mirrored: {self.mirrored}, " \
115-
f"Spin: {self.spin}, " \
116-
f"Angle: {self.angle}"
114+
return "Mirrored: {0}, Spin: {1}, Angle: {2}".format(self.mirrored,
115+
self.spin,
116+
self.angle)
117117

118118
def _rectangle_vertices(self, el):
119119
# Note: Eagle specifies a rectangle using opposing corners
@@ -782,11 +782,28 @@ def _parse(self, brdfile):
782782
extra_fields=extra_fields)
783783

784784
# For component, get footprint data
785-
library = [lib for lib in board.find('libraries').findall('library')
786-
if lib.attrib['name'] == el.attrib['library']][0]
787-
package = \
788-
[pac for pac in library.find('packages').findall('package')
789-
if pac.attrib['name'] == el.attrib['package']][0]
785+
libs = [lib for lib in board.find('libraries').findall('library')
786+
if lib.attrib['name'] == el.attrib['library']]
787+
packages = []
788+
for lib in libs:
789+
p = [pac for pac in lib.find('packages').findall('package')
790+
if pac.attrib['name'] == el.attrib['package']]
791+
packages.extend(p)
792+
if not packages:
793+
self.logger.error("Package {0} in library {1} not found in "
794+
"source file {2} for element {3}"
795+
.format(el.attrib['package'],
796+
el.attrib['library'],
797+
brdfile.name,
798+
el.attrib['name']))
799+
return None, None
800+
else:
801+
package = packages[0]
802+
if len(packages) > 1:
803+
self.logger.warn("Multiple packages found for package {0}"
804+
" in library {1}, using first instance "
805+
"found".format(el.attrib['package'],
806+
el.attrib['library']))
790807

791808
elx = float(el.attrib['x'])
792809
ely = float(el.attrib['y'])
@@ -835,7 +852,7 @@ def _parse(self, brdfile):
835852
a.get('current') == 'yes']
836853
variant = None if not variant else variant[0]
837854
if variant:
838-
title = f"{title}, Variant: {variant}"
855+
title = "{0}, Variant: {1}".format(title, variant)
839856

840857
date = datetime.fromtimestamp(
841858
os.path.getmtime(self.file_name)).strftime('%Y-%m-%d %H:%M:%S')

0 commit comments

Comments
 (0)