nucleon 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +2 -2
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/bin/nucleon +1 -53
- data/lib/core/core.rb +21 -3
- data/lib/core/facade.rb +146 -53
- data/lib/core/gems.rb +16 -13
- data/lib/core/manager.rb +67 -51
- data/lib/core/mixin/action/commit.rb +19 -25
- data/lib/core/mixin/action/project.rb +28 -16
- data/lib/core/mixin/action/push.rb +11 -21
- data/lib/core/plugin/action.rb +26 -14
- data/lib/core/plugin/base.rb +6 -4
- data/lib/core/util/cli.rb +20 -8
- data/lib/core/util/data.rb +0 -8
- data/lib/nucleon.rb +3 -161
- data/lib/nucleon/action/add.rb +28 -34
- data/lib/nucleon/action/create.rb +23 -28
- data/lib/nucleon/action/extract.rb +3 -3
- data/lib/nucleon/action/remove.rb +30 -26
- data/lib/nucleon/action/save.rb +26 -26
- data/lib/nucleon/action/update.rb +13 -18
- data/lib/nucleon/project/git.rb +2 -2
- data/lib/nucleon_base.rb +184 -0
- data/locales/en.yml +47 -41
- data/nucleon.gemspec +3 -2
- metadata +31 -30
data/lib/core/plugin/base.rb
CHANGED
@@ -167,7 +167,9 @@ class Base < Core
|
|
167
167
|
#---
|
168
168
|
|
169
169
|
def extended_config(type, options = {})
|
170
|
-
Nucleon.config(type, Config.ensure(options).import({ :plugin => myself }))
|
170
|
+
config = Nucleon.config(type, Config.ensure(options).import({ :plugin => myself }))
|
171
|
+
config.delete(:plugin)
|
172
|
+
config
|
171
173
|
end
|
172
174
|
|
173
175
|
#---
|
@@ -179,7 +181,7 @@ class Base < Core
|
|
179
181
|
#---
|
180
182
|
|
181
183
|
def extension_set(hook, value, options = {})
|
182
|
-
Nucleon.
|
184
|
+
Nucleon.value(hook_method(hook), value, Config.ensure(options).import({ :plugin => myself }))
|
183
185
|
end
|
184
186
|
|
185
187
|
#---
|
@@ -266,7 +268,7 @@ class Base < Core
|
|
266
268
|
|
267
269
|
def self.translate(data)
|
268
270
|
logger.debug("Translating data to internal plugin structure: #{data.inspect}")
|
269
|
-
return ( data.is_a?(Hash) ? symbol_map(data) :
|
271
|
+
return ( data.is_a?(Hash) ? symbol_map(data) : data )
|
270
272
|
end
|
271
273
|
|
272
274
|
#---
|
@@ -302,7 +304,7 @@ class Base < Core
|
|
302
304
|
|
303
305
|
def admin_exec(return_result = true, &code)
|
304
306
|
if Nucleon.admin?
|
305
|
-
safe_exec(return_result, &code)
|
307
|
+
safe_exec(return_result, &code)
|
306
308
|
else
|
307
309
|
ui.warn("The #{plugin_provider} action must be run as a machine administrator")
|
308
310
|
myself.status = code.access_denied
|
data/lib/core/util/cli.rb
CHANGED
@@ -35,7 +35,7 @@ module CLI
|
|
35
35
|
|
36
36
|
#---
|
37
37
|
|
38
|
-
def initialize(args, banner = '', help = '')
|
38
|
+
def initialize(args, banner = '', help = '', split_help = false)
|
39
39
|
|
40
40
|
@parser = OptionParser.new
|
41
41
|
|
@@ -50,7 +50,7 @@ module CLI
|
|
50
50
|
|
51
51
|
yield(self) if block_given?
|
52
52
|
|
53
|
-
parse_command(args)
|
53
|
+
parse_command(args, split_help)
|
54
54
|
end
|
55
55
|
|
56
56
|
#---
|
@@ -70,7 +70,7 @@ module CLI
|
|
70
70
|
end
|
71
71
|
|
72
72
|
main_args = args.dup if main_args.nil?
|
73
|
-
results = [ Parser.new(main_args, banner, separator) ]
|
73
|
+
results = [ Parser.new(main_args, banner, separator, true) ]
|
74
74
|
|
75
75
|
if sub_command
|
76
76
|
results << [ sub_command, sub_args ]
|
@@ -103,7 +103,7 @@ module CLI
|
|
103
103
|
|
104
104
|
#---
|
105
105
|
|
106
|
-
def parse_command(args)
|
106
|
+
def parse_command(args, split_help = false)
|
107
107
|
args = args.dup
|
108
108
|
error = false
|
109
109
|
|
@@ -117,14 +117,26 @@ module CLI
|
|
117
117
|
'--encoded STR',
|
118
118
|
'nucleon.core.util.cli.options.encoded'
|
119
119
|
)
|
120
|
-
|
121
|
-
options
|
122
|
-
|
120
|
+
if split_help
|
121
|
+
parser.on_tail('-h', CLI.message('nucleon.core.util.cli.options.short_help')) do
|
122
|
+
options[:help] = true
|
123
|
+
end
|
124
|
+
parser.on_tail('--help', CLI.message('nucleon.core.util.cli.options.extended_help')) do
|
125
|
+
options[:help] = true
|
126
|
+
options[:extended_help] = true
|
127
|
+
end
|
128
|
+
else
|
129
|
+
parser.on_tail('-h', '--help', CLI.message('nucleon.core.util.cli.options.short_help')) do
|
130
|
+
options[:help] = true
|
131
|
+
end
|
123
132
|
end
|
124
133
|
|
125
134
|
parser.parse!(args)
|
126
|
-
|
135
|
+
|
136
|
+
# Now we can act on options given
|
127
137
|
Nucleon.log_level = options[:log_level] if options[:log_level]
|
138
|
+
return if options[:help]
|
139
|
+
|
128
140
|
parse_encoded
|
129
141
|
|
130
142
|
remaining_args = args.dup
|
data/lib/core/util/data.rb
CHANGED
@@ -300,9 +300,6 @@ class Data
|
|
300
300
|
matches = item.match(regexp)
|
301
301
|
result = nil
|
302
302
|
|
303
|
-
#dbg(item, 'item')
|
304
|
-
#dbg(matches, 'matches')
|
305
|
-
|
306
303
|
unless matches.nil?
|
307
304
|
replacement = scope.search(matches[group], options)
|
308
305
|
result = item.gsub(matches[0], replacement) unless replacement.nil?
|
@@ -312,21 +309,16 @@ class Data
|
|
312
309
|
|
313
310
|
case value
|
314
311
|
when String
|
315
|
-
#dbg(value, 'interpolate (string) -> init')
|
316
312
|
while (temp = replace.call(value))
|
317
|
-
#dbg(temp, 'interpolate (string) -> replacement')
|
318
313
|
value = temp
|
319
314
|
end
|
320
315
|
|
321
316
|
when Hash
|
322
|
-
#dbg(value, 'interpolate (hash) -> init')
|
323
317
|
value.each do |key, data|
|
324
|
-
#dbg(data, "interpolate (#{key}) -> data")
|
325
318
|
value[key] = interpolate(data, scope, options)
|
326
319
|
end
|
327
320
|
end
|
328
321
|
end
|
329
|
-
#dbg(value, 'interpolate -> result')
|
330
322
|
return value
|
331
323
|
end
|
332
324
|
|
data/lib/nucleon.rb
CHANGED
@@ -9,167 +9,9 @@
|
|
9
9
|
# Author:: Adrian Webb (mailto:adrian.webb@coralnexus.com)
|
10
10
|
# License:: GPLv3
|
11
11
|
|
12
|
-
|
13
|
-
# Global namespace
|
14
|
-
|
15
|
-
module Kernel
|
16
|
-
|
17
|
-
def dbg(data, label = '')
|
18
|
-
# Invocations of this function should NOT be committed to the project
|
19
|
-
require 'pp'
|
20
|
-
|
21
|
-
puts '>>----------------------'
|
22
|
-
unless label.empty?
|
23
|
-
puts label
|
24
|
-
puts '---'
|
25
|
-
end
|
26
|
-
pp data
|
27
|
-
puts '<<'
|
28
|
-
end
|
29
|
-
|
30
|
-
#---
|
31
|
-
|
32
|
-
def nucleon_locate(command)
|
33
|
-
command = command.to_s
|
34
|
-
exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
|
35
|
-
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
|
36
|
-
exts.each do |ext|
|
37
|
-
exe = File.join(path, "#{command}#{ext}")
|
38
|
-
return exe if File.executable?(exe)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
return nil
|
42
|
-
end
|
43
|
-
|
44
|
-
#---
|
45
|
-
|
46
|
-
def nucleon_require(base_dir, name)
|
47
|
-
name = name.to_s
|
48
|
-
top_level_file = File.join(base_dir, "#{name}.rb")
|
49
|
-
|
50
|
-
require top_level_file if File.exists?(top_level_file)
|
51
|
-
|
52
|
-
directory = File.join(base_dir, name)
|
53
|
-
|
54
|
-
if File.directory?(directory)
|
55
|
-
Dir.glob(File.join(directory, '**', '*.rb')).each do |sub_file|
|
56
|
-
require sub_file
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
#-------------------------------------------------------------------------------
|
63
|
-
# Load paths
|
64
|
-
|
65
|
-
lib_dir = File.dirname(__FILE__)
|
66
|
-
core_dir = File.join(lib_dir, 'core')
|
67
|
-
mixin_dir = File.join(core_dir, 'mixin')
|
68
|
-
mixin_config_dir = File.join(mixin_dir, 'config')
|
69
|
-
mixin_action_dir = File.join(mixin_dir, 'action')
|
70
|
-
macro_dir = File.join(mixin_dir, 'macro')
|
71
|
-
util_dir = File.join(core_dir, 'util')
|
72
|
-
mod_dir = File.join(core_dir, 'mod')
|
73
|
-
plugin_dir = File.join(core_dir, 'plugin')
|
74
|
-
|
75
|
-
#-------------------------------------------------------------------------------
|
76
|
-
# Coral requirements
|
77
|
-
|
78
|
-
$:.unshift(lib_dir) unless $:.include?(lib_dir) || $:.include?(File.expand_path(lib_dir))
|
79
|
-
|
80
|
-
#---
|
81
|
-
|
82
|
-
require 'rubygems'
|
83
|
-
|
84
|
-
require 'optparse'
|
85
|
-
require 'pp'
|
86
|
-
require 'i18n'
|
87
|
-
require 'log4r'
|
88
|
-
require 'log4r/configurator'
|
89
|
-
require 'deep_merge'
|
90
|
-
|
91
|
-
require 'digest/sha1'
|
92
|
-
require 'base64'
|
93
|
-
|
94
|
-
require 'yaml'
|
95
|
-
require 'multi_json'
|
96
|
-
|
97
|
-
require 'thread' # Eventually depreciated
|
98
|
-
require 'celluloid'
|
99
|
-
require 'celluloid/autostart'
|
100
|
-
|
101
|
-
#---
|
102
|
-
|
103
|
-
# TODO: Make this dynamically settable
|
104
|
-
|
105
|
-
I18n.enforce_available_locales = false
|
106
|
-
I18n.load_path << File.expand_path(File.join('..', 'locales', 'en.yml'), lib_dir)
|
107
|
-
|
108
|
-
#---
|
109
|
-
|
110
|
-
if nucleon_locate('git')
|
111
|
-
require 'grit'
|
112
|
-
nucleon_require(util_dir, :git)
|
113
|
-
end
|
114
|
-
|
115
|
-
#---
|
116
|
-
|
117
|
-
# Make sure logger is at the top of our load order priorities
|
118
|
-
nucleon_require(util_dir, :logger)
|
119
|
-
|
120
|
-
#---
|
121
|
-
|
122
|
-
# Object modifications (100% pure monkey patches)
|
123
|
-
Dir.glob(File.join(mod_dir, '*.rb')).each do |file|
|
124
|
-
require file
|
125
|
-
end
|
126
|
-
|
127
|
-
#---
|
128
|
-
|
129
|
-
# Mixins for classes
|
130
|
-
Dir.glob(File.join(mixin_dir, '*.rb')).each do |file|
|
131
|
-
require file
|
132
|
-
end
|
133
|
-
Dir.glob(File.join(mixin_config_dir, '*.rb')).each do |file|
|
134
|
-
require file
|
135
|
-
end
|
136
|
-
Dir.glob(File.join(mixin_action_dir, '*.rb')).each do |file|
|
137
|
-
require file
|
138
|
-
end
|
139
|
-
Dir.glob(File.join(macro_dir, '*.rb')).each do |file|
|
140
|
-
require file
|
141
|
-
end
|
142
|
-
|
143
|
-
#---
|
144
|
-
|
145
|
-
# Include bootstrap classes
|
146
|
-
nucleon_require(core_dir, :errors)
|
147
|
-
nucleon_require(core_dir, :codes)
|
148
|
-
nucleon_require(util_dir, :data)
|
149
|
-
nucleon_require(core_dir, :config)
|
150
|
-
nucleon_require(util_dir, :console)
|
151
|
-
nucleon_require(core_dir, :core)
|
152
|
-
|
153
|
-
#---
|
154
|
-
|
155
|
-
# Include core utilities
|
156
|
-
[ :liquid,
|
157
|
-
:cli,
|
158
|
-
:disk,
|
159
|
-
:package,
|
160
|
-
:shell
|
161
|
-
].each do |name|
|
162
|
-
nucleon_require(util_dir, name)
|
163
|
-
end
|
164
|
-
|
165
|
-
# Include plugin system
|
166
|
-
nucleon_require(core_dir, :facade)
|
167
|
-
nucleon_require(core_dir, :gems)
|
168
|
-
nucleon_require(core_dir, :manager)
|
169
|
-
nucleon_require(plugin_dir, :base)
|
170
|
-
nucleon_require(core_dir, :plugin)
|
12
|
+
require File.join(File.dirname(__FILE__), "nucleon_base.rb")
|
171
13
|
|
172
14
|
#-------------------------------------------------------------------------------
|
173
|
-
#
|
15
|
+
# Core initialization
|
174
16
|
|
175
|
-
Nucleon.reload
|
17
|
+
Nucleon.reload(true)
|
data/lib/nucleon/action/add.rb
CHANGED
@@ -1,67 +1,61 @@
|
|
1
1
|
|
2
2
|
module Nucleon
|
3
3
|
module Action
|
4
|
-
class Add <
|
4
|
+
class Add < Nucleon.plugin_class(:action)
|
5
5
|
|
6
6
|
include Mixin::Action::Project
|
7
7
|
include Mixin::Action::Push
|
8
8
|
|
9
9
|
#-----------------------------------------------------------------------------
|
10
|
-
#
|
10
|
+
# Settings
|
11
11
|
|
12
|
-
def
|
13
|
-
super
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
12
|
+
def configure
|
13
|
+
super do
|
14
|
+
codes :project_failure,
|
15
|
+
:add_failure,
|
16
|
+
:push_failure
|
17
|
+
|
18
|
+
register :sub_path, :str, nil
|
19
|
+
register :editable, :bool, false
|
20
|
+
|
21
|
+
project_config
|
22
|
+
push_config
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
#---
|
27
|
+
|
28
|
+
def arguments
|
29
|
+
[ :sub_path, :project_reference ]
|
18
30
|
end
|
19
31
|
|
20
32
|
#-----------------------------------------------------------------------------
|
21
33
|
# Action operations
|
22
34
|
|
23
|
-
def parse(parser)
|
24
|
-
parser.arg_str(:sub_path, nil,
|
25
|
-
'nucleon.core.actions.add.options.sub_path'
|
26
|
-
)
|
27
|
-
parser.arg_str(:sub_reference, nil,
|
28
|
-
'nucleon.core.actions.add.options.sub_reference'
|
29
|
-
)
|
30
|
-
parser.option_bool(:editable, false,
|
31
|
-
'--editable',
|
32
|
-
'nucleon.core.actions.add.options.editable'
|
33
|
-
)
|
34
|
-
project_options(parser, true, true)
|
35
|
-
push_options(parser, true)
|
36
|
-
end
|
37
|
-
|
38
|
-
#---
|
39
|
-
|
40
35
|
def execute
|
41
|
-
super do
|
42
|
-
info('nucleon.
|
36
|
+
super do
|
37
|
+
info('nucleon.actions.add.start')
|
43
38
|
|
44
39
|
if project = project_load(Dir.pwd, false)
|
45
|
-
sub_info = project.translate_reference(settings[:
|
40
|
+
sub_info = project.translate_reference(settings[:project_reference], settings[:editable])
|
46
41
|
sub_path = settings[:sub_path]
|
47
42
|
|
48
43
|
if sub_info
|
49
44
|
sub_url = sub_info[:url]
|
50
45
|
sub_revision = sub_info[:revision]
|
51
46
|
else
|
52
|
-
sub_url = settings[:
|
47
|
+
sub_url = settings[:project_reference]
|
53
48
|
sub_revision = nil
|
54
49
|
end
|
55
50
|
|
56
51
|
if project.add_subproject(sub_path, sub_url, sub_revision)
|
57
|
-
status = code.push_failure unless push(project)
|
52
|
+
myself.status = code.push_failure unless push(project)
|
58
53
|
else
|
59
|
-
status = code.add_failure
|
54
|
+
myself.status = code.add_failure
|
60
55
|
end
|
61
56
|
else
|
62
|
-
status = code.project_failure
|
63
|
-
end
|
64
|
-
status
|
57
|
+
myself.status = code.project_failure
|
58
|
+
end
|
65
59
|
end
|
66
60
|
end
|
67
61
|
end
|
@@ -1,50 +1,45 @@
|
|
1
1
|
|
2
2
|
module Nucleon
|
3
3
|
module Action
|
4
|
-
class Create <
|
5
|
-
|
6
|
-
#-----------------------------------------------------------------------------
|
7
|
-
# Create action interface
|
4
|
+
class Create < Nucleon.plugin_class(:action)
|
8
5
|
|
9
|
-
|
10
|
-
super('nucleon create [ <project:::reference> ]')
|
11
|
-
|
12
|
-
codes :project_failure => 20
|
13
|
-
end
|
6
|
+
include Mixin::Action::Project
|
14
7
|
|
15
8
|
#-----------------------------------------------------------------------------
|
16
|
-
#
|
9
|
+
# Settings
|
17
10
|
|
18
|
-
def
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
)
|
27
|
-
parser.arg_str(:reference,
|
28
|
-
'github:::coralnexus/puppet-cloud-template',
|
29
|
-
'nucleon.core.actions.create.options.reference'
|
30
|
-
)
|
11
|
+
def configure
|
12
|
+
super do
|
13
|
+
codes :project_failure
|
14
|
+
|
15
|
+
register :path, :str, Dir.pwd
|
16
|
+
|
17
|
+
project_config
|
18
|
+
end
|
31
19
|
end
|
32
20
|
|
33
21
|
#---
|
22
|
+
|
23
|
+
def arguments
|
24
|
+
[ :project_reference ]
|
25
|
+
end
|
26
|
+
|
27
|
+
#-----------------------------------------------------------------------------
|
28
|
+
# Operations
|
34
29
|
|
35
30
|
def execute
|
36
|
-
super do |node, network
|
37
|
-
info('nucleon.
|
31
|
+
super do |node, network|
|
32
|
+
info('nucleon.actions.create.start')
|
38
33
|
|
39
34
|
project = Nucleon.project(extended_config(:project, {
|
40
35
|
:create => true,
|
41
36
|
:directory => settings[:path],
|
42
|
-
:url => settings[:
|
37
|
+
:url => settings[:project_reference],
|
43
38
|
:revision => settings[:revision],
|
44
39
|
:pull => true
|
45
|
-
}))
|
40
|
+
}), settings[:project_provider])
|
46
41
|
|
47
|
-
|
42
|
+
myself.status = code.project_failure unless project
|
48
43
|
end
|
49
44
|
end
|
50
45
|
end
|