Created
March 31, 2015 04:10
-
-
Save Shinichi-Ohki/682334a6a0422e1feba8 to your computer and use it in GitHub Desktop.
Eagleのライブラリを再帰的に探して、登録されている部品名を出力するRubyスクリプト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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