Commit 1e8430d5 authored by Dick Hollenbeck's avatar Dick Hollenbeck

Lorenzo's help enabled a fix to UTF8 support in csv.writer in python bom generators.

parent c7531d6c
......@@ -27,16 +27,23 @@ except IOError:
# are created a tab delimited list instead!
out = csv.writer(f, lineterminator='\n', delimiter='\t', quoting=csv.QUOTE_NONE)
# override csv.writer's writerow() to support utf8 encoding:
def writerow( acsvwriter, columns ):
utf8row = []
for col in columns:
utf8row.append( str(col).encode('utf8') )
acsvwriter.writerow( utf8row )
# Output a field delimited header line
out.writerow(['Source:', net.getSource()])
out.writerow(['Date:', net.getDate()])
out.writerow(['Tool:', net.getTool()])
out.writerow(['Component Count:', len(net.components)])
out.writerow(['Ref', 'Value', 'Part', 'Documentation', 'Description', 'Vendor'])
writerow( out, ['Source:', net.getSource()] )
writerow( out, ['Date:', net.getDate()] )
writerow( out, ['Tool:', net.getTool()] )
writerow( out, ['Component Count:', len(net.components)] )
writerow( out, ['Ref', 'Value', 'Part', 'Documentation', 'Description', 'Vendor'] )
components = net.getInterestingComponents()
# Output all of the component information
for c in components:
out.writerow([c.getRef(), c.getValue(), c.getLibName() + ":" + c.getPartName(),
writerow( out, [c.getRef(), c.getValue(), c.getLibName() + ":" + c.getPartName(),
c.getDatasheet(), c.getDescription(), c.getField("Vendor")])
......@@ -26,17 +26,24 @@ except IOError:
# Create a new csv writer object to use as the output formatter
out = csv.writer(f, lineterminator='\n', delimiter=',', quotechar="\"", quoting=csv.QUOTE_ALL)
# override csv.writer's writerow() to support utf8 encoding:
def writerow( acsvwriter, columns ):
utf8row = []
for col in columns:
utf8row.append( str(col).encode('utf8') )
acsvwriter.writerow( utf8row )
# Output a field delimited header line
out.writerow(['Source:', net.getSource()])
out.writerow(['Date:', net.getDate()])
out.writerow(['Tool:', net.getTool()])
out.writerow(['Component Count:', len(net.components)])
out.writerow(['Ref', 'Value', 'Footprint', 'Datasheet', 'Manufacturer', 'Vendor'])
writerow( out, ['Source:', net.getSource()] )
writerow( out, ['Date:', net.getDate()] )
writerow( out, ['Tool:', net.getTool()] )
writerow( out, ['Component Count:', len(net.components)] )
writerow( out, ['Ref', 'Value', 'Footprint', 'Datasheet', 'Manufacturer', 'Vendor'] )
components = net.getInterestingComponents()
# Output all of the component information (One component per row)
for c in components:
out.writerow([c.getRef(), c.getValue(), c.getFootprint(), c.getDatasheet(),
writerow( out, [c.getRef(), c.getValue(), c.getFootprint(), c.getDatasheet(),
c.getField("Manufacturer"), c.getField("Vendor")])
......@@ -47,15 +47,22 @@ columns = ['Item', 'Qty', 'Reference(s)', 'Value', 'LibPart', 'Footprint', 'Data
# Create a new csv writer object to use as the output formatter
out = csv.writer(f, lineterminator='\n', delimiter=',', quotechar='\"', quoting=csv.QUOTE_MINIMAL)
# override csv.writer's writerow() to support utf8 encoding:
def writerow( acsvwriter, columns ):
utf8row = []
for col in columns:
utf8row.append( str(col).encode('utf8') )
acsvwriter.writerow( utf8row )
# Output a set of rows as a header providing general information
out.writerow(['Source:', net.getSource()])
out.writerow(['Date:', net.getDate()])
out.writerow(['Tool:', net.getTool()])
out.writerow(['Component Count:', len(components)])
out.writerow([])
out.writerow(['Individual Components:'])
out.writerow([]) # blank line
out.writerow(columns)
writerow( out, ['Source:', net.getSource()] )
writerow( out, ['Date:', net.getDate()] )
writerow( out, ['Tool:', net.getTool()] )
writerow( out, ['Component Count:', len(components)] )
writerow( out, [] )
writerow( out, ['Individual Components:'] )
writerow( out, [] ) # blank line
writerow( out, columns )
# Output all the interesting components individually first:
row = []
......@@ -74,16 +81,16 @@ for c in components:
for field in columns[7:]:
row.append( c.getField( field ) );
out.writerow(row)
writerow( out, row )
out.writerow([]) # blank line
out.writerow([]) # blank line
out.writerow([]) # blank line
writerow( out, [] ) # blank line
writerow( out, [] ) # blank line
writerow( out, [] ) # blank line
out.writerow(['Collated Components:'])
out.writerow([]) # blank line
out.writerow(columns) # reuse same columns
writerow( out, ['Collated Components:'] )
writerow( out, [] ) # blank line
writerow( out, columns ) # reuse same columns
......@@ -121,6 +128,6 @@ for group in grouped:
for field in columns[7:]:
row.append( net.getGroupField(group, field) );
out.writerow( row )
writerow( out, row )
f.close()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment