Skip to content

Commit

Permalink
Add Description field parsing'
Browse files Browse the repository at this point in the history
  • Loading branch information
qu1ck committed Mar 5, 2021
1 parent 0195f14 commit 034cde1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
12 changes: 10 additions & 2 deletions InteractiveHtmlBom/ecad/kicad_extra/netlistparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,27 @@ def get_extra_field_data(self):
ref = None
fields = None
datasheet = None
libsource = None
for f in c[1:]:
if f[0] == 'ref':
ref = f[1]
if f[0] == 'fields':
fields = f[1:]
if f[0] == 'datasheet':
datasheet = f[1]
if f[0] == 'libsource':
libsource = f[1:]
if ref is None:
return None
ref_fields = comp_dict.setdefault(ref, {})
if datasheet and datasheet != '~':
field_set.add('datasheet')
ref_fields['datasheet'] = datasheet
field_set.add('Datasheet')
ref_fields['Datasheet'] = datasheet
if libsource is not None:
for lib_field in libsource:
if lib_field[0] == 'description':
field_set.add('Description')
ref_fields['Description'] = lib_field[1]
if fields is None:
continue
for f in fields:
Expand Down
3 changes: 1 addition & 2 deletions InteractiveHtmlBom/ecad/kicad_extra/parser_base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
class ParserBase:
DEFAULT_FIELDS = []

def __init__(self, file_name):
"""
Expand Down Expand Up @@ -29,7 +28,7 @@ def parse(self, normalize_case):
def get_extra_field_data(self):
# type: () -> tuple
"""
Parses the file and returns a extra field data.
Parses the file and returns extra field data.
:return: tuple of the format
(
[field_name1, field_name2,... ],
Expand Down
14 changes: 9 additions & 5 deletions InteractiveHtmlBom/ecad/kicad_extra/xmlparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,16 @@ def get_extra_field_data(self):
if datasheet:
datasheet = self.get_text(datasheet[0].childNodes)
if datasheet != '~':
field_set.add('datasheet')
ref_fields['datasheet'] = datasheet
field_set.add('Datasheet')
ref_fields['Datasheet'] = datasheet
libsource = c.getElementsByTagName('libsource')
if libsource and libsource[0].hasAttribute('description'):
field_set.add('Description')
attr = libsource[0].attributes['description']
ref_fields['Description'] = attr.value
for f in c.getElementsByTagName('field'):
name = f.attributes['name'].value
if name not in self.DEFAULT_FIELDS:
field_set.add(name)
ref_fields[name] = self.get_text(f.childNodes)
field_set.add(name)
ref_fields[name] = self.get_text(f.childNodes)

return list(field_set), comp_dict

0 comments on commit 034cde1

Please sign in to comment.