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.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +88 -0
  4. data/.travis.yml +56 -4
  5. data/Gemfile +4 -4
  6. data/Gemfile.lock +55 -27
  7. data/Rakefile +12 -8
  8. data/Vagrantfile +68 -0
  9. data/completion/_falkor +55 -7
  10. data/falkorlib.gemspec +14 -12
  11. data/lib/falkorlib.rb +22 -21
  12. data/lib/falkorlib/bootstrap.rb +5 -1
  13. data/lib/falkorlib/bootstrap/base.rb +385 -693
  14. data/lib/falkorlib/bootstrap/git.rb +137 -0
  15. data/lib/falkorlib/bootstrap/latex.rb +186 -0
  16. data/lib/falkorlib/bootstrap/link.rb +108 -96
  17. data/lib/falkorlib/bootstrap/ruby.rb +102 -0
  18. data/lib/falkorlib/cli.rb +82 -26
  19. data/lib/falkorlib/cli/config.rb +8 -8
  20. data/lib/falkorlib/cli/link.rb +8 -9
  21. data/lib/falkorlib/cli/new.rb +25 -39
  22. data/lib/falkorlib/common.rb +425 -425
  23. data/lib/falkorlib/config.rb +114 -110
  24. data/lib/falkorlib/error.rb +27 -16
  25. data/lib/falkorlib/gem_tasks.rb +12 -11
  26. data/lib/falkorlib/git.rb +3 -4
  27. data/lib/falkorlib/git/base.rb +439 -396
  28. data/lib/falkorlib/git/flow.rb +163 -165
  29. data/lib/falkorlib/git_tasks.rb +31 -31
  30. data/lib/falkorlib/loader.rb +1 -1
  31. data/lib/falkorlib/puppet.rb +3 -5
  32. data/lib/falkorlib/puppet/base.rb +10 -15
  33. data/lib/falkorlib/puppet/modules.rb +367 -365
  34. data/lib/falkorlib/puppet_tasks.rb +11 -8
  35. data/lib/falkorlib/tasks.rb +51 -54
  36. data/lib/falkorlib/tasks/gem.rake +42 -43
  37. data/lib/falkorlib/tasks/gem.rb +12 -11
  38. data/lib/falkorlib/tasks/git.rake +101 -107
  39. data/lib/falkorlib/tasks/git.rb +31 -31
  40. data/lib/falkorlib/tasks/gitflow.rake +131 -141
  41. data/lib/falkorlib/tasks/puppet.rb +11 -8
  42. data/lib/falkorlib/tasks/puppet_modules.rake +143 -154
  43. data/lib/falkorlib/tasks/rspec.rake +94 -59
  44. data/lib/falkorlib/tasks/yard.rake +35 -39
  45. data/lib/falkorlib/version.rb +55 -55
  46. data/lib/falkorlib/versioning.rb +169 -167
  47. data/spec/falkorlib/bootstrap_helpers_spec.rb +106 -56
  48. data/spec/falkorlib/bootstrap_latex_spec.rb +145 -0
  49. data/spec/falkorlib/bootstrap_link_spec.rb +137 -0
  50. data/spec/falkorlib/bootstrap_ruby_spec.rb +118 -0
  51. data/spec/falkorlib/bootstrap_spec.rb +112 -129
  52. data/spec/falkorlib/git_spec.rb +94 -22
  53. data/spec/falkorlib/gitflow_spec.rb +54 -42
  54. data/spec/falkorlib/puppet_modules_spec.rb +35 -26
  55. data/spec/falkorlib/versioning_puppet_module_spec.rb +94 -90
  56. data/spec/falkorlib_spec.rb +5 -0
  57. data/spec/spec_helper.rb +88 -47
  58. data/templates/latex/article-ieee/main.tex.erb +509 -0
  59. data/templates/latex/article/_abstract.tex.erb +19 -0
  60. data/templates/latex/article/_acronyms.tex.erb +116 -0
  61. data/templates/latex/article/_conclusion.tex.erb +25 -0
  62. data/templates/latex/article/_context.tex.erb +17 -0
  63. data/templates/latex/article/_experiments.tex.erb +27 -0
  64. data/templates/latex/article/_implem.tex.erb +17 -0
  65. data/templates/latex/article/_introduction.tex.erb +39 -0
  66. data/templates/latex/article/_related_works.tex.erb +19 -0
  67. data/templates/latex/article/biblio.bib.erb +28 -0
  68. data/templates/latex/article/template.tex.erb +16 -0
  69. data/templates/latex/ieee/IEEEtran.bst +2409 -0
  70. data/templates/latex/ieee/IEEEtran.cls +6347 -0
  71. data/templates/motd/motd.erb +2 -1
  72. metadata +82 -2
@@ -1,6 +1,6 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  ################################################################################
3
- # Time-stamp: <Lun 2015-01-19 17:56 svarrette>
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 #:nodoc:
15
- module Config
16
- module Puppet
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: <Tue 2015-06-16 10:12 svarrette>
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 #:nodoc:
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
- # Puppet actions
19
+ module Config
53
20
  module Puppet
54
- # Management of Puppet Modules operations
55
- module Modules
56
-
57
- module_function
21
+ module Modules
58
22
 
59
- def _get_classdefs(moduledir = Dir.pwd, type = 'classes')
60
- name = File.basename( moduledir )
61
- error "The module #{name} does not exist" unless File.directory?( moduledir )
62
- t = case type
63
- when /class*/i
64
- 'class'
65
- when /def*/
66
- 'define'
67
- else
68
- ''
69
- end
70
- error "Undefined type #{type}" if t.empty?
71
- result = []
72
- Dir["#{moduledir}/manifests/**/*.pp"].each do |ppfile|
73
- #puts "=> testing #{ppfile}"
74
- File.read(ppfile).scan(/^[ \t]*#{t}[\s]+([0-9a-zA-z:-]+).*$/).each do |line|
75
- result << line[0]
76
- end
77
- end
78
- result.uniq!
79
- result.sort
80
- end
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
- # Initialize a new Puppet Module named `name` in `rootdir`.
85
- # Supported options:
86
- # * :no_iteraction [boolean]
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
- # Supported platforms
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
- # Propose to commit the key files
167
- if FalkorLib::Git.init?(moduledir)
168
- if FalkorLib::GitFlow.init?(moduledir)
169
- info "=> preparing git-flow feature for the newly created module '#{config[:name]}'"
170
- FalkorLib::GitFlow.start('feature', "bootstrapping", moduledir)
171
- end
172
- [ 'metadata.json',
173
- 'docs/', 'mkdocs.yml', 'LICENSE', '.gitignore', '.pmtignore',
174
- '.ruby-version', '.ruby-gemset', 'Gemfile',
175
- '.vagrant_init.rb', 'Rakefile', 'Vagrantfile' ].each do |f|
176
- FalkorLib::Git.add(File.join(moduledir, f))
177
- end
178
- end
179
- end # init
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
- # Retrieves the metadata from the metadata.json file in `moduledir`.
241
- # Supported options:
242
- # :use_symbols [boolean]: convert all keys to symbols
243
- # :extras [boolean]: add extra keys
244
- #
245
- def metadata(moduledir = Dir.pwd, options = {
246
- :use_symbols => true,
247
- :extras => true,
248
- :no_interaction => false
249
- })
250
- add_extras = options[:extras].nil? ? true : options[:extras]
251
- name = File.basename( moduledir )
252
- error "The module #{name} does not exist" unless File.directory?( moduledir )
253
- jsonfile = File.join( moduledir, 'metadata.json')
254
- error "Unable to find #{jsonfile}" unless File.exist?( jsonfile )
255
- metadata = JSON.parse( IO.read( jsonfile ) )
256
- metadata["docs_project"] = ask("\tRead the Docs (RTFD) project:", "#{metadata['name'].downcase.gsub(/\//,'-puppet-')}") if metadata["docs_project"].nil?
257
- if add_extras
258
- metadata[:shortname] = name.gsub(/.*-/, '')
259
- metadata[:platforms] = []
260
- metadata["operatingsystem_support"].each do |e|
261
- metadata[:platforms] << e["operatingsystem"].downcase unless e["operatingsystem"].nil?
262
- end
263
- # Analyse params
264
- params_manifest = File.join(moduledir, 'manifests', 'params.pp')
265
- if File.exist?(params_manifest)
266
- params = []
267
- File.read(params_manifest).scan(/^\s*\$(.*)\s*=/) do |m|
268
- params << $1.gsub(/\s+$/,'') unless $1.nil?
269
- end
270
- metadata[:params] = params.uniq
271
- end
272
- end
273
- if options[:use_symbols]
274
- # convert string keys to symbols
275
- metadata.keys.each do |k|
276
- metadata[(k.to_sym rescue k) || k] = metadata.delete(k)
277
- end
278
- end
279
- metadata
280
- end # metadata
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
- # Upgrade the key files (README etc.) of the puppet module hosted
286
- # in `moduledir` with the latest version of the FalkorLib template
287
- # Supported options:
288
- # :no_interaction [boolean]: do not interact
289
- # :only [Array of string]: update only the listed files
290
- # :exclude [Array of string]: exclude from the upgrade the listed
291
- # files
292
- # return the number of considered files
293
- def upgrade(moduledir = Dir.pwd,
294
- options = {
295
- :no_interaction => false,
296
- :only => nil,
297
- :exclude => []
298
- })
299
- metadata = metadata(moduledir)
300
- templatedir = File.join( FalkorLib.templates, 'puppet', 'modules')
301
- i = 0
302
- update_from_erb = [
303
- 'README.md',
304
- 'docs/contacts.md',
305
- 'docs/contributing/index.md', 'docs/contributing/layout.md', 'docs/contributing/setup.md', 'docs/contributing/versioning.md',
306
- 'docs/index.md', 'docs/rtfd.md', 'docs/vagrant.md'
307
- ]
308
- (update_from_erb + [ 'Gemfile', 'Rakefile', 'Vagrantfile', '.vagrant_init.rb' ]).each do |f|
309
- next unless options[:exclude].nil? or ! options[:exclude].include?( f )
310
- next unless options[:only].nil? or options[:only].include?(f)
311
- info "Upgrade the content of #{f}"
312
- ans = options[:no_interaction] ? 'Yes' : ask(cyan("==> procceed? (Y|n)"), 'Yes')
313
- next if ans =~ /n.*/i
314
- if update_from_erb.include?(f)
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
- # initializes or update the (tests/specs/etc.) sub-directory of the
332
- # `moduledir` using the correcponding ERB files.
333
- # Supported options:
334
- # :no_interaction [boolean]: do not interactww
335
- #
336
- # returns the number of considered files
337
- def upgrade_from_template(moduledir = Dir.pwd,
338
- subdir = 'tests',
339
- options = {
340
- :no_interaction => false
341
- })
342
- metadata = metadata(moduledir)
343
- ap metadata
344
- i = 0
345
- templatedir = File.join( FalkorLib.templates, 'puppet', 'modules', subdir)
346
- error "Unable to find the template directory '#{templatedir}" unless File.directory?( templatedir )
347
- Dir["#{templatedir}/**/*.erb"].each do |erbfile|
348
- f = File.join(subdir, File.basename(erbfile, '.erb'))
349
- info "Upgrade the content of #{f}"
350
- ans = options[:no_interaction] ? 'Yes' : ask(cyan("==> procceed? (Y|n)"), 'Yes')
351
- next if ans =~ /n.*/i
352
- i+= write_from_erb_template(erbfile, File.join(moduledir, f), metadata, options)
353
- end
354
- i
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
- # Find the definitions of a given module
367
- ###
368
- def definitions(moduledir = Dir.pwd)
369
- _get_classdefs(moduledir, 'definitions')
370
- end
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
- # Find the dependencies of a given module
374
- ###
375
- def deps(moduledir = Dir.pwd)
376
- name = File.basename( moduledir )
377
- error "The module #{name} does not exist" unless File.directory?( moduledir )
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
- result << name
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
- while result != result2 do
386
- resulttmp = result.dup
387
- (result - result2).each do |x|
388
- Dir["#{moduledir}/**/*.pp"].each do |ppfile|
389
- File.read(ppfile).scan(/^\s*(include|require|class\s*{)\s*["']?(::)?([0-9a-zA-Z:{$}\-]*)["']?/) do |m|
390
- next if $3.nil?
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
- end # module FalkorLib::Puppet
400
+ result.delete name.to_s
401
+ result
402
+ end
403
+
404
+ end
405
+ end # module FalkorLib::Puppet
406
+
405
407
  end # module FalkorLib