Created
February 23, 2015 22:17
-
-
Save ilyakava/b7268ad6461de9e80ff4 to your computer and use it in GitHub Desktop.
ruby parser for scala dependency xmls
This file contains hidden or 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
# input is an default-*-build-compile.xml generated by scala/sbt | |
# output is a csv with headers: name version homepage summary license license_url org | |
require 'nokogiri' | |
require 'csv' | |
infile = ARGV[0] | |
infile_name = infile.split('.')[0..-2].join('.') | |
f = File.open(ARGV[0]) | |
doc = Nokogiri::XML(f) | |
f.close | |
CSV.open("#{infile_name}.csv", 'w') do |o| | |
o << %w(name version homepage summary license license_url org) | |
doc.css('module').each do |mnode| | |
name = mnode.attributes['name'].value if (mnode.attributes['name']) | |
version = mnode.css('revision').first.attributes['name'].value if (mnode.css('revision').first && mnode.css('revision').first.attributes['name']) | |
homepage = mnode.css('revision').first.attributes['homepage'].value if (mnode.css('revision').first && mnode.css('revision').first.attributes['homepage']) | |
license = mnode.css('license').last.attributes['name'].value if (mnode.css('license').last && mnode.css('license').last.attributes['name']) | |
license_url = mnode.css('license').last.attributes['url'].value if (mnode.css('license').last && mnode.css('license').last.attributes['url']) | |
org = mnode.attributes['organisation'].value if (mnode.attributes['organisation']) | |
o << [ | |
name, | |
version, | |
homepage, | |
"", | |
license, | |
license_url, | |
org | |
] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment