Module: Common

Instance Method Summary collapse

Instance Method Details



16
17
18
# File 'lib/bento/common.rb', line 16

def banner(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_listObject



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_ymlObject



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

Returns:

  • (Boolean)


91
92
93
# File 'lib/bento/common.rb', line 91

def macos?
  !!(RUBY_PLATFORM =~ /darwin/)
end

#metadata_filesObject



52
53
54
# File 'lib/bento/common.rb', line 52

def 
  @metadata_files ||= Dir.glob("builds/*.json")
end

#private_box?(boxname) ⇒ Boolean

Returns:

  • (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

Returns:

  • (Boolean)


95
96
97
# File 'lib/bento/common.rb', line 95

def unix?
  !windows?
end

#vc_accountObject



11
12
13
14
# File 'lib/bento/common.rb', line 11

def 
  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

Returns:

  • (Boolean)


99
100
101
# File 'lib/bento/common.rb', line 99

def windows?
  !!(RUBY_PLATFORM =~ /mswin|mingw|windows/)
end