falkorlib 0.6.19 → 0.7.0
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.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +88 -0
- data/.travis.yml +56 -4
- data/Gemfile +4 -4
- data/Gemfile.lock +55 -27
- data/Rakefile +12 -8
- data/Vagrantfile +68 -0
- data/completion/_falkor +55 -7
- data/falkorlib.gemspec +14 -12
- data/lib/falkorlib.rb +22 -21
- data/lib/falkorlib/bootstrap.rb +5 -1
- data/lib/falkorlib/bootstrap/base.rb +385 -693
- data/lib/falkorlib/bootstrap/git.rb +137 -0
- data/lib/falkorlib/bootstrap/latex.rb +186 -0
- data/lib/falkorlib/bootstrap/link.rb +108 -96
- data/lib/falkorlib/bootstrap/ruby.rb +102 -0
- data/lib/falkorlib/cli.rb +82 -26
- data/lib/falkorlib/cli/config.rb +8 -8
- data/lib/falkorlib/cli/link.rb +8 -9
- data/lib/falkorlib/cli/new.rb +25 -39
- data/lib/falkorlib/common.rb +425 -425
- data/lib/falkorlib/config.rb +114 -110
- data/lib/falkorlib/error.rb +27 -16
- data/lib/falkorlib/gem_tasks.rb +12 -11
- data/lib/falkorlib/git.rb +3 -4
- data/lib/falkorlib/git/base.rb +439 -396
- data/lib/falkorlib/git/flow.rb +163 -165
- data/lib/falkorlib/git_tasks.rb +31 -31
- data/lib/falkorlib/loader.rb +1 -1
- data/lib/falkorlib/puppet.rb +3 -5
- data/lib/falkorlib/puppet/base.rb +10 -15
- data/lib/falkorlib/puppet/modules.rb +367 -365
- data/lib/falkorlib/puppet_tasks.rb +11 -8
- data/lib/falkorlib/tasks.rb +51 -54
- data/lib/falkorlib/tasks/gem.rake +42 -43
- data/lib/falkorlib/tasks/gem.rb +12 -11
- data/lib/falkorlib/tasks/git.rake +101 -107
- data/lib/falkorlib/tasks/git.rb +31 -31
- data/lib/falkorlib/tasks/gitflow.rake +131 -141
- data/lib/falkorlib/tasks/puppet.rb +11 -8
- data/lib/falkorlib/tasks/puppet_modules.rake +143 -154
- data/lib/falkorlib/tasks/rspec.rake +94 -59
- data/lib/falkorlib/tasks/yard.rake +35 -39
- data/lib/falkorlib/version.rb +55 -55
- data/lib/falkorlib/versioning.rb +169 -167
- data/spec/falkorlib/bootstrap_helpers_spec.rb +106 -56
- data/spec/falkorlib/bootstrap_latex_spec.rb +145 -0
- data/spec/falkorlib/bootstrap_link_spec.rb +137 -0
- data/spec/falkorlib/bootstrap_ruby_spec.rb +118 -0
- data/spec/falkorlib/bootstrap_spec.rb +112 -129
- data/spec/falkorlib/git_spec.rb +94 -22
- data/spec/falkorlib/gitflow_spec.rb +54 -42
- data/spec/falkorlib/puppet_modules_spec.rb +35 -26
- data/spec/falkorlib/versioning_puppet_module_spec.rb +94 -90
- data/spec/falkorlib_spec.rb +5 -0
- data/spec/spec_helper.rb +88 -47
- data/templates/latex/article-ieee/main.tex.erb +509 -0
- data/templates/latex/article/_abstract.tex.erb +19 -0
- data/templates/latex/article/_acronyms.tex.erb +116 -0
- data/templates/latex/article/_conclusion.tex.erb +25 -0
- data/templates/latex/article/_context.tex.erb +17 -0
- data/templates/latex/article/_experiments.tex.erb +27 -0
- data/templates/latex/article/_implem.tex.erb +17 -0
- data/templates/latex/article/_introduction.tex.erb +39 -0
- data/templates/latex/article/_related_works.tex.erb +19 -0
- data/templates/latex/article/biblio.bib.erb +28 -0
- data/templates/latex/article/template.tex.erb +16 -0
- data/templates/latex/ieee/IEEEtran.bst +2409 -0
- data/templates/latex/ieee/IEEEtran.cls +6347 -0
- data/templates/motd/motd.erb +2 -1
- metadata +82 -2
@@ -1,6 +1,6 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
################################################################################
|
3
|
-
# Time-stamp: <
|
3
|
+
# Time-stamp: <Fri 2016-11-11 15:58 svarrette>
|
4
4
|
################################################################################
|
5
5
|
# Interface for the main Puppet operations
|
6
6
|
#
|
@@ -11,20 +11,15 @@ require "falkorlib/common"
|
|
11
11
|
|
12
12
|
include FalkorLib::Common
|
13
13
|
|
14
|
-
module FalkorLib
|
15
|
-
|
16
|
-
|
17
|
-
# Puppet defaults for FalkorLib
|
18
|
-
DEFAULTS = {
|
19
|
-
:modulesdir => File.join(Dir.pwd, 'modules')
|
20
|
-
}
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
module Puppet #:nodoc
|
25
|
-
|
26
|
-
end
|
27
|
-
|
14
|
+
module FalkorLib #:nodoc:
|
15
|
+
module Config
|
16
|
+
module Puppet
|
28
17
|
|
18
|
+
# Puppet defaults for FalkorLib
|
19
|
+
DEFAULTS = {
|
20
|
+
:modulesdir => File.join(Dir.pwd, 'modules')
|
21
|
+
}
|
29
22
|
|
23
|
+
end
|
24
|
+
end
|
30
25
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
################################################################################
|
3
|
-
# Time-stamp: <
|
3
|
+
# Time-stamp: <Sat 2016-11-12 12:18 svarrette>
|
4
4
|
################################################################################
|
5
5
|
# Interface for the main Puppet Module operations
|
6
6
|
#
|
@@ -14,392 +14,394 @@ require 'diffy'
|
|
14
14
|
|
15
15
|
include FalkorLib::Common
|
16
16
|
|
17
|
-
module FalkorLib
|
18
|
-
module Config
|
19
|
-
module Puppet
|
20
|
-
module Modules
|
21
|
-
DEFAULTS = {
|
22
|
-
:metadata => {
|
23
|
-
:name => '',
|
24
|
-
:version => '0.0.1',
|
25
|
-
:author => "#{ENV['GIT_AUTHOR_NAME']}",
|
26
|
-
:mail => "#{ENV['GIT_AUTHOR_EMAIL']}",
|
27
|
-
:summary => "Configure and manage rtfm",
|
28
|
-
:description => '',
|
29
|
-
:license => 'Apache-2.0',
|
30
|
-
:source => '',
|
31
|
-
:project_page => '',
|
32
|
-
:issues_url => '',
|
33
|
-
:forge_url => 'https://forge.puppetlabs.com',
|
34
|
-
:dependencies => [],
|
35
|
-
:operatingsystem_support => [],
|
36
|
-
:tags => []
|
37
|
-
},
|
38
|
-
:licenses => [
|
39
|
-
"Apache-2.0",
|
40
|
-
"BSD",
|
41
|
-
"GPL-2.0",
|
42
|
-
"GPL-3.0",
|
43
|
-
"LGPL-2.1",
|
44
|
-
"LGPL-3.0",
|
45
|
-
"MIT"
|
46
|
-
]
|
47
|
-
}
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
17
|
+
module FalkorLib #:nodoc:
|
51
18
|
|
52
|
-
|
19
|
+
module Config
|
53
20
|
module Puppet
|
54
|
-
|
55
|
-
module Modules
|
56
|
-
|
57
|
-
module_function
|
21
|
+
module Modules
|
58
22
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
23
|
+
DEFAULTS = {
|
24
|
+
:metadata => {
|
25
|
+
:name => '',
|
26
|
+
:version => '0.0.1',
|
27
|
+
:author => `git config user.name`.chomp,
|
28
|
+
:mail => `git config user.email`.chomp,
|
29
|
+
:summary => "Configure and manage rtfm",
|
30
|
+
:description => '',
|
31
|
+
:license => 'Apache-2.0',
|
32
|
+
:source => '',
|
33
|
+
:project_page => '',
|
34
|
+
:issues_url => '',
|
35
|
+
:forge_url => 'https://forge.puppetlabs.com',
|
36
|
+
:dependencies => [],
|
37
|
+
:operatingsystem_support => [],
|
38
|
+
:tags => []
|
39
|
+
},
|
40
|
+
:licenses => [
|
41
|
+
"Apache-2.0",
|
42
|
+
"BSD",
|
43
|
+
"GPL-2.0",
|
44
|
+
"GPL-3.0",
|
45
|
+
"LGPL-2.1",
|
46
|
+
"LGPL-3.0",
|
47
|
+
"MIT"
|
48
|
+
]
|
49
|
+
}
|
81
50
|
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
82
54
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
##
|
88
|
-
def init(rootdir = Dir.pwd, name = '', options = {})
|
89
|
-
config = {}
|
90
|
-
#login = `whoami`.chomp
|
91
|
-
config[:name] = name unless name.empty?
|
92
|
-
moduledir = rootdir
|
93
|
-
#name.empty? ? rootdir : File.join(rootdir, name)
|
94
|
-
FalkorLib::Config::Puppet::Modules::DEFAULTS[:metadata].each do |k,v|
|
95
|
-
next if v.kind_of?(Array) or k == :license
|
96
|
-
next if k == :name and ! name.empty?
|
97
|
-
default_answer = case k
|
98
|
-
when :project_page
|
99
|
-
config[:source].nil? ? v : config[:source]
|
100
|
-
when :name
|
101
|
-
File.basename(rootdir).gsub(/^puppet-/, '')
|
102
|
-
when :issues_url
|
103
|
-
config[:project_page].nil? ? v : "#{config[:project_page]}/issues"
|
104
|
-
when :forge_url
|
105
|
-
v + '/' + config[:name].gsub(/-/,'/')
|
106
|
-
when :description
|
107
|
-
config[:summary].nil? ? v : "#{config[:summary]}"
|
108
|
-
when :source
|
109
|
-
v.empty? ? "https://github.com/#{config[:name].gsub(/\//,'/puppet-')}" : v
|
110
|
-
else
|
111
|
-
v
|
112
|
-
end
|
113
|
-
config[k.to_sym] = ask( "\t" + sprintf("%-20s", "Module #{k}"), default_answer)
|
114
|
-
end
|
115
|
-
config[:shortname] = name = config[:name].gsub(/.*[-\/]/, '')
|
116
|
-
config[:docs_project] = ask("\tRead the Docs (RTFD) project:", config[:name].downcase.gsub(/\//,'-puppet-'))
|
117
|
-
tags = ask("\tKeywords (comma-separated list of tags)", config[:shortname])
|
118
|
-
config[:tags] = tags.split(',')
|
119
|
-
list_license = FalkorLib::Config::Puppet::Modules::DEFAULTS[:licenses]
|
120
|
-
default_license = FalkorLib::Config::Puppet::Modules::DEFAULTS[:metadata][:license]
|
121
|
-
idx = list_license.index(default_license) unless default_license.nil?
|
122
|
-
license = select_from(list_license,
|
123
|
-
'Select the license index for the Puppet module:',
|
124
|
-
idx.nil? ? 1 : idx + 1)
|
125
|
-
config[:license] = license unless license.empty?
|
126
|
-
puts "\t" + sprintf("%-20s", "Module License:") + config[:license]
|
55
|
+
# Puppet actions
|
56
|
+
module Puppet
|
57
|
+
# Management of Puppet Modules operations
|
58
|
+
module Modules
|
127
59
|
|
128
|
-
|
129
|
-
config[:platforms] = [ 'debian' ]
|
130
|
-
config[:dependencies] = [{
|
131
|
-
"name" => "puppetlabs-stdlib",
|
132
|
-
"version_requirement" => ">=4.2.2 <5.0.0"
|
133
|
-
}]
|
134
|
-
config[:params] = [ 'ensure', 'protocol', 'port', 'packagename' ]
|
135
|
-
#ap config
|
136
|
-
# Bootstrap the directory
|
137
|
-
templatedir = File.join( FalkorLib.templates, 'puppet', 'modules')
|
138
|
-
init_from_template(templatedir, moduledir, config, {
|
139
|
-
:erb_exclude => [ 'templates\/[^\/]*variables\.erb$' ],
|
140
|
-
:no_interaction => true
|
141
|
-
})
|
142
|
-
# Rename the files / element templatename
|
143
|
-
Dir["#{moduledir}/**/*"].each do |e|
|
144
|
-
next unless e =~ /templatename/
|
145
|
-
info "renaming #{e}"
|
146
|
-
newname = e.gsub(/templatename/, "#{name}")
|
147
|
-
run %{ mv #{e} #{newname} }
|
148
|
-
end
|
149
|
-
# Update docs directory
|
150
|
-
run %{ ln -s ../README.md #{moduledir}/docs/overview.md }
|
151
|
-
info "Generating the License file"
|
152
|
-
authors = config[:author].empty? ? 'UNKNOWN' : config[:author]
|
153
|
-
Dir.chdir(moduledir) do
|
154
|
-
run %{ licgen #{config[:license].downcase} #{authors} }
|
155
|
-
end
|
156
|
-
info "Initialize RVM"
|
157
|
-
init_rvm(moduledir)
|
158
|
-
unless FalkorLib::Git.init?(moduledir)
|
159
|
-
init_gitflow = FalkorLib::Git.command?('flow')
|
160
|
-
warn "Git #{init_gitflow ? '[Flow]' : ''} is not initialized in #{moduledir}."
|
161
|
-
a = ask("Proceed to git-flow initialization (Y|n)", 'Yes')
|
162
|
-
return if a =~ /n.*/i
|
163
|
-
init_gitflow ? FalkorLib::GitFlow.init(moduledir) : FalkorLib::Git.init(moduledir)
|
164
|
-
end
|
60
|
+
module_function
|
165
61
|
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
62
|
+
def _get_classdefs(moduledir = Dir.pwd, type = 'classes')
|
63
|
+
name = File.basename( moduledir )
|
64
|
+
error "The module #{name} does not exist" unless File.directory?( moduledir )
|
65
|
+
t = case type
|
66
|
+
when /class*/i
|
67
|
+
'class'
|
68
|
+
when /def*/
|
69
|
+
'define'
|
70
|
+
else
|
71
|
+
''
|
72
|
+
end
|
73
|
+
error "Undefined type #{type}" if t.empty?
|
74
|
+
result = []
|
75
|
+
Dir["#{moduledir}/manifests/**/*.pp"].each do |ppfile|
|
76
|
+
#puts "=> testing #{ppfile}"
|
77
|
+
File.read(ppfile).scan(/^[ \t]*#{t}[\s]+([0-9a-zA-z:-]+).*$/).each do |line|
|
78
|
+
result << line[0]
|
79
|
+
end
|
80
|
+
end
|
81
|
+
result.uniq!
|
82
|
+
result.sort
|
83
|
+
end
|
180
84
|
|
181
|
-
####
|
182
|
-
# Parse a given modules to collect information
|
183
|
-
# Supported options:
|
184
|
-
# :no_interaction [boolean]: do not interact
|
185
|
-
#
|
186
|
-
def parse(moduledir = Dir.pwd, options = {
|
187
|
-
:no_interaction => false
|
188
|
-
})
|
189
|
-
name = File.basename(moduledir)
|
190
|
-
metadata = metadata(moduledir, {
|
191
|
-
:use_symbols => false,
|
192
|
-
:extras => false,
|
193
|
-
:no_interaction => options[:no_interaction]
|
194
|
-
})
|
195
|
-
puts metadata.to_yaml
|
196
|
-
# error "The module #{name} does not exist" unless File.directory?( moduledir )
|
197
|
-
jsonfile = File.join( moduledir, 'metadata.json')
|
198
|
-
# error "Unable to find #{jsonfile}" unless File.exist?( jsonfile )
|
199
|
-
# metadata = JSON.parse( IO.read( jsonfile ) )
|
200
|
-
ref = JSON.pretty_generate( metadata )
|
201
|
-
metadata["classes"] = classes(moduledir)
|
202
|
-
metadata["definitions"] = definitions(moduledir)
|
203
|
-
deps = deps(moduledir)
|
204
|
-
listed_deps = metadata["dependencies"]
|
205
|
-
missed_deps = []
|
206
|
-
metadata["dependencies"].each do |dep|
|
207
|
-
lib = dep["name"].gsub(/^[^\/-]+[\/-]/,'')
|
208
|
-
if deps.include?( lib )
|
209
|
-
deps.delete( lib )
|
210
|
-
else
|
211
|
-
unless lib =~ /stdlib/
|
212
|
-
warn "The library '#{dep["name"]}' is not analyzed as part of the #{metadata['shortname']} module"
|
213
|
-
missed_deps << dep
|
214
|
-
end
|
215
|
-
end
|
216
|
-
end
|
217
|
-
if ! deps.empty?
|
218
|
-
deps.each do |l|
|
219
|
-
next if [name, metadata["name"], name.gsub(/.*-/, ''), metadata["name"].gsub(/.*-/, '') ].include? ( l )
|
220
|
-
warn "The module '#{l}' is missing in the dependencies thus added"
|
221
|
-
login = ask("[Github] login for the module '#{l}'")
|
222
|
-
version = ask("Version requirement (ex: '>=1.0.0 <2.0.0' or '1.2.3' or '1.x')")
|
223
|
-
metadata["dependencies"] << {
|
224
|
-
"name" => "#{login}/#{l}",
|
225
|
-
"version_requirement" => "#{version}"
|
226
|
-
}
|
227
|
-
end
|
228
|
-
end
|
229
|
-
content = JSON.pretty_generate( metadata )
|
230
|
-
info "Metadata configuration for the module '#{name}'"
|
231
|
-
puts content
|
232
|
-
show_diff_and_write(content, jsonfile, {
|
233
|
-
:no_interaction => options[:no_interaction],
|
234
|
-
:json_pretty_format => true
|
235
|
-
})
|
236
|
-
metadata
|
237
|
-
end # parse
|
238
85
|
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
86
|
+
####
|
87
|
+
# Initialize a new Puppet Module named `name` in `rootdir`.
|
88
|
+
# Supported options:
|
89
|
+
# * :no_iteraction [boolean]
|
90
|
+
##
|
91
|
+
def init(rootdir = Dir.pwd, name = '', _options = {})
|
92
|
+
config = {}
|
93
|
+
#login = `whoami`.chomp
|
94
|
+
config[:name] = name unless name.empty?
|
95
|
+
moduledir = rootdir
|
96
|
+
#name.empty? ? rootdir : File.join(rootdir, name)
|
97
|
+
FalkorLib::Config::Puppet::Modules::DEFAULTS[:metadata].each do |k, v|
|
98
|
+
next if v.is_a?(Array) || (k == :license)
|
99
|
+
next if (k == :name) && !name.empty?
|
100
|
+
default_answer = case k
|
101
|
+
when :project_page
|
102
|
+
(config[:source].nil?) ? v : config[:source]
|
103
|
+
when :name
|
104
|
+
File.basename(rootdir).gsub(/^puppet-/, '')
|
105
|
+
when :issues_url
|
106
|
+
(config[:project_page].nil?) ? v : "#{config[:project_page]}/issues"
|
107
|
+
when :forge_url
|
108
|
+
v + '/' + config[:name].tr('-', '/')
|
109
|
+
when :description
|
110
|
+
(config[:summary].nil?) ? v : (config[:summary]).to_s
|
111
|
+
when :source
|
112
|
+
(v.empty?) ? "https://github.com/#{config[:name].gsub(/\//, '/puppet-')}" : v
|
113
|
+
else
|
114
|
+
v
|
115
|
+
end
|
116
|
+
config[k.to_sym] = ask( "\t" + Kernel.format("%-20s", "Module #{k}"), default_answer)
|
117
|
+
end
|
118
|
+
config[:shortname] = name = config[:name].gsub(/.*[-\/]/, '')
|
119
|
+
config[:docs_project] = ask("\tRead the Docs (RTFD) project:", config[:name].downcase.gsub(/\//, '-puppet-'))
|
120
|
+
tags = ask("\tKeywords (comma-separated list of tags)", config[:shortname])
|
121
|
+
config[:tags] = tags.split(',')
|
122
|
+
list_license = FalkorLib::Config::Puppet::Modules::DEFAULTS[:licenses]
|
123
|
+
default_license = FalkorLib::Config::Puppet::Modules::DEFAULTS[:metadata][:license]
|
124
|
+
idx = list_license.index(default_license) unless default_license.nil?
|
125
|
+
license = select_from(list_license,
|
126
|
+
'Select the license index for the Puppet module:',
|
127
|
+
(idx.nil?) ? 1 : idx + 1)
|
128
|
+
config[:license] = license unless license.empty?
|
129
|
+
puts "\t" + format("%-20s", "Module License:") + config[:license]
|
281
130
|
|
131
|
+
# Supported platforms
|
132
|
+
config[:platforms] = [ 'debian' ]
|
133
|
+
config[:dependencies] = [{
|
134
|
+
"name" => "puppetlabs-stdlib",
|
135
|
+
"version_requirement" => ">=4.2.2 <5.0.0"
|
136
|
+
}]
|
137
|
+
config[:params] = %w(ensure protocol port packagename)
|
138
|
+
#ap config
|
139
|
+
# Bootstrap the directory
|
140
|
+
templatedir = File.join( FalkorLib.templates, 'puppet', 'modules')
|
141
|
+
init_from_template(templatedir, moduledir, config, :erb_exclude => [ 'templates\/[^\/]*variables\.erb$' ],
|
142
|
+
:no_interaction => true)
|
143
|
+
# Rename the files / element templatename
|
144
|
+
Dir["#{moduledir}/**/*"].each do |e|
|
145
|
+
next unless e =~ /templatename/
|
146
|
+
info "renaming #{e}"
|
147
|
+
newname = e.gsub(/templatename/, name.to_s)
|
148
|
+
run %( mv #{e} #{newname} )
|
149
|
+
end
|
150
|
+
# Update docs directory
|
151
|
+
run %( ln -s ../README.md #{moduledir}/docs/overview.md )
|
152
|
+
info "Generating the License file"
|
153
|
+
authors = (config[:author].empty?) ? 'UNKNOWN' : config[:author]
|
154
|
+
Dir.chdir(moduledir) do
|
155
|
+
run %( licgen #{config[:license].downcase} #{authors} )
|
156
|
+
end
|
157
|
+
info "Initialize RVM"
|
158
|
+
init_rvm(moduledir)
|
159
|
+
unless FalkorLib::Git.init?(moduledir)
|
160
|
+
init_gitflow = FalkorLib::Git.command?('flow')
|
161
|
+
warn "Git #{(init_gitflow) ? '[Flow]' : ''} is not initialized in #{moduledir}."
|
162
|
+
a = ask("Proceed to git-flow initialization (Y|n)", 'Yes')
|
163
|
+
return if a =~ /n.*/i
|
164
|
+
(init_gitflow) ? FalkorLib::GitFlow.init(moduledir) : FalkorLib::Git.init(moduledir)
|
165
|
+
end
|
282
166
|
|
167
|
+
# Propose to commit the key files
|
168
|
+
if FalkorLib::Git.init?(moduledir)
|
169
|
+
if FalkorLib::GitFlow.init?(moduledir)
|
170
|
+
info "=> preparing git-flow feature for the newly created module '#{config[:name]}'"
|
171
|
+
FalkorLib::GitFlow.start('feature', "bootstrapping", moduledir)
|
172
|
+
end
|
173
|
+
[ 'metadata.json',
|
174
|
+
'docs/', 'mkdocs.yml', 'LICENSE', '.gitignore', '.pmtignore',
|
175
|
+
'.ruby-version', '.ruby-gemset', 'Gemfile',
|
176
|
+
'.vagrant_init.rb', 'Rakefile', 'Vagrantfile' ].each do |f|
|
177
|
+
FalkorLib::Git.add(File.join(moduledir, f))
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end # init
|
283
181
|
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
puts "=> updating #{f}.erb"
|
316
|
-
i += write_from_erb_template(File.join(templatedir, "#{f}.erb"),
|
317
|
-
File.join(moduledir, f),
|
318
|
-
metadata,
|
319
|
-
options)
|
320
|
-
else
|
321
|
-
i+= write_from_template(f, moduledir, {
|
322
|
-
:no_interaction => options[:no_interaction],
|
323
|
-
:srcdir => templatedir
|
324
|
-
})
|
325
|
-
end
|
326
|
-
end
|
327
|
-
i
|
182
|
+
####
|
183
|
+
# Parse a given modules to collect information
|
184
|
+
# Supported options:
|
185
|
+
# :no_interaction [boolean]: do not interact
|
186
|
+
#
|
187
|
+
def parse(moduledir = Dir.pwd, options = {
|
188
|
+
:no_interaction => false
|
189
|
+
})
|
190
|
+
name = File.basename(moduledir)
|
191
|
+
metadata = metadata(moduledir, :use_symbols => false,
|
192
|
+
:extras => false,
|
193
|
+
:no_interaction => options[:no_interaction])
|
194
|
+
puts metadata.to_yaml
|
195
|
+
# error "The module #{name} does not exist" unless File.directory?( moduledir )
|
196
|
+
jsonfile = File.join( moduledir, 'metadata.json')
|
197
|
+
# error "Unable to find #{jsonfile}" unless File.exist?( jsonfile )
|
198
|
+
# metadata = JSON.parse( IO.read( jsonfile ) )
|
199
|
+
#ref = JSON.pretty_generate( metadata )
|
200
|
+
metadata["classes"] = classes(moduledir)
|
201
|
+
metadata["definitions"] = definitions(moduledir)
|
202
|
+
deps = deps(moduledir)
|
203
|
+
#listed_deps = metadata["dependencies"]
|
204
|
+
missed_deps = []
|
205
|
+
metadata["dependencies"].each do |dep|
|
206
|
+
lib = dep["name"].gsub(/^[^\/-]+[\/-]/, '')
|
207
|
+
if deps.include?( lib )
|
208
|
+
deps.delete( lib )
|
209
|
+
else
|
210
|
+
unless lib =~ /stdlib/
|
211
|
+
warn "The library '#{dep['name']}' is not analyzed as part of the #{metadata['shortname']} module"
|
212
|
+
missed_deps << dep
|
328
213
|
end
|
214
|
+
end
|
215
|
+
end
|
216
|
+
unless deps.empty?
|
217
|
+
deps.each do |l|
|
218
|
+
next if [name, metadata["name"], name.gsub(/.*-/, ''), metadata["name"].gsub(/.*-/, '') ].include?( l )
|
219
|
+
warn "The module '#{l}' is missing in the dependencies thus added"
|
220
|
+
login = ask("[Github] login for the module '#{l}'")
|
221
|
+
version = ask("Version requirement (ex: '>=1.0.0 <2.0.0' or '1.2.3' or '1.x')")
|
222
|
+
metadata["dependencies"] << {
|
223
|
+
"name" => "#{login}/#{l}",
|
224
|
+
"version_requirement" => version.to_s
|
225
|
+
}
|
226
|
+
end
|
227
|
+
end
|
228
|
+
content = JSON.pretty_generate( metadata )
|
229
|
+
info "Metadata configuration for the module '#{name}'"
|
230
|
+
puts content
|
231
|
+
show_diff_and_write(content, jsonfile, :no_interaction => options[:no_interaction],
|
232
|
+
:json_pretty_format => true)
|
233
|
+
metadata
|
234
|
+
end # parse
|
329
235
|
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
236
|
+
###
|
237
|
+
# Retrieves the metadata from the metadata.json file in `moduledir`.
|
238
|
+
# Supported options:
|
239
|
+
# :use_symbols [boolean]: convert all keys to symbols
|
240
|
+
# :extras [boolean]: add extra keys
|
241
|
+
#
|
242
|
+
def metadata(moduledir = Dir.pwd, options = {
|
243
|
+
:use_symbols => true,
|
244
|
+
:extras => true,
|
245
|
+
:no_interaction => false
|
246
|
+
})
|
247
|
+
add_extras = (options[:extras].nil?) ? true : options[:extras]
|
248
|
+
name = File.basename( moduledir )
|
249
|
+
error "The module #{name} does not exist" unless File.directory?( moduledir )
|
250
|
+
jsonfile = File.join( moduledir, 'metadata.json')
|
251
|
+
error "Unable to find #{jsonfile}" unless File.exist?( jsonfile )
|
252
|
+
metadata = JSON.parse( IO.read( jsonfile ) )
|
253
|
+
metadata["docs_project"] = ask("\tRead the Docs (RTFD) project:", (metadata['name'].downcase.gsub(/\//, '-puppet-')).to_s) if metadata["docs_project"].nil?
|
254
|
+
if add_extras
|
255
|
+
metadata[:shortname] = name.gsub(/.*-/, '')
|
256
|
+
metadata[:platforms] = []
|
257
|
+
metadata["operatingsystem_support"].each do |e|
|
258
|
+
metadata[:platforms] << e["operatingsystem"].downcase unless e["operatingsystem"].nil?
|
259
|
+
end
|
260
|
+
# Analyse params
|
261
|
+
params_manifest = File.join(moduledir, 'manifests', 'params.pp')
|
262
|
+
if File.exist?(params_manifest)
|
263
|
+
params = []
|
264
|
+
File.read(params_manifest).scan(/^\s*\$(.*)\s*=/) do |_m|
|
265
|
+
params << Regexp.last_match(1).gsub(/\s+$/, '') unless Regexp.last_match(1).nil?
|
355
266
|
end
|
267
|
+
metadata[:params] = params.uniq
|
268
|
+
end
|
269
|
+
end
|
270
|
+
if options[:use_symbols]
|
271
|
+
# convert string keys to symbols
|
272
|
+
metadata.keys.each do |k|
|
273
|
+
metadata[(begin
|
274
|
+
k.to_sym
|
275
|
+
rescue
|
276
|
+
k
|
277
|
+
end) || k] = metadata.delete(k)
|
278
|
+
end
|
279
|
+
end
|
280
|
+
metadata
|
281
|
+
end # metadata
|
356
282
|
|
357
283
|
|
358
|
-
#######
|
359
|
-
# Find the classes of a given module
|
360
|
-
###
|
361
|
-
def classes(moduledir = Dir.pwd)
|
362
|
-
_get_classdefs(moduledir, 'classes')
|
363
|
-
end
|
364
284
|
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
285
|
+
##
|
286
|
+
# Upgrade the key files (README etc.) of the puppet module hosted
|
287
|
+
# in `moduledir` with the latest version of the FalkorLib template
|
288
|
+
# Supported options:
|
289
|
+
# :no_interaction [boolean]: do not interact
|
290
|
+
# :only [Array of string]: update only the listed files
|
291
|
+
# :exclude [Array of string]: exclude from the upgrade the listed
|
292
|
+
# files
|
293
|
+
# return the number of considered files
|
294
|
+
def upgrade(moduledir = Dir.pwd,
|
295
|
+
options = {
|
296
|
+
:no_interaction => false,
|
297
|
+
:only => nil,
|
298
|
+
:exclude => []
|
299
|
+
})
|
300
|
+
metadata = metadata(moduledir)
|
301
|
+
templatedir = File.join( FalkorLib.templates, 'puppet', 'modules')
|
302
|
+
i = 0
|
303
|
+
update_from_erb = [
|
304
|
+
'README.md',
|
305
|
+
'docs/contacts.md',
|
306
|
+
'docs/contributing/index.md', 'docs/contributing/layout.md', 'docs/contributing/setup.md', 'docs/contributing/versioning.md',
|
307
|
+
'docs/index.md', 'docs/rtfd.md', 'docs/vagrant.md'
|
308
|
+
]
|
309
|
+
(update_from_erb + [ 'Gemfile', 'Rakefile', 'Vagrantfile', '.vagrant_init.rb' ]).each do |f|
|
310
|
+
next unless options[:exclude].nil? || !options[:exclude].include?( f )
|
311
|
+
next unless options[:only].nil? || options[:only].include?(f)
|
312
|
+
info "Upgrade the content of #{f}"
|
313
|
+
ans = (options[:no_interaction]) ? 'Yes' : ask(cyan("==> procceed? (Y|n)"), 'Yes')
|
314
|
+
next if ans =~ /n.*/i
|
315
|
+
if update_from_erb.include?(f)
|
316
|
+
puts "=> updating #{f}.erb"
|
317
|
+
i += write_from_erb_template(File.join(templatedir, "#{f}.erb"),
|
318
|
+
File.join(moduledir, f),
|
319
|
+
metadata,
|
320
|
+
options)
|
321
|
+
else
|
322
|
+
i += write_from_template(f, moduledir,
|
323
|
+
:no_interaction => options[:no_interaction],
|
324
|
+
:srcdir => templatedir)
|
371
325
|
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
326
|
+
end
|
327
|
+
end
|
328
|
+
i
|
329
|
+
end
|
330
|
+
|
331
|
+
##
|
332
|
+
# initializes or update the (tests/specs/etc.) sub-directory of the
|
333
|
+
# `moduledir` using the correcponding ERB files.
|
334
|
+
# Supported options:
|
335
|
+
# :no_interaction [boolean]: do not interactww
|
336
|
+
#
|
337
|
+
# returns the number of considered files
|
338
|
+
def upgrade_from_template(moduledir = Dir.pwd,
|
339
|
+
subdir = 'tests',
|
340
|
+
options = {
|
341
|
+
:no_interaction => false
|
342
|
+
})
|
343
|
+
metadata = metadata(moduledir)
|
344
|
+
ap metadata
|
345
|
+
i = 0
|
346
|
+
templatedir = File.join( FalkorLib.templates, 'puppet', 'modules', subdir)
|
347
|
+
error "Unable to find the template directory '#{templatedir}" unless File.directory?( templatedir )
|
348
|
+
Dir["#{templatedir}/**/*.erb"].each do |erbfile|
|
349
|
+
f = File.join(subdir, File.basename(erbfile, '.erb'))
|
350
|
+
info "Upgrade the content of #{f}"
|
351
|
+
ans = (options[:no_interaction]) ? 'Yes' : ask(cyan("==> procceed? (Y|n)"), 'Yes')
|
352
|
+
next if ans =~ /n.*/i
|
353
|
+
i += write_from_erb_template(erbfile, File.join(moduledir, f), metadata, options)
|
354
|
+
end
|
355
|
+
i
|
356
|
+
end
|
378
357
|
|
379
|
-
result = Array.new
|
380
|
-
result2 = Array.new
|
381
|
-
resulttmp = Array.new
|
382
358
|
|
383
|
-
|
359
|
+
#######
|
360
|
+
# Find the classes of a given module
|
361
|
+
###
|
362
|
+
def classes(moduledir = Dir.pwd)
|
363
|
+
_get_classdefs(moduledir, 'classes')
|
364
|
+
end
|
384
365
|
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
entry = $3.split('::').first
|
392
|
-
result << entry unless entry.nil? or entry.empty?
|
393
|
-
end
|
394
|
-
end
|
395
|
-
end
|
396
|
-
result.uniq!
|
397
|
-
result2 = resulttmp.dup
|
398
|
-
end
|
399
|
-
result.delete "#{name}"
|
400
|
-
result
|
401
|
-
end
|
366
|
+
#######
|
367
|
+
# Find the definitions of a given module
|
368
|
+
###
|
369
|
+
def definitions(moduledir = Dir.pwd)
|
370
|
+
_get_classdefs(moduledir, 'definitions')
|
371
|
+
end
|
402
372
|
|
373
|
+
#######
|
374
|
+
# Find the dependencies of a given module
|
375
|
+
###
|
376
|
+
def deps(moduledir = Dir.pwd)
|
377
|
+
name = File.basename( moduledir )
|
378
|
+
error "The module #{name} does not exist" unless File.directory?( moduledir )
|
379
|
+
|
380
|
+
result = []
|
381
|
+
result2 = []
|
382
|
+
resulttmp = []
|
383
|
+
|
384
|
+
result << name
|
385
|
+
|
386
|
+
while result != result2
|
387
|
+
resulttmp = result.dup
|
388
|
+
(result - result2).each do |_x|
|
389
|
+
Dir["#{moduledir}/**/*.pp"].each do |ppfile|
|
390
|
+
File.read(ppfile).scan(/^\s*(include|require|class\s*{)\s*["']?(::)?([0-9a-zA-Z:{$}\-]*)["']?/) do |_m|
|
391
|
+
next if Regexp.last_match(3).nil?
|
392
|
+
entry = Regexp.last_match(3).split('::').first
|
393
|
+
result << entry unless entry.nil? || entry.empty?
|
394
|
+
end
|
395
|
+
end
|
396
|
+
end
|
397
|
+
result.uniq!
|
398
|
+
result2 = resulttmp.dup
|
403
399
|
end
|
404
|
-
|
400
|
+
result.delete name.to_s
|
401
|
+
result
|
402
|
+
end
|
403
|
+
|
404
|
+
end
|
405
|
+
end # module FalkorLib::Puppet
|
406
|
+
|
405
407
|
end # module FalkorLib
|