Rakefile: add notes target

This commit is contained in:
King Kévin 2019-12-17 00:48:29 +01:00
parent 2efd234f3b
commit f3b46626dd
1 changed files with 52 additions and 0 deletions

View File

@ -7,6 +7,7 @@ uses Lepton EDA for schematic and pcb-rnd for board layouts.
Rakefile instead of Makefile for better text file parsing capabilities.
=end
require 'rake/clean'
require 'csv' # to export BOM and costs
# =================
# project variables
@ -90,6 +91,11 @@ net = [ "#{name}.tdx" ]
task :netlist => net
CLOBBER.include(net)
desc "export notes from schematic"
notes = [ "#{name}.notes.txt" ]
task :notes => notes
CLOBBER.include(notes)
# ===============
# file generation
# ===============
@ -134,3 +140,49 @@ rule ".tdx" => ".sch" do |t|
sh "lepton-netlist -g tEDAx -o #{t.name} #{t.source} 2> /dev/null"
end
desc "generate note file from schematic, listing the 'note' attributes from elements"
rule ".notes.txt" => ".sch" do |t|
notes_data = bom2(t.prerequisites[0], ["note", "value"])
File.open(t.name,"w") do |notes_file|
notes_data.each do |note|
next unless note['note']
note['note'] = note['note'].gsub('. ',".\n").gsub(/\n+$/,'')
notes_file.puts "#{note['value']} (#{note['refdes']}):\n#{note['note']}\n\n"
end
end
end
# ================
# helper functions
# ================
# generate gnetlist bom2 and parse them
# arguments: schematic=schematic to use, attributes=attributes to use for generating bom2
# returns an array of hash. key is the attribute name, value is the attribute value
def bom2(schematic, attributes)
to_return = []
# force attributes to be an array
attributes = case attributes
when String
[attributes]
when Array
attributes
else
[attributes.to_s]
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
# parse bom2
csv = CSV.parse(list,{:col_sep => ":"})
csv[1..-1].each do |row|
line = {}
row.each_index do |col|
line[csv[0][col]] = row[col] unless row[col] == "unknown"
end
to_return << line
end
return to_return
end