changed how bom2 works (does not use attribs anymore; simplified using CSV)
This commit is contained in:
parent
63e548ce35
commit
9ef9e6f4ad
|
@ -1,4 +1,10 @@
|
||||||
|
# encoding: utf-8
|
||||||
|
# ruby: 2.1.0
|
||||||
|
=begin
|
||||||
|
Rakefile to manage gEDA hardware projects
|
||||||
|
=end
|
||||||
require 'rake/clean'
|
require 'rake/clean'
|
||||||
|
require 'csv'
|
||||||
|
|
||||||
# =================
|
# =================
|
||||||
# project variables
|
# project variables
|
||||||
|
@ -131,7 +137,7 @@ end
|
||||||
|
|
||||||
# generate gnetlist bom2 and parse them
|
# generate gnetlist bom2 and parse them
|
||||||
# arguments: schematic=schematic to use, attributes=the attributes to use for generating bom2
|
# arguments: schematic=schematic to use, attributes=the attributes to use for generating bom2
|
||||||
# return [{:refdes => [refdes of component], <attributes> => text of attributes}]
|
# returns an array of hash. key is the attribute name, value is the attribute value
|
||||||
def bom2(schematic, attributes)
|
def bom2(schematic, attributes)
|
||||||
to_return = []
|
to_return = []
|
||||||
# force attributes to be an array
|
# force attributes to be an array
|
||||||
|
@ -143,28 +149,19 @@ def bom2(schematic, attributes)
|
||||||
else
|
else
|
||||||
[attributes.to_s]
|
[attributes.to_s]
|
||||||
end
|
end
|
||||||
# create gnetlist backend
|
|
||||||
File.open("attribs","w") do |attribs|
|
|
||||||
attributes.each do |attribute|
|
|
||||||
attribs.puts attribute
|
|
||||||
end
|
|
||||||
end
|
|
||||||
# generate bom2
|
# generate bom2
|
||||||
list = `gnetlist -g bom2 -q -o - #{schematic}`
|
list = `gnetlist -g bom2 -Oattribs=#{attributes*','} -q -o - #{schematic}`
|
||||||
# parse bom2
|
# parse bom2
|
||||||
regex = /^(?<refdes>(\w+,?)+):(?<attributes>.*):(?<qty>\d+)$/
|
csv = CSV.parse(list,:col_sep => ":")
|
||||||
list.each_line do |line|
|
csv[1..-1].each do |row|
|
||||||
next unless line =~ regex
|
line = {}
|
||||||
data = line.match regex
|
line.each_index do |col|
|
||||||
hash = {refdes: data[:refdes].split(',')}
|
line[csv[0][col]] = row[col] unless row[col]=="unknown"
|
||||||
attributes.each_index do |i|
|
|
||||||
hash.merge!({attributes[i] => data[:attributes].split(':')[i]})
|
|
||||||
end
|
end
|
||||||
to_return << hash
|
to_return << line
|
||||||
end
|
end
|
||||||
return to_return
|
return csv
|
||||||
end
|
end
|
||||||
CLEAN.include("attribs")
|
|
||||||
|
|
||||||
# ===============
|
# ===============
|
||||||
# file generation
|
# file generation
|
||||||
|
@ -223,8 +220,8 @@ targets.each do |target|
|
||||||
notes_data = bom2(t.prerequisites[0],"note")
|
notes_data = bom2(t.prerequisites[0],"note")
|
||||||
File.open(t.name,"w") do |notes_file|
|
File.open(t.name,"w") do |notes_file|
|
||||||
notes_data.each do |note|
|
notes_data.each do |note|
|
||||||
next if note["note"]=="unknown"
|
next unless note['note']
|
||||||
notes_file.puts "#{note[:refdes]*','}:\n#{note["note"]}\n\n"
|
notes_file.puts "#{note['refdes']}:\n#{note['note']}\n\n"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue