Module: Common
- Included in:
- BuildMetadata, BuildRunner, DeleteRunner, ListRunner, NormalizeRunner, ProviderMetadata, ReleaseRunner, RevokeRunner, TestRunner, UploadRunner
- Defined in:
- lib/bento/common.rb
Instance Method Summary collapse
- #banner(msg) ⇒ Object
- #box_metadata(metadata_file) ⇒ Object
- #build_list ⇒ Object
- #builds_yml ⇒ Object
- #duration(total) ⇒ Object
- #info(msg) ⇒ Object
- #macos? ⇒ Boolean
- #metadata_files ⇒ Object
- #private_box?(boxname) ⇒ Boolean
- #unix? ⇒ Boolean
- #vc_account ⇒ Object
- #warn(msg) ⇒ Object
- #windows? ⇒ Boolean
Instance Method Details
#banner(msg) ⇒ Object
16 17 18 |
# File 'lib/bento/common.rb', line 16 def (msg) puts "==> #{msg}" end |
#box_metadata(metadata_file) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/bento/common.rb', line 35 def () = {} file = File.read() json = JSON.parse(file) # metadata needed for upload: boxname, version, provider, box filename ["name"] = json["name"] ["version"] = json["version"] ["box_basename"] = json["box_basename"] ["tools"] = json["tools"] ["providers"] = {} json["providers"].each do |provider| ["providers"][provider["name"]] = provider.reject { |k, _| k == "name" } end end |
#build_list ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/bento/common.rb', line 60 def build_list bit32 = [] bit64 = [] builds_yml["public"].each do |platform, versions| versions.each do |version, archs| archs.each do |arch| folder = case platform when "opensuse-leap" "opensuse" when "oracle" "oraclelinux" else platform end case arch when "i386" bit32 << "#{folder}/#{platform}-#{version}-#{arch}" else bit64 << "#{folder}/#{platform}-#{version}-#{arch}" end end end end bit64 + bit32 end |
#builds_yml ⇒ Object
56 57 58 |
# File 'lib/bento/common.rb', line 56 def builds_yml YAML.load(File.read("builds.yml")) end |
#duration(total) ⇒ Object
28 29 30 31 32 33 |
# File 'lib/bento/common.rb', line 28 def duration(total) total = 0 if total.nil? minutes = (total / 60).to_i seconds = (total - (minutes * 60)) format("%dm%.2fs", minutes, seconds) end |
#info(msg) ⇒ Object
20 21 22 |
# File 'lib/bento/common.rb', line 20 def info(msg) puts " #{msg}" end |
#macos? ⇒ Boolean
91 92 93 |
# File 'lib/bento/common.rb', line 91 def macos? !!(RUBY_PLATFORM =~ /darwin/) end |
#metadata_files ⇒ Object
52 53 54 |
# File 'lib/bento/common.rb', line 52 def @metadata_files ||= Dir.glob("builds/*.json") end |
#private_box?(boxname) ⇒ Boolean
86 87 88 89 |
# File 'lib/bento/common.rb', line 86 def private_box?(boxname) proprietary_os_list = %w{macos windows sles solaris rhel} proprietary_os_list.any? { |p| boxname.include?(p) } end |
#unix? ⇒ Boolean
95 96 97 |
# File 'lib/bento/common.rb', line 95 def unix? !windows? end |
#vc_account ⇒ Object
11 12 13 14 |
# File 'lib/bento/common.rb', line 11 def vc_account raise "You must set the 'VAGRANT_CLOUD_ORG' and 'VAGRANT_CLOUD_TOKEN' tokens to interact with the Vagrant Cloud!" unless ENV["VAGRANT_CLOUD_ORG"] && ENV["VAGRANT_CLOUD_TOKEN"] VagrantCloud::Account.new(ENV["VAGRANT_CLOUD_ORG"], ENV["VAGRANT_CLOUD_TOKEN"]) end |
#warn(msg) ⇒ Object
24 25 26 |
# File 'lib/bento/common.rb', line 24 def warn(msg) puts ">>> #{msg}" end |
#windows? ⇒ Boolean
99 100 101 |
# File 'lib/bento/common.rb', line 99 def windows? !!(RUBY_PLATFORM =~ /mswin|mingw|windows/) end |