forked from boxgrinder/boxgrinder-core
/
config.rb
70 lines (63 loc) · 2.25 KB
/
config.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#
# Copyright 2010 Red Hat, Inc.
#
# This is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation; either version 3 of
# the License, or (at your option) any later version.
#
# This software is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this software; if not, write to the Free
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
require 'rubygems'
require 'hashery/opencascade'
require 'yaml'
module BoxGrinder
class Config < OpenCascade
def initialize(values = {})
super({})
merge!(
:file => ENV['BG_CONFIG_FILE'] || "#{ENV['HOME']}/.boxgrinder/config",
:name => 'BoxGrinder Build',
:platform => :none,
:delivery => :none,
:force => false,
:log_level => :info,
:backtrace => false,
:dir => {
:root => Dir.pwd,
:build => 'build',
:cache => '/var/cache/boxgrinder', # required for appliance-creator
:tmp => '/tmp'
},
:os_config => {},
:platform_config => {},
:delivery_config => {},
:additional_plugins => []
)
if ENV['BG_CONFIG_FILE']
unless ENV['BG_CONFIG_FILE'].strip.empty?
raise(Errno::ENOENT, ENV['BG_CONFIG_FILE']) unless File.exists? ENV['BG_CONFIG_FILE']
end
end
deep_merge(self, YAML.load_file(self.file)) if File.exists?(self.file)
merge!(values.inject({}) { |memo, (k, v)| memo[k.to_sym] = v; memo })
self.backtrace = true if [:debug, :trace].include?(self.log_level)
end
def deep_merge(first, second)
second.each_key do |k|
if first[k.to_sym].is_a?(Hash) and second[k].is_a?(Hash)
deep_merge(first[k.to_sym], second[k])
else
first[k.to_sym] = second[k]
end
end if second
end
end
end