← Back to team overview

kicad-developers team mailing list archive

Re: Are the python BOMmers case sensitive?


On Thu, Sep 19, 2013 at 04:28:17PM +0200, Lorenzo Marcantonio wrote:
> so something like c.getRef().encode('utf8') and so one probably would do
> the trick. BTW I'm perfectly fine with the xslt generators, so I'll try
> this and only if it work at the first try I'll do a patch for it.

This solve the unicode issue (absolutely no elegance whatsoever, but I hope
there is something like mapcar in python). Also it seems to exist a unicodecvs
module which does the trick (but I don't have it)

=== modified file 'scripts/bom-in-python/bom_csv_by_ref_v2.py'
--- scripts/bom-in-python/bom_csv_by_ref_v2.py  2013-09-01 17:49:01 +0000
+++ scripts/bom-in-python/bom_csv_by_ref_v2.py  2013-09-19 14:33:32 +0000
@@ -27,8 +27,10 @@
 out = csv.writer(f, lineterminator='\n', delimiter=',', quotechar="\"", quoting=csv.QUOTE_ALL)
 # Output a field delimited header line
-out.writerow(['Source:', net.getSource()])
-out.writerow(['Date:', net.getDate()])
+out.writerow(['Source:', net.getSource().encode('utf8')])
+out.writerow(['Date:', net.getDate().encode('utf8')])
+# Hope that the kicad version string will never need utf8 encoding...
 out.writerow(['Tool:', net.getTool()])
 out.writerow(['Component Count:', len(net.components)])
 out.writerow(['Ref', 'Value', 'Footprint', 'Datasheet', 'Manufacturer', 'Vendor'])
@@ -36,7 +38,13 @@
 components = net.getInterestingComponents()
 # Output all of the component information (One component per row)
+# Probably you could apply the encode('utf8') as a map operation but
+# I have no idea of the python syntax
 for c in components:
-    out.writerow([c.getRef(), c.getValue(), c.getFootprint(), c.getDatasheet(),
-        c.getField("Manufacturer"), c.getField("Vendor")])
+    out.writerow([c.getRef().encode('utf8'), 
+        c.getValue().encode('utf8'), 
+        c.getFootprint().encode('utf8'), 
+        c.getDatasheet().encode('utf8'),
+        c.getField("Manufacturer").encode('utf8'), 
+        c.getField("Vendor").encode('utf8')])

Lorenzo Marcantonio
Logos Srl

Follow ups