coral_core 0.2.19 → 0.2.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- metadata +4 -38
- data/.document +0 -5
- data/.gitmodules +0 -12
- data/Gemfile +0 -14
- data/Gemfile.lock +0 -39
- data/Rakefile +0 -77
- data/VERSION +0 -1
- data/coral_core.gemspec +0 -102
- data/lib/coral_core/command.rb +0 -244
- data/lib/coral_core/config.rb +0 -347
- data/lib/coral_core/core.rb +0 -212
- data/lib/coral_core/event/regexp_event.rb +0 -55
- data/lib/coral_core/event.rb +0 -170
- data/lib/coral_core/interface.rb +0 -180
- data/lib/coral_core/memory.rb +0 -226
- data/lib/coral_core/repository.rb +0 -164
- data/lib/coral_core/resource.rb +0 -243
- data/lib/coral_core/template/environment.rb +0 -72
- data/lib/coral_core/template/json.rb +0 -13
- data/lib/coral_core/template/wrapper.rb +0 -13
- data/lib/coral_core/template/yaml.rb +0 -13
- data/lib/coral_core/template.rb +0 -92
- data/lib/coral_core/util/data.rb +0 -219
- data/lib/coral_core/util/disk.rb +0 -92
- data/lib/coral_core/util/git/base.rb +0 -58
- data/lib/coral_core/util/git/lib.rb +0 -82
- data/lib/coral_core/util/git/remote.rb +0 -12
- data/lib/coral_core/util/git.rb +0 -15
- data/lib/coral_core/util/shell.rb +0 -183
- data/lib/coral_core.rb +0 -260
- data/lib/hiera_backend.rb +0 -63
- data/spec/coral_core/interface_spec.rb +0 -489
- data/spec/coral_mock_input.rb +0 -29
- data/spec/coral_test_kernel.rb +0 -22
- data/spec/spec_helper.rb +0 -15
data/lib/coral_core/event.rb
DELETED
@@ -1,170 +0,0 @@
|
|
1
|
-
|
2
|
-
module Coral
|
3
|
-
class Event < Core
|
4
|
-
|
5
|
-
#-----------------------------------------------------------------------------
|
6
|
-
# Constructor / Destructor
|
7
|
-
|
8
|
-
def self.instance!(data = {}, build_hash = false, keep_array = false)
|
9
|
-
group = ( build_hash ? {} : [] )
|
10
|
-
events = build_info(data)
|
11
|
-
|
12
|
-
index = 1
|
13
|
-
events.each do |info|
|
14
|
-
type = info[:type]
|
15
|
-
|
16
|
-
if type && ! type.empty?
|
17
|
-
event = ( block_given? ? yield(type, info) : create(type, info) )
|
18
|
-
|
19
|
-
if event
|
20
|
-
if build_hash
|
21
|
-
group[index] = event
|
22
|
-
else
|
23
|
-
group << event
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
index += 1
|
28
|
-
end
|
29
|
-
if ! build_hash && events.length == 1 && ! keep_array
|
30
|
-
return group.shift
|
31
|
-
end
|
32
|
-
return group
|
33
|
-
end
|
34
|
-
|
35
|
-
#---
|
36
|
-
|
37
|
-
def self.instance(options = {}, build_hash = false, keep_array = false)
|
38
|
-
return instance!(options, build_hash, keep_array)
|
39
|
-
end
|
40
|
-
|
41
|
-
#---
|
42
|
-
|
43
|
-
def initialize(options = {})
|
44
|
-
config = Config.ensure(options)
|
45
|
-
|
46
|
-
super(config)
|
47
|
-
|
48
|
-
@name = config.get(:name, '')
|
49
|
-
@delegate = config.get(:delegate, nil)
|
50
|
-
@properties = config.options
|
51
|
-
end
|
52
|
-
|
53
|
-
#-----------------------------------------------------------------------------
|
54
|
-
# Property accessors / modifiers
|
55
|
-
|
56
|
-
attr_accessor :name
|
57
|
-
|
58
|
-
#---
|
59
|
-
|
60
|
-
def type
|
61
|
-
return string(@properties[:type])
|
62
|
-
end
|
63
|
-
|
64
|
-
#---
|
65
|
-
|
66
|
-
def set_properties(data)
|
67
|
-
return @delegate.set_properties(data) if @delegate
|
68
|
-
|
69
|
-
@properties = hash(data)
|
70
|
-
return self
|
71
|
-
end
|
72
|
-
|
73
|
-
#---
|
74
|
-
|
75
|
-
def property(name, default = '', format = false)
|
76
|
-
name = name.to_sym
|
77
|
-
|
78
|
-
property = default
|
79
|
-
property = filter(@properties[name], format) if @properties.has_key?(name)
|
80
|
-
return property
|
81
|
-
end
|
82
|
-
|
83
|
-
#---
|
84
|
-
|
85
|
-
def set_property(name, value)
|
86
|
-
return @delegate.set_property(name, value) if @delegate
|
87
|
-
|
88
|
-
@properties[name] = value
|
89
|
-
return self
|
90
|
-
end
|
91
|
-
|
92
|
-
#-----------------------------------------------------------------------------
|
93
|
-
# Import / Export
|
94
|
-
|
95
|
-
def export
|
96
|
-
return type
|
97
|
-
end
|
98
|
-
|
99
|
-
#-----------------------------------------------------------------------------
|
100
|
-
# Event handling
|
101
|
-
|
102
|
-
def check(source)
|
103
|
-
return false
|
104
|
-
end
|
105
|
-
|
106
|
-
#-----------------------------------------------------------------------------
|
107
|
-
# Utilities
|
108
|
-
|
109
|
-
def self.build_info!(data = {})
|
110
|
-
events = []
|
111
|
-
|
112
|
-
if data.is_a?(String)
|
113
|
-
data = data.split(/\s*,\s*/)
|
114
|
-
elsif data.is_a?(Hash)
|
115
|
-
data = [ data ]
|
116
|
-
end
|
117
|
-
|
118
|
-
if data.is_a?(Array)
|
119
|
-
data.each do |element|
|
120
|
-
event = {}
|
121
|
-
|
122
|
-
if block_given?
|
123
|
-
event = yield(element)
|
124
|
-
else
|
125
|
-
case element
|
126
|
-
when String
|
127
|
-
event = split_event_string(element)
|
128
|
-
|
129
|
-
when Hash
|
130
|
-
event = element
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
unless event.empty?
|
135
|
-
events << event
|
136
|
-
end
|
137
|
-
end
|
138
|
-
end
|
139
|
-
return events
|
140
|
-
end
|
141
|
-
|
142
|
-
#---
|
143
|
-
|
144
|
-
def self.build_info(data = {})
|
145
|
-
return build_info!(data)
|
146
|
-
end
|
147
|
-
|
148
|
-
#-----------------------------------------------------------------------------
|
149
|
-
|
150
|
-
def self.create(type, info)
|
151
|
-
event = nil
|
152
|
-
begin
|
153
|
-
event = Module.const_get("Coral").const_get("#{type.capitalize}Event").new(info)
|
154
|
-
rescue
|
155
|
-
end
|
156
|
-
return event
|
157
|
-
end
|
158
|
-
|
159
|
-
#-----------------------------------------------------------------------------
|
160
|
-
|
161
|
-
def self.split_event_string(data)
|
162
|
-
info = {}
|
163
|
-
components = data.split(':')
|
164
|
-
info[:type] = components.shift
|
165
|
-
info[:string] = components.join(':')
|
166
|
-
|
167
|
-
return info
|
168
|
-
end
|
169
|
-
end
|
170
|
-
end
|
data/lib/coral_core/interface.rb
DELETED
@@ -1,180 +0,0 @@
|
|
1
|
-
|
2
|
-
require 'log4r'
|
3
|
-
|
4
|
-
module Coral
|
5
|
-
class Interface
|
6
|
-
|
7
|
-
#-----------------------------------------------------------------------------
|
8
|
-
# Properties
|
9
|
-
|
10
|
-
@@logger = Log4r::Logger.new("coral::interface")
|
11
|
-
|
12
|
-
#---
|
13
|
-
|
14
|
-
COLORS = {
|
15
|
-
:clear => "\e[0m",
|
16
|
-
:red => "\e[31m",
|
17
|
-
:green => "\e[32m",
|
18
|
-
:yellow => "\e[33m"
|
19
|
-
}
|
20
|
-
|
21
|
-
COLOR_MAP = {
|
22
|
-
:warn => COLORS[:yellow],
|
23
|
-
:error => COLORS[:red],
|
24
|
-
:success => COLORS[:green]
|
25
|
-
}
|
26
|
-
|
27
|
-
#-----------------------------------------------------------------------------
|
28
|
-
# Constructor
|
29
|
-
|
30
|
-
def initialize(options = {})
|
31
|
-
class_name = self.class.to_s.downcase
|
32
|
-
|
33
|
-
if options.is_a?(String)
|
34
|
-
options = { :resource => options, :logger => options }
|
35
|
-
end
|
36
|
-
config = Config.ensure(options)
|
37
|
-
|
38
|
-
if config.get(:logger, false)
|
39
|
-
if config[:logger].is_a?(String)
|
40
|
-
@logger = Log4r::Logger.new(config[:logger])
|
41
|
-
else
|
42
|
-
@logger = config[:logger]
|
43
|
-
end
|
44
|
-
else
|
45
|
-
@logger = Log4r::Logger.new(class_name)
|
46
|
-
end
|
47
|
-
|
48
|
-
@resource = config.get(:resource, '')
|
49
|
-
@color = config.get(:color, true)
|
50
|
-
|
51
|
-
@printer = config.get(:printer, :puts)
|
52
|
-
|
53
|
-
@input = config.get(:input, $stdin)
|
54
|
-
@output = config.get(:output, $stdout)
|
55
|
-
@error = config.get(:error, $stderr)
|
56
|
-
|
57
|
-
@delegate = config.get(:ui_delegate, nil)
|
58
|
-
end
|
59
|
-
|
60
|
-
#-----------------------------------------------------------------------------
|
61
|
-
# Accessors / Modifiers
|
62
|
-
|
63
|
-
attr_accessor :logger, :resource, :color, :input, :output, :error, :delegate
|
64
|
-
|
65
|
-
#-----------------------------------------------------------------------------
|
66
|
-
|
67
|
-
def self.logger
|
68
|
-
return @@logger
|
69
|
-
end
|
70
|
-
|
71
|
-
#-----------------------------------------------------------------------------
|
72
|
-
# UI functionality
|
73
|
-
|
74
|
-
def say(type, message, options = {})
|
75
|
-
return @delegate.say(type, message, options) if check_delegate('say')
|
76
|
-
|
77
|
-
defaults = { :new_line => true, :prefix => true }
|
78
|
-
options = defaults.merge(options)
|
79
|
-
printer = options[:new_line] ? :puts : :print
|
80
|
-
channel = type == :error || options[:channel] == :error ? @error : @output
|
81
|
-
|
82
|
-
safe_puts(format_message(type, message, options),
|
83
|
-
:channel => channel, :printer => printer)
|
84
|
-
end
|
85
|
-
|
86
|
-
#---
|
87
|
-
|
88
|
-
def ask(message, options = {})
|
89
|
-
return @delegate.ask(message, options) if check_delegate('ask')
|
90
|
-
|
91
|
-
options[:new_line] = false if ! options.has_key?(:new_line)
|
92
|
-
options[:prefix] = false if ! options.has_key?(:prefix)
|
93
|
-
|
94
|
-
say(:info, message, options)
|
95
|
-
return @input.gets.chomp
|
96
|
-
end
|
97
|
-
|
98
|
-
#-----------------------------------------------------------------------------
|
99
|
-
|
100
|
-
def info(message, *args)
|
101
|
-
@logger.info("info: #{message}")
|
102
|
-
|
103
|
-
return @delegate.info(message, *args) if check_delegate('info')
|
104
|
-
say(:info, message, *args)
|
105
|
-
end
|
106
|
-
|
107
|
-
#---
|
108
|
-
|
109
|
-
def warn(message, *args)
|
110
|
-
@logger.info("warn: #{message}")
|
111
|
-
|
112
|
-
return @delegate.warn(message, *args) if check_delegate('warn')
|
113
|
-
say(:warn, message, *args)
|
114
|
-
end
|
115
|
-
|
116
|
-
#---
|
117
|
-
|
118
|
-
def error(message, *args)
|
119
|
-
@logger.info("error: #{message}")
|
120
|
-
|
121
|
-
return @delegate.error(message, *args) if check_delegate('error')
|
122
|
-
say(:error, message, *args)
|
123
|
-
end
|
124
|
-
|
125
|
-
#---
|
126
|
-
|
127
|
-
def success(message, *args)
|
128
|
-
@logger.info("success: #{message}")
|
129
|
-
|
130
|
-
return @delegate.success(message, *args) if check_delegate('success')
|
131
|
-
say(:success, message, *args)
|
132
|
-
end
|
133
|
-
|
134
|
-
#-----------------------------------------------------------------------------
|
135
|
-
# Utilities
|
136
|
-
|
137
|
-
def format_message(type, message, options = {})
|
138
|
-
return @delegate.format_message(type, message, options) if check_delegate('format_message')
|
139
|
-
|
140
|
-
if @resource && ! @resource.empty? && options[:prefix]
|
141
|
-
prefix = "[#{@resource}]"
|
142
|
-
end
|
143
|
-
message = "#{prefix} #{message}".strip
|
144
|
-
|
145
|
-
if @color
|
146
|
-
if options.has_key?(:color)
|
147
|
-
color = COLORS[options[:color]]
|
148
|
-
message = "#{color}#{message}#{COLORS[:clear]}"
|
149
|
-
else
|
150
|
-
message = "#{COLOR_MAP[type]}#{message}#{COLORS[:clear]}" if COLOR_MAP[type]
|
151
|
-
end
|
152
|
-
end
|
153
|
-
return message
|
154
|
-
end
|
155
|
-
|
156
|
-
#---
|
157
|
-
|
158
|
-
def safe_puts(message = nil, options = {})
|
159
|
-
return @delegate.safe_puts(message, options) if check_delegate('safe_puts')
|
160
|
-
|
161
|
-
message ||= ""
|
162
|
-
options = {
|
163
|
-
:channel => @output,
|
164
|
-
:printer => @printer,
|
165
|
-
}.merge(options)
|
166
|
-
|
167
|
-
begin
|
168
|
-
options[:channel].send(options[:printer], message)
|
169
|
-
rescue Errno::EPIPE
|
170
|
-
return
|
171
|
-
end
|
172
|
-
end
|
173
|
-
|
174
|
-
#-----------------------------------------------------------------------------
|
175
|
-
|
176
|
-
def check_delegate(method)
|
177
|
-
return ( @delegate && @delegate.respond_to?(method.to_s) )
|
178
|
-
end
|
179
|
-
end
|
180
|
-
end
|
data/lib/coral_core/memory.rb
DELETED
@@ -1,226 +0,0 @@
|
|
1
|
-
|
2
|
-
require 'json'
|
3
|
-
|
4
|
-
module Coral
|
5
|
-
class Memory < Repository
|
6
|
-
|
7
|
-
#-----------------------------------------------------------------------------
|
8
|
-
# Constructor / Destructor
|
9
|
-
|
10
|
-
def initialize(options = {})
|
11
|
-
config = Config.ensure(options)
|
12
|
-
|
13
|
-
super(config)
|
14
|
-
|
15
|
-
@absolute_config_file = ''
|
16
|
-
@config_file = ''
|
17
|
-
|
18
|
-
@properties = config.get(:properties, {})
|
19
|
-
|
20
|
-
@autoload = config.get(:autoload, true)
|
21
|
-
@autosave = config.get(:autosave, true)
|
22
|
-
@autocommit = config.get(:autocommit, true)
|
23
|
-
@commit_message = config.get(:commit_message, 'Saving state')
|
24
|
-
|
25
|
-
self.config_file = config.get(:config_file, '')
|
26
|
-
end
|
27
|
-
|
28
|
-
#---
|
29
|
-
|
30
|
-
def self.finalize(file_name)
|
31
|
-
proc do
|
32
|
-
Coral::Util::Disk.close(file_name)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
#-----------------------------------------------------------------------------
|
37
|
-
# Property accessors / modifiers
|
38
|
-
|
39
|
-
attr_accessor :autoload, :autosave, :autocommit, :commit_message
|
40
|
-
attr_reader :config_file, :absolute_config_file
|
41
|
-
|
42
|
-
#---
|
43
|
-
|
44
|
-
def set_absolute_config_file
|
45
|
-
if @directory.empty? || @config_file.empty?
|
46
|
-
@absolute_config_file = ''
|
47
|
-
else
|
48
|
-
@absolute_config_file = ( ! @submodule.empty? ? File.join(@directory, @submodule, @config_file) : File.join(@directory, @config_file) )
|
49
|
-
ObjectSpace.define_finalizer(self, self.class.finalize(@absolute_config_file))
|
50
|
-
end
|
51
|
-
return self
|
52
|
-
end
|
53
|
-
|
54
|
-
#---
|
55
|
-
|
56
|
-
def config_file=file
|
57
|
-
unless Util::Data.empty?(file)
|
58
|
-
@config_file = ( file.is_a?(Array) ? file.join(File::SEPARATOR) : string(file) )
|
59
|
-
end
|
60
|
-
|
61
|
-
set_absolute_config_file
|
62
|
-
load if @autoload
|
63
|
-
end
|
64
|
-
|
65
|
-
#-----------------------------------------------------------------------------
|
66
|
-
|
67
|
-
def get(key, default = '', format = false)
|
68
|
-
value = default
|
69
|
-
key = string(key)
|
70
|
-
|
71
|
-
if ! @properties || ! @properties.is_a?(Hash)
|
72
|
-
@properties = {}
|
73
|
-
end
|
74
|
-
if @properties.has_key?(key)
|
75
|
-
value = @properties[key]
|
76
|
-
end
|
77
|
-
return filter(value, format)
|
78
|
-
end
|
79
|
-
|
80
|
-
#---
|
81
|
-
|
82
|
-
def set(key, value = '')
|
83
|
-
key = string(key)
|
84
|
-
|
85
|
-
if ! @properties || ! @properties.is_a?(Hash)
|
86
|
-
@properties = {}
|
87
|
-
end
|
88
|
-
@properties[key] = value
|
89
|
-
save if @autosave
|
90
|
-
return self
|
91
|
-
end
|
92
|
-
|
93
|
-
#---
|
94
|
-
|
95
|
-
def delete(key)
|
96
|
-
key = string(key)
|
97
|
-
|
98
|
-
if ! @properties || ! @properties.is_a?(Hash)
|
99
|
-
@properties = {}
|
100
|
-
end
|
101
|
-
@properties.delete(key)
|
102
|
-
save if @autosave
|
103
|
-
return self
|
104
|
-
end
|
105
|
-
|
106
|
-
#---
|
107
|
-
|
108
|
-
def get_group(group, name = '', key = nil, default = {}, format = false)
|
109
|
-
info = get(group, {})
|
110
|
-
value = info
|
111
|
-
|
112
|
-
if name
|
113
|
-
name = string(name)
|
114
|
-
if info.has_key?(name) && info[name].is_a?(Hash)
|
115
|
-
if key && ! key.empty?
|
116
|
-
key = string(key)
|
117
|
-
if info[name].has_key?(key)
|
118
|
-
value = info[name][key]
|
119
|
-
else
|
120
|
-
value = default
|
121
|
-
end
|
122
|
-
else
|
123
|
-
value = info[name]
|
124
|
-
end
|
125
|
-
else
|
126
|
-
value = default
|
127
|
-
end
|
128
|
-
end
|
129
|
-
return filter(value, format)
|
130
|
-
end
|
131
|
-
|
132
|
-
#---
|
133
|
-
|
134
|
-
def set_group(group, name, key = nil, value = {})
|
135
|
-
group = string(group)
|
136
|
-
name = string(name)
|
137
|
-
|
138
|
-
if ! @properties || ! @properties.is_a?(Hash)
|
139
|
-
@properties = {}
|
140
|
-
end
|
141
|
-
if ! @properties[group] || ! @properties[group].is_a?(Hash)
|
142
|
-
@properties[group] = {}
|
143
|
-
end
|
144
|
-
|
145
|
-
if key && ! key.empty?
|
146
|
-
key = string(key)
|
147
|
-
if ! @properties[group][name] || ! @properties[group][name].is_a?(Hash)
|
148
|
-
@properties[group][name] = {}
|
149
|
-
end
|
150
|
-
@properties[group][name][key] = value
|
151
|
-
|
152
|
-
else
|
153
|
-
@properties[group][name] = value
|
154
|
-
end
|
155
|
-
save if @autosave
|
156
|
-
return self
|
157
|
-
end
|
158
|
-
|
159
|
-
#---
|
160
|
-
|
161
|
-
def delete_group(group, name, key = nil)
|
162
|
-
group = string(group)
|
163
|
-
name = string(name)
|
164
|
-
|
165
|
-
if ! @properties || ! @properties.is_a?(Hash)
|
166
|
-
@properties = {}
|
167
|
-
end
|
168
|
-
if ! @properties[group] || ! @properties[group].is_a?(Hash)
|
169
|
-
@properties[group] = {}
|
170
|
-
end
|
171
|
-
|
172
|
-
if key && ! key.empty?
|
173
|
-
key = string(key)
|
174
|
-
if @properties[group][name] && @properties[group][name].is_a?(Hash)
|
175
|
-
@properties[group][name].delete(key)
|
176
|
-
end
|
177
|
-
else
|
178
|
-
@properties[group].delete(name)
|
179
|
-
end
|
180
|
-
save if @autosave
|
181
|
-
return self
|
182
|
-
end
|
183
|
-
|
184
|
-
#-----------------------------------------------------------------------------
|
185
|
-
# Import / Export
|
186
|
-
|
187
|
-
def export
|
188
|
-
return @properties
|
189
|
-
end
|
190
|
-
|
191
|
-
#-----------------------------------------------------------------------------
|
192
|
-
# Configuration loading / saving
|
193
|
-
|
194
|
-
def load
|
195
|
-
if can_persist?
|
196
|
-
config = Coral::Util::Disk.read(@absolute_config_file)
|
197
|
-
if config && ! config.empty?
|
198
|
-
@properties = JSON.parse(config)
|
199
|
-
end
|
200
|
-
end
|
201
|
-
return self
|
202
|
-
end
|
203
|
-
|
204
|
-
#---
|
205
|
-
|
206
|
-
def save(options = {})
|
207
|
-
if can_persist?
|
208
|
-
config = JSON.generate(@properties)
|
209
|
-
if config && ! config.empty?
|
210
|
-
Coral::Util::Disk.write(@absolute_config_file, config)
|
211
|
-
commit(@absolute_config_file, options) if @autocommit
|
212
|
-
end
|
213
|
-
end
|
214
|
-
return self
|
215
|
-
end
|
216
|
-
|
217
|
-
#-----------------------------------------------------------------------------
|
218
|
-
# Checks
|
219
|
-
|
220
|
-
def can_persist?
|
221
|
-
success = super
|
222
|
-
success = false if success && @absolute_config_file.empty?
|
223
|
-
return success
|
224
|
-
end
|
225
|
-
end
|
226
|
-
end
|