eeschema: Fix python BOM generators to handle symbols
* Implement proper natural sorting of the reference values * Perform quoting of all items in BOM generators that use csv.writer Fixes: lp:1833822 * https://bugs.launchpad.net/kicad/+bug/1833822
This commit is contained in:
parent
a498d7e9c5
commit
3b645ed305
|
@ -36,7 +36,7 @@ except IOError:
|
|||
|
||||
# Create a new csv writer object to use as the output formatter, although we
|
||||
# are created a tab delimited list instead!
|
||||
out = csv.writer(f, lineterminator='\n', delimiter='\t', quoting=csv.QUOTE_NONE)
|
||||
out = csv.writer(f, lineterminator='\n', delimiter='\t', quotechar="\"", quoting=csv.QUOTE_ALL)
|
||||
|
||||
# override csv.writer's writerow() to support utf8 encoding:
|
||||
def writerow( acsvwriter, columns ):
|
||||
|
|
|
@ -618,10 +618,14 @@ class netlist():
|
|||
if not exclude:
|
||||
ret.append(c)
|
||||
|
||||
# Sort first by ref as this makes for easier to read BOM's
|
||||
def f(v):
|
||||
return re.sub(r'([A-z]+)[0-9]+', r'\1', v) + '%08i' % int(re.sub(r'[A-z]+([0-9]+)', r'\1', v))
|
||||
ret.sort(key=lambda g: f(g.getRef()))
|
||||
# The key to sort the components in the BOM
|
||||
# This sorts using a natural sorting order (e.g. 100 after 99), and if it wasn't used
|
||||
# the normal sort would place 100 before 99 since it only would look at the first digit.
|
||||
def sortKey( str ):
|
||||
return [ int(t) if t.isdigit() else t.lower()
|
||||
for t in re.split( '(\d+)', str ) ]
|
||||
|
||||
ret.sort(key=lambda g: sortKey(g.getRef()))
|
||||
|
||||
return ret
|
||||
|
||||
|
@ -660,15 +664,18 @@ class netlist():
|
|||
# Add the new component group to the groups list
|
||||
groups.append(newgroup)
|
||||
|
||||
# Each group is a list of components, we need to sort each list first
|
||||
# to get them in order as this makes for easier to read BOM's
|
||||
def f(v):
|
||||
return re.sub(r'([A-z]+)[0-9]+', r'\1', v) + '%08i' % int(re.sub(r'[A-z]+([0-9]+)', r'\1', v))
|
||||
# The key to sort the components in the BOM
|
||||
# This sorts using a natural sorting order (e.g. 100 after 99), and if it wasn't used
|
||||
# the normal sort would place 100 before 99 since it only would look at the first digit.
|
||||
def sortKey( str ):
|
||||
return [ int(t) if t.isdigit() else t.lower()
|
||||
for t in re.split( '(\d+)', str ) ]
|
||||
|
||||
for g in groups:
|
||||
g = sorted(g, key=lambda g: f(g.getRef()))
|
||||
g = sorted(g, key=lambda g: sortKey(g.getRef()))
|
||||
|
||||
# Finally, sort the groups to order the references alphabetically
|
||||
groups = sorted(groups, key=lambda group: f(group[0].getRef()))
|
||||
groups = sorted(groups, key=lambda group: sortKey(group[0].getRef()))
|
||||
|
||||
return groups
|
||||
|
||||
|
|
Loading…
Reference in New Issue