Merge remote-tracking branch 'hw-template/master'

This commit is contained in:
King Kévin 2014-04-02 17:15:57 +02:00
commit e5b087b1b3
1 changed files with 23 additions and 23 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
@ -38,11 +44,11 @@ end
# ==========
desc "main building task"
task :default => [:version,:print,:notes,:photo,:gerber]
task :default => [:version,:print,:notes,:gerber]
desc "create release file"
release = "hardware-release_v#{version}.tar.gz"
task :release => [:gerber,release]
task :release => [:gerber,:photo,release]
CLOBBER.include(release)
desc "set version in schematic and layout"
@ -90,8 +96,11 @@ task :sch2pcb do
sh "gsch2pcb #{target[:sch]} --elements-dir #{File.dirname(__FILE__)}/lib/footprints --skip-m4 --output-name #{target[:name]}"
end
end
CLOBBER.include("*.net")
CLOBBER.include("*.new.pcb")
targets.each do |target|
CLOBBER.include("#{target[:name]}.net")
CLOBBER.include("#{target[:name]}.cmd")
CLOBBER.include("#{target[:name]}.new.pcb")
end
photos = targets.collect{|target| ["#{target[:name]}_layout-top.png","#{target[:name]}_layout-bottom.png"]}.flatten
desc "render layout"
@ -131,7 +140,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 +152,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 = {}
row.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
end
CLEAN.include("attribs")
# ===============
# file generation
@ -223,8 +223,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