Last active
August 29, 2015 14:08
-
-
Save sgzijl/c4d0ec569e1e0a5fcb1f to your computer and use it in GitHub Desktop.
Quick&dirty modulefile2metadata.json script for puppet 3.6+
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 | |
# Very quick&dirty script to quickly migrate puppet's modulefile to metadata.json files | |
# (Puppet >= 3.6 deprecated the Modulefile) | |
# | |
# Usage: check-out all your modules to a current directory and run ./modulefile2metadatajson.rb | |
# | |
# After completion, a proper metadata.json file should remain in each module directory. | |
require 'json' | |
Dir.glob('**/Modulefile') do | module_file | | |
input = File.open(module_file) | |
hash = {} | |
dep_array = [] | |
input.each_line { | line | | |
key, val = line.split ' ', 2 | |
val = "#{val}".gsub('\'','') | |
val.to_s.delete!("\n") | |
if key =~ /^depen.*/ | |
key, val = line.split ',', 2 | |
key = "#{key}".gsub('dependency ', '') | |
key = "#{key}".gsub('\'','') | |
# remove ' and \n from version | |
val = "#{val}".gsub('\'','') | |
val = "#{val}".gsub(' ','') | |
val.to_s.delete!("\n") | |
temp_hash = {} | |
temp_hash.store("name", key) | |
temp_hash.store("version_requirement", val) | |
dep_array << temp_hash | |
elsif key =~ /^$/ | |
# foo | |
else | |
hash.store(key, val) | |
end | |
} | |
hash.store("project_page", "http://yoururl2yourprojects.tld") | |
hash.store("issues_url", "http://yoururl2issues.tld") | |
hash.store("dependenies", dep_array) | |
puts JSON.pretty_generate(hash) | |
dirname = File.dirname(module_file) | |
output = File.open( "#{dirname}/metadata.json", "w") | |
output << JSON.pretty_generate(hash) | |
output.write "\n" | |
output.close | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment