From 49bb4caf7548e78935d7cc489906c64cb669418f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?King=20K=C3=A9vin?= Date: Wed, 2 Apr 2014 17:03:20 +0200 Subject: [PATCH] changed how bom2 works (does not use attribs anymore; simplified using CSV) --- hardware/Rakefile | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/hardware/Rakefile b/hardware/Rakefile index 0b0e984..fdbdac9 100644 --- a/hardware/Rakefile +++ b/hardware/Rakefile @@ -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], => 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 = /^(?(\w+,?)+):(?.*):(?\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