nucleon 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +4 -8
- data/Gemfile.lock +0 -28
- data/README.rdoc +13 -5
- data/Rakefile +9 -1
- data/VERSION +1 -1
- data/bin/nucleon +55 -0
- data/lib/core/codes.rb +107 -0
- data/lib/core/config/collection.rb +57 -0
- data/lib/core/config/options.rb +70 -0
- data/lib/core/config.rb +342 -0
- data/lib/core/core.rb +54 -0
- data/lib/core/errors.rb +84 -0
- data/lib/core/facade.rb +283 -0
- data/lib/core/gems.rb +80 -0
- data/lib/core/manager.rb +594 -0
- data/lib/core/mixin/action/commit.rb +58 -0
- data/lib/core/mixin/action/project.rb +53 -0
- data/lib/core/mixin/action/push.rb +52 -0
- data/lib/core/mixin/config/collection.rb +53 -0
- data/lib/core/mixin/config/options.rb +39 -0
- data/lib/core/mixin/macro/object_interface.rb +361 -0
- data/lib/core/mixin/macro/plugin_interface.rb +380 -0
- data/lib/core/mixin/settings.rb +46 -0
- data/lib/core/mixin/sub_config.rb +148 -0
- data/lib/core/mod/hash.rb +29 -0
- data/lib/core/plugin/action.rb +371 -0
- data/lib/core/plugin/base.rb +313 -0
- data/lib/core/plugin/command.rb +98 -0
- data/lib/core/plugin/event.rb +53 -0
- data/lib/core/plugin/extension.rb +12 -0
- data/lib/core/plugin/project.rb +890 -0
- data/lib/core/plugin/template.rb +80 -0
- data/lib/core/plugin/translator.rb +38 -0
- data/lib/core/util/cli.rb +353 -0
- data/lib/core/util/console.rb +237 -0
- data/lib/core/util/data.rb +404 -0
- data/lib/core/util/disk.rb +114 -0
- data/lib/core/util/git.rb +43 -0
- data/lib/core/util/liquid.rb +17 -0
- data/lib/core/util/logger.rb +147 -0
- data/lib/core/util/package.rb +93 -0
- data/lib/core/util/shell.rb +239 -0
- data/lib/nucleon/action/add.rb +69 -0
- data/lib/nucleon/action/create.rb +52 -0
- data/lib/nucleon/action/extract.rb +49 -0
- data/lib/nucleon/action/remove.rb +51 -0
- data/lib/nucleon/action/save.rb +53 -0
- data/lib/nucleon/action/update.rb +37 -0
- data/lib/nucleon/command/bash.rb +146 -0
- data/lib/nucleon/event/regex.rb +52 -0
- data/lib/nucleon/project/git.rb +465 -0
- data/lib/nucleon/project/github.rb +108 -0
- data/lib/nucleon/template/json.rb +16 -0
- data/lib/nucleon/template/wrapper.rb +16 -0
- data/lib/nucleon/template/yaml.rb +16 -0
- data/lib/nucleon/translator/json.rb +27 -0
- data/lib/nucleon/translator/yaml.rb +27 -0
- data/lib/nucleon.rb +18 -15
- data/locales/en.yml +3 -132
- data/nucleon.gemspec +66 -27
- data/spec/core/util/console_spec.rb +489 -0
- metadata +109 -96
data/lib/core/facade.rb
ADDED
@@ -0,0 +1,283 @@
|
|
1
|
+
|
2
|
+
module Nucleon
|
3
|
+
|
4
|
+
VERSION = File.read(File.join(File.dirname(__FILE__), '..', '..', 'VERSION'))
|
5
|
+
|
6
|
+
#-----------------------------------------------------------------------------
|
7
|
+
|
8
|
+
def self.ui
|
9
|
+
Core.ui
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.quiet=quiet
|
13
|
+
Util::Console.quiet = quiet
|
14
|
+
end
|
15
|
+
|
16
|
+
#---
|
17
|
+
|
18
|
+
def self.logger
|
19
|
+
Core.logger
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.log_level
|
23
|
+
Util::Logger.level
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.log_level=log_level
|
27
|
+
Util::Logger.level = log_level
|
28
|
+
end
|
29
|
+
|
30
|
+
#-----------------------------------------------------------------------------
|
31
|
+
|
32
|
+
def self.admin?
|
33
|
+
is_admin = ( ENV['USER'] == 'root' )
|
34
|
+
ext_admin = exec(:check_admin) do |op, results|
|
35
|
+
if op == :reduce
|
36
|
+
results.values.include?(true)
|
37
|
+
else
|
38
|
+
results ? true : false
|
39
|
+
end
|
40
|
+
end
|
41
|
+
is_admin || ext_admin ? true : false
|
42
|
+
end
|
43
|
+
|
44
|
+
#-----------------------------------------------------------------------------
|
45
|
+
# Status codes
|
46
|
+
|
47
|
+
@@codes = Codes.new
|
48
|
+
|
49
|
+
def self.code
|
50
|
+
@@codes
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.codes(*codes)
|
54
|
+
Codes.codes(*codes)
|
55
|
+
end
|
56
|
+
|
57
|
+
#-----------------------------------------------------------------------------
|
58
|
+
# Core plugin interface
|
59
|
+
|
60
|
+
def self.reload
|
61
|
+
Manager.connection.reload
|
62
|
+
end
|
63
|
+
|
64
|
+
#---
|
65
|
+
|
66
|
+
def self.types
|
67
|
+
Manager.connection.types
|
68
|
+
end
|
69
|
+
|
70
|
+
def self.define_type(type_info)
|
71
|
+
Manager.connection.define_type(type_info)
|
72
|
+
end
|
73
|
+
|
74
|
+
def self.type_default(type)
|
75
|
+
Manager.connection.type_default(type)
|
76
|
+
end
|
77
|
+
|
78
|
+
#---
|
79
|
+
|
80
|
+
def self.register(base_path, &code)
|
81
|
+
Manager.connection.register(base_path, &code)
|
82
|
+
Manager.connection.autoload
|
83
|
+
end
|
84
|
+
|
85
|
+
def self.loaded_plugins(type = nil, provider = nil)
|
86
|
+
Manager.connection.loaded_plugins(type, provider)
|
87
|
+
end
|
88
|
+
|
89
|
+
#---
|
90
|
+
|
91
|
+
def self.active_plugins(type = nil, provider = nil)
|
92
|
+
Manager.connection.plugins(type, provider)
|
93
|
+
end
|
94
|
+
|
95
|
+
#---
|
96
|
+
|
97
|
+
def self.plugin(type, provider, options = {})
|
98
|
+
Manager.connection.load(type, provider, options)
|
99
|
+
end
|
100
|
+
|
101
|
+
#---
|
102
|
+
|
103
|
+
def self.plugins(type, data, build_hash = false, keep_array = false)
|
104
|
+
Manager.connection.load_multiple(type, data, build_hash, keep_array)
|
105
|
+
end
|
106
|
+
|
107
|
+
#---
|
108
|
+
|
109
|
+
def self.get_plugin(type, name)
|
110
|
+
Manager.connection.get(type, name)
|
111
|
+
end
|
112
|
+
|
113
|
+
#---
|
114
|
+
|
115
|
+
def self.remove_plugin(plugin)
|
116
|
+
Manager.connection.remove(plugin)
|
117
|
+
end
|
118
|
+
|
119
|
+
#-----------------------------------------------------------------------------
|
120
|
+
# Core plugin type facade
|
121
|
+
|
122
|
+
def self.extension(provider)
|
123
|
+
plugin(:extension, provider, {})
|
124
|
+
end
|
125
|
+
|
126
|
+
#---
|
127
|
+
|
128
|
+
def self.action(provider, options)
|
129
|
+
plugin(:action, provider, options)
|
130
|
+
end
|
131
|
+
|
132
|
+
def self.actions(data, build_hash = false, keep_array = false)
|
133
|
+
plugins(:action, data, build_hash, keep_array)
|
134
|
+
end
|
135
|
+
|
136
|
+
def self.action_config(provider)
|
137
|
+
action(provider, { :settings => {}, :quiet => true }).configure
|
138
|
+
end
|
139
|
+
|
140
|
+
def self.action_run(provider, options = {}, quiet = true)
|
141
|
+
Plugin::Action.exec(provider, options, quiet)
|
142
|
+
end
|
143
|
+
|
144
|
+
def self.action_cli(provider, args = [], quiet = false)
|
145
|
+
Plugin::Action.exec_cli(provider, args, quiet)
|
146
|
+
end
|
147
|
+
|
148
|
+
#---
|
149
|
+
|
150
|
+
def self.project(options, provider = nil)
|
151
|
+
plugin(:project, provider, options)
|
152
|
+
end
|
153
|
+
|
154
|
+
def self.projects(data, build_hash = false, keep_array = false)
|
155
|
+
plugins(:project, data, build_hash, keep_array)
|
156
|
+
end
|
157
|
+
|
158
|
+
#-----------------------------------------------------------------------------
|
159
|
+
# Utility plugin type facade
|
160
|
+
|
161
|
+
def self.command(options, provider = nil)
|
162
|
+
plugin(:command, provider, options)
|
163
|
+
end
|
164
|
+
|
165
|
+
def self.commands(data, build_hash = false, keep_array = false)
|
166
|
+
plugins(:command, data, build_hash, keep_array)
|
167
|
+
end
|
168
|
+
|
169
|
+
#---
|
170
|
+
|
171
|
+
def self.event(options, provider = nil)
|
172
|
+
plugin(:event, provider, options)
|
173
|
+
end
|
174
|
+
|
175
|
+
def self.events(data, build_hash = false, keep_array = false)
|
176
|
+
plugins(:event, data, build_hash, keep_array)
|
177
|
+
end
|
178
|
+
|
179
|
+
#---
|
180
|
+
|
181
|
+
def self.template(options, provider = nil)
|
182
|
+
plugin(:template, provider, options)
|
183
|
+
end
|
184
|
+
|
185
|
+
def self.templates(data, build_hash = false, keep_array = false)
|
186
|
+
plugins(:template, data, build_hash, keep_array)
|
187
|
+
end
|
188
|
+
|
189
|
+
#---
|
190
|
+
|
191
|
+
def self.translator(options, provider = nil)
|
192
|
+
plugin(:translator, provider, options)
|
193
|
+
end
|
194
|
+
|
195
|
+
def self.translators(data, build_hash = false, keep_array = false)
|
196
|
+
plugins(:translator, data, build_hash, keep_array)
|
197
|
+
end
|
198
|
+
|
199
|
+
#-----------------------------------------------------------------------------
|
200
|
+
# Plugin extensions
|
201
|
+
|
202
|
+
def self.exec(method, options = {}, &code)
|
203
|
+
Manager.connection.exec(method, options, &code)
|
204
|
+
end
|
205
|
+
|
206
|
+
#---
|
207
|
+
|
208
|
+
def self.config(type, options = {})
|
209
|
+
Manager.connection.config(method, options)
|
210
|
+
end
|
211
|
+
|
212
|
+
#---
|
213
|
+
|
214
|
+
def self.check(method, options = {})
|
215
|
+
Manager.connection.check(method, options)
|
216
|
+
end
|
217
|
+
|
218
|
+
#---
|
219
|
+
|
220
|
+
def self.value(method, value, options = {})
|
221
|
+
Manager.connection.value(method, value, options)
|
222
|
+
end
|
223
|
+
|
224
|
+
#---
|
225
|
+
|
226
|
+
def self.collect(method, options = {})
|
227
|
+
Manager.connection.collect(method, options)
|
228
|
+
end
|
229
|
+
|
230
|
+
#-----------------------------------------------------------------------------
|
231
|
+
# External execution
|
232
|
+
|
233
|
+
def self.run
|
234
|
+
begin
|
235
|
+
logger.debug("Running contained process at #{Time.now}")
|
236
|
+
yield
|
237
|
+
|
238
|
+
rescue Exception => error
|
239
|
+
logger.error("Nucleon run experienced an error! Details:")
|
240
|
+
logger.error(error.inspect)
|
241
|
+
logger.error(error.message)
|
242
|
+
logger.error(Util::Data.to_yaml(error.backtrace))
|
243
|
+
|
244
|
+
ui.error(error.message) if error.message
|
245
|
+
raise
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
249
|
+
#---
|
250
|
+
|
251
|
+
def self.cli_run(command, options = {}, &code)
|
252
|
+
command = command.join(' ') if command.is_a?(Array)
|
253
|
+
config = Config.ensure(options)
|
254
|
+
|
255
|
+
logger.info("Executing command #{command}")
|
256
|
+
|
257
|
+
result = Util::Shell.connection.exec(command, config, &code)
|
258
|
+
|
259
|
+
unless result.status == Nucleon.code.success
|
260
|
+
ui.error("Command #{command} failed to execute")
|
261
|
+
end
|
262
|
+
result
|
263
|
+
end
|
264
|
+
|
265
|
+
#-----------------------------------------------------------------------------
|
266
|
+
# Utilities
|
267
|
+
|
268
|
+
def self.class_name(name, separator = '::', want_array = false)
|
269
|
+
Manager.connection.class_name(name, separator, want_array)
|
270
|
+
end
|
271
|
+
|
272
|
+
#---
|
273
|
+
|
274
|
+
def self.class_const(name, separator = '::')
|
275
|
+
Manager.connection.class_const(name, separator)
|
276
|
+
end
|
277
|
+
|
278
|
+
#---
|
279
|
+
|
280
|
+
def self.sha1(data)
|
281
|
+
Digest::SHA1.hexdigest(Util::Data.to_json(data, false))
|
282
|
+
end
|
283
|
+
end
|
data/lib/core/gems.rb
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
|
2
|
+
module Nucleon
|
3
|
+
module Gems
|
4
|
+
|
5
|
+
#-----------------------------------------------------------------------------
|
6
|
+
|
7
|
+
@@core = nil
|
8
|
+
@@gems = {}
|
9
|
+
|
10
|
+
#-----------------------------------------------------------------------------
|
11
|
+
# Gem interface
|
12
|
+
|
13
|
+
def self.logger
|
14
|
+
Core.logger
|
15
|
+
end
|
16
|
+
|
17
|
+
#---
|
18
|
+
|
19
|
+
def self.core
|
20
|
+
@@core
|
21
|
+
end
|
22
|
+
|
23
|
+
#---
|
24
|
+
|
25
|
+
def self.registered
|
26
|
+
@@gems
|
27
|
+
end
|
28
|
+
|
29
|
+
#---
|
30
|
+
|
31
|
+
def self.register(reset = false)
|
32
|
+
if reset || Util::Data.empty?(@@gems)
|
33
|
+
logger.info("Registering external gem defined Nucleon plugins at #{Time.now}")
|
34
|
+
|
35
|
+
if defined?(Gem)
|
36
|
+
if ! defined?(Bundler) && Gem::Specification.respond_to?(:latest_specs)
|
37
|
+
logger.debug("Not using bundler")
|
38
|
+
Gem::Specification.latest_specs(true).each do |spec|
|
39
|
+
register_gem(spec)
|
40
|
+
end
|
41
|
+
else
|
42
|
+
logger.debug("Using bundler or Gem specification without latest_specs")
|
43
|
+
Gem.loaded_specs.each do |name, spec|
|
44
|
+
register_gem(spec)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
@@gems
|
50
|
+
end
|
51
|
+
|
52
|
+
#---
|
53
|
+
|
54
|
+
def self.register_gem(spec)
|
55
|
+
name = spec.name
|
56
|
+
base_path = File.join(spec.full_gem_path, 'lib')
|
57
|
+
|
58
|
+
Manager.connection.register(base_path) do |data|
|
59
|
+
namespace = data[:namespace]
|
60
|
+
plugin_path = data[:directory]
|
61
|
+
|
62
|
+
logger.info("Registering gem #{name} at #{plugin_path} at #{Time.now}")
|
63
|
+
|
64
|
+
unless @@gems.has_key?(name)
|
65
|
+
@@gems[name] = {
|
66
|
+
:spec => spec,
|
67
|
+
:base_path => base_path,
|
68
|
+
:namespaces => []
|
69
|
+
}
|
70
|
+
end
|
71
|
+
@@gems[name][:namespaces] << namespace unless @@gems[name][:namespaces].include?(namespace)
|
72
|
+
|
73
|
+
if name == 'nucleon'
|
74
|
+
logger.debug("Setting Nucleon core gemspec")
|
75
|
+
@@core = spec
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|