Rakefile: add bom target to export bill of material
This commit is contained in:
parent
49deb064e1
commit
77353aa822
|
@ -150,13 +150,21 @@ to export the netlist (in tEDAx format):
|
||||||
rake netlist
|
rake netlist
|
||||||
~~~
|
~~~
|
||||||
|
|
||||||
to export archive (with symbols included in schematic) and pdf:
|
to export as pdf:
|
||||||
~~~
|
~~~
|
||||||
rake print
|
rake print
|
||||||
~~~
|
~~~
|
||||||
|
|
||||||
|
BOM
|
||||||
|
---
|
||||||
|
|
||||||
|
to export the bill of material (as CSV):
|
||||||
|
~~~
|
||||||
|
rake bom
|
||||||
|
~~~
|
||||||
|
|
||||||
board
|
board
|
||||||
-----
|
=====
|
||||||
|
|
||||||
the `usb_cable_test.lht` file is the board layout source file.
|
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/).
|
it has been drawn using [coralEDA pcb-rnd](http://repo.hu/projects/pcb-rnd/).
|
||||||
|
|
|
@ -108,6 +108,11 @@ notes = [ "#{name}.notes.txt" ]
|
||||||
task :notes => notes
|
task :notes => notes
|
||||||
CLOBBER.include(notes)
|
CLOBBER.include(notes)
|
||||||
|
|
||||||
|
desc "export BOMs from schematic"
|
||||||
|
boms = [ "#{name}.bom.csv" ]
|
||||||
|
task :bom => boms
|
||||||
|
CLOBBER.include(boms)
|
||||||
|
|
||||||
# ===============
|
# ===============
|
||||||
# file generation
|
# file generation
|
||||||
# ===============
|
# ===============
|
||||||
|
@ -175,6 +180,19 @@ rule ".notes.txt" => ".sch" do |t|
|
||||||
end
|
end
|
||||||
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
|
# helper functions
|
||||||
# ================
|
# ================
|
||||||
|
@ -195,10 +213,12 @@ def bom2(schematic, attributes)
|
||||||
end
|
end
|
||||||
# generate bom2
|
# generate bom2
|
||||||
list = `lepton-netlist --backend bom2 --backend-option attribs=#{attributes*','} --quiet --output - #{schematic} 2> /dev/null`
|
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 = list.each_line {|l| '"' + l + '"' + '\n' }
|
||||||
list.gsub!(/(https?:\/\/[^:]*):/, '"\1":') # ':' (like in links) are not protected
|
list.gsub!(/^(.+)/, '"\1')
|
||||||
|
list.gsub!(/(.+)$/, '\1"')
|
||||||
|
list.gsub!(/(?!http):(?!\/\/)/, '\1":"\2') # protect the values between ':' (such as URLs)
|
||||||
# parse bom2
|
# parse bom2
|
||||||
csv = CSV.parse(list,{:col_sep => ":"})
|
csv = CSV.parse(list, {:col_sep => ":", :quote_char => '"'})
|
||||||
csv[1..-1].each do |row|
|
csv[1..-1].each do |row|
|
||||||
line = {}
|
line = {}
|
||||||
row.each_index do |col|
|
row.each_index do |col|
|
||||||
|
|
Loading…
Reference in New Issue