Rakefile: add bom target to export bill of material

This commit is contained in:
King Kévin 2019-12-17 15:54:02 +01:00
parent 49deb064e1
commit 77353aa822
2 changed files with 33 additions and 5 deletions

View File

@ -150,13 +150,21 @@ to export the netlist (in tEDAx format):
rake netlist
~~~
to export archive (with symbols included in schematic) and pdf:
to export as pdf:
~~~
rake print
~~~
BOM
---
to export the bill of material (as CSV):
~~~
rake bom
~~~
board
-----
=====
the `usb_cable_test.lht` file is the board layout source file.
it has been drawn using [coralEDA pcb-rnd](http://repo.hu/projects/pcb-rnd/).

View File

@ -108,6 +108,11 @@ notes = [ "#{name}.notes.txt" ]
task :notes => notes
CLOBBER.include(notes)
desc "export BOMs from schematic"
boms = [ "#{name}.bom.csv" ]
task :bom => boms
CLOBBER.include(boms)
# ===============
# file generation
# ===============
@ -175,6 +180,19 @@ rule ".notes.txt" => ".sch" do |t|
end
end
desc "generate BOM file from schematic"
rule ".bom.csv" => ".sch" do |t|
attributes = ["category", "device", "value", "description", "manufacturer", "manufacturer-id", "datasheet", "lcsc-id", "aliexpress-id", "alternatives"]
bom_data = bom2(t.prerequisites[0],attributes)
CSV.open(t.name, "wb") do |csv|
all_attributes = ["refdes","qty"]+attributes
csv << all_attributes
bom_data.each do |line|
csv << all_attributes.collect{|attribute| line[attribute]}
end
end
end
# ================
# helper functions
# ================
@ -195,10 +213,12 @@ def bom2(schematic, attributes)
end
# generate bom2
list = `lepton-netlist --backend bom2 --backend-option attribs=#{attributes*','} --quiet --output - #{schematic} 2> /dev/null`
list.gsub!(/(\d[Mkmµ]?)\?/, '\1Ω') # UTF-8 characters like Ω are replaced with ? by gnetlist
list.gsub!(/(https?:\/\/[^:]*):/, '"\1":') # ':' (like in links) are not protected
list = list.each_line {|l| '"' + l + '"' + '\n' }
list.gsub!(/^(.+)/, '"\1')
list.gsub!(/(.+)$/, '\1"')
list.gsub!(/(?!http):(?!\/\/)/, '\1":"\2') # protect the values between ':' (such as URLs)
# parse bom2
csv = CSV.parse(list,{:col_sep => ":"})
csv = CSV.parse(list, {:col_sep => ":", :quote_char => '"'})
csv[1..-1].each do |row|
line = {}
row.each_index do |col|