Skip to content

Instantly share code, notes, and snippets.

@Shinichi-Ohki
Created March 31, 2015 04:10
Show Gist options
  • Save Shinichi-Ohki/682334a6a0422e1feba8 to your computer and use it in GitHub Desktop.
Save Shinichi-Ohki/682334a6a0422e1feba8 to your computer and use it in GitHub Desktop.
Eagleのライブラリを再帰的に探して、登録されている部品名を出力するRubyスクリプト
#!/usr/bin/env ruby
require 'rexml/document'
def libdevicelist(partslibrary)
devicelist = []
partslibrary.elements.each('eagle/drawing/library/devicesets/deviceset') do |element|
devicelist << element.attributes["name"]
end
return devicelist
end
def checklbr(file_path)
File.open(file_path,'rb') do |file|
head = file.read(5)
return true if (head == "<?xml")
return false
end
end
files = Dir.glob("#{ARGV[0]}**/*.lbr")
files.each do |filename|
if checklbr(filename) then
partslib = REXML::Document.new(open(filename))
puts File.absolute_path(filename)
libdevicelist(partslib).each do |lib|
print "\t#{lib}\n"
end
else
puts "[#{filename}] is old version library."
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment