changed how bom2 works (does not use attribs anymore; simplified using CSV)

This commit is contained in:
King Kévin 2014-04-02 17:03:20 +02:00
parent 31a9080fac
commit 49bb4caf75
1 changed files with 17 additions and 20 deletions

View File

@ -1,4 +1,10 @@
# encoding: utf-8
# ruby: 2.1.0
=begin
Rakefile to manage gEDA hardware projects
=end
require 'rake/clean'
require 'csv'
# =================
# project variables
@ -131,7 +137,7 @@ end
# generate gnetlist bom2 and parse them
# 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)
to_return = []
# force attributes to be an array
@ -143,28 +149,19 @@ def bom2(schematic, attributes)
else
[attributes.to_s]
end
# create gnetlist backend
File.open("attribs","w") do |attribs|
attributes.each do |attribute|
attribs.puts attribute
end
end
# generate bom2
list = `gnetlist -g bom2 -q -o - #{schematic}`
list = `gnetlist -g bom2 -Oattribs=#{attributes*','} -q -o - #{schematic}`
# parse bom2
regex = /^(?<refdes>(\w+,?)+):(?<attributes>.*):(?<qty>\d+)$/
list.each_line do |line|
next unless line =~ regex
data = line.match regex
hash = {refdes: data[:refdes].split(',')}
attributes.each_index do |i|
hash.merge!({attributes[i] => data[:attributes].split(':')[i]})
csv = CSV.parse(list,:col_sep => ":")
csv[1..-1].each do |row|
line = {}
line.each_index do |col|
line[csv[0][col]] = row[col] unless row[col]=="unknown"
end
to_return << hash
to_return << line
end
return to_return
return csv
end
CLEAN.include("attribs")
# ===============
# file generation
@ -223,8 +220,8 @@ targets.each do |target|
notes_data = bom2(t.prerequisites[0],"note")
File.open(t.name,"w") do |notes_file|
notes_data.each do |note|
next if note["note"]=="unknown"
notes_file.puts "#{note[:refdes]*','}:\n#{note["note"]}\n\n"
next unless note['note']
notes_file.puts "#{note['refdes']}:\n#{note['note']}\n\n"
end
end
end