falkorlib 0.3.1 → 0.3.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 39932a4c7312da0130e12bd7d2e3f0263e1314d7
4
- data.tar.gz: 0de959dd8614849eb537293e154c143a7a173c2a
3
+ metadata.gz: 395609cb7eea10171f370b653926e3f45d1ec4fb
4
+ data.tar.gz: 4c1be259201f3f86178f6538930d2c62cbc727bf
5
5
  SHA512:
6
- metadata.gz: 7e13d023f008ae000f8c3aad8c0c67deeed9e778a7a2c19b2ad1801c860a259acb407583e6161f9cf8ff9bbc5e46bbeb68ce2b20b29228c5ab587442781117bf
7
- data.tar.gz: 3d23d36238a9ad43d8e08ad611558c331b06496e9910e97cc856682657b5bfdb91da115f9fd84eaa7ed1bc7a4a1288472a7bb8187c188d685e80710996924301
6
+ metadata.gz: c373d7743ad2a45ec4a5f452d25ae24dc10476c12a879b3c8b8133287f1e4f22672c646aec4a40e77de138d588fcb102450b12d63c065ca434da55f14442e684
7
+ data.tar.gz: 43e3a90e07c2dac1298a096be8c1ea27fc450d2fcd0b130e64b642660ced449348c50b54a67d8ea8f52f820b813baf27a31f7f322daa4c713fe34ecf62c8e599
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- falkorlib (0.3.1)
4
+ falkorlib (0.3.2)
5
5
  awesome_print (~> 1.2)
6
6
  configatron (~> 3.2)
7
7
  git_remote_branch (~> 0)
@@ -1,6 +1,6 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  ################################################################################
3
- # Time-stamp: <Lun 2014-08-25 23:43 svarrette>
3
+ # Time-stamp: <Thu 2014-08-28 23:12 svarrette>
4
4
  ################################################################################
5
5
 
6
6
  require "falkorlib"
@@ -171,11 +171,12 @@ module FalkorLib #:nodoc:
171
171
  # :only_files [boolean]: list only files in the glob
172
172
  # :only_dirs [boolean]: list only directories in the glob
173
173
  # :pattern_include [array of strings]: pattern(s) to include for listing
174
- # :pattern_exclude [array of strings]: pattern(s) to exclude for listing
174
+ # :pattern_exclude [array of strings]: pattern(s) to exclude for listing
175
+ # :text [string]: text to put
175
176
  def list_items(glob_pattern, options = {})
176
177
  list = { 0 => 'Exit' }
177
178
  index = 1
178
- raw_list = { }
179
+ raw_list = { 0 => 'Exit' }
179
180
 
180
181
  Dir["#{glob_pattern}"].each do |elem|
181
182
  #puts "=> element '#{elem}' - dir = #{File.directory?(elem)}; file = #{File.file?(elem)}"
@@ -206,6 +207,8 @@ module FalkorLib #:nodoc:
206
207
  text = options[:text].nil? ? "select the index" : options[:text]
207
208
  default_idx = options[:default].nil? ? 0 : options[:default]
208
209
  raise SystemExit.new('Empty list') if index == 1
210
+ #ap list
211
+ #ap raw_list
209
212
  # puts list.to_yaml
210
213
  # answer = ask("=> #{text}", "#{default_idx}")
211
214
  # raise SystemExit.new('exiting selection') if answer == '0'
@@ -1,6 +1,6 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  ################################################################################
3
- # Time-stamp: <Lun 2014-08-25 22:29 svarrette>
3
+ # Time-stamp: <Fri 2014-08-29 14:06 svarrette>
4
4
  ################################################################################
5
5
  # FalkorLib Configuration
6
6
  #
@@ -45,6 +45,9 @@ module FalkorLib #:nodoc:
45
45
  :custom_cfg => '.falkorlib.yaml',
46
46
  :rvm => {
47
47
  :rubies => [ '1.9.3', '2.0.0', '2.1.0']
48
+ },
49
+ :templates => {
50
+ :puppet => {}
48
51
  }
49
52
  }
50
53
 
@@ -58,7 +61,10 @@ module FalkorLib #:nodoc:
58
61
  res[:git] = FalkorLib::Config::Git::DEFAULTS if path.include?('lib/falkorlib/git.rb')
59
62
  res[:gitflow] = FalkorLib::Config::GitFlow::DEFAULTS if path.include?('lib/falkorlib/git.rb')
60
63
  res[:versioning] = FalkorLib::Config::Versioning::DEFAULTS if path.include?('lib/falkorlib/versioning.rb')
61
- res[:puppet] = FalkorLib::Config::Puppet::DEFAULTS if path.include?('lib/falkorlib/puppet.rb')
64
+ if path.include?('lib/falkorlib/puppet.rb')
65
+ res[:puppet] = FalkorLib::Config::Puppet::DEFAULTS
66
+ res[:templates][:puppet][:modules] = FalkorLib::Config::Puppet::Modules::DEFAULTS[:metadata]
67
+ end
62
68
  end
63
69
  # Check the potential local customizations
64
70
  custom_cfg = File.join( res[:root], res[:custom_cfg])
@@ -1,6 +1,6 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  ################################################################################
3
- # Time-stamp: <Mar 2014-08-26 14:17 svarrette>
3
+ # Time-stamp: <Thu 2014-08-28 23:02 svarrette>
4
4
  ################################################################################
5
5
  # Interface for the main Puppet Module operations
6
6
  #
@@ -9,6 +9,7 @@ require "falkorlib"
9
9
  require "falkorlib/common"
10
10
 
11
11
  require "pathname"
12
+ require 'json'
12
13
 
13
14
  include FalkorLib::Common
14
15
 
@@ -51,18 +52,46 @@ module FalkorLib #:nodoc:
51
52
  module Puppet
52
53
  # Management of Puppet Modules operations
53
54
  module Modules
54
- module_function
55
55
 
56
- ## Initialize a new Puppet Module named `name` in `rootdir`.
57
- # Supported options:
56
+ module_function
57
+
58
+ def _get_classdefs(moduledir = Dir.pwd, type = 'classes')
59
+ name = File.basename( moduledir )
60
+ error "The module #{name} does not exist" unless File.directory?( moduledir )
61
+ t = case type
62
+ when /class*/i
63
+ 'class'
64
+ when /def*/
65
+ 'define'
66
+ else
67
+ ''
68
+ end
69
+ error "Undefined type #{type}" if t.empty?
70
+ result = []
71
+ Dir["#{moduledir}/manifests/**/*.pp"].each do |ppfile|
72
+ File.read(ppfile).scan(/^[ \t]*#{t}[\s]+([0-9a-zA-z:]+).*$/).each do |line|
73
+ result << line[0]
74
+ end
75
+ end
76
+ result.uniq!
77
+ result
78
+ end
79
+
80
+
81
+
82
+ ####
83
+ # Initialize a new Puppet Module named `name` in `rootdir`.
84
+ # Supported options:
58
85
  # * :no_iteraction [boolean]
86
+ ##
59
87
  def init(rootdir = Dir.pwd, name = '', options = {})
60
88
  config = {}
61
- login = `whoami`.chomp
62
- config[:name] = name unless name.empty?
63
- FalkorLib::Config::Puppet::Modules::DEFAULTS[:metadata].each do |k,v|
89
+ login = `whoami`.chomp
90
+ config[:name] = name unless name.empty?
91
+ moduledir = name.empty? ? rootdir : File.join(rootdir, name)
92
+ FalkorLib::Config::Puppet::Modules::DEFAULTS[:metadata].each do |k,v|
64
93
  next if v.kind_of?(Array) or k == :license
65
- next if k == :name and ! name.empty?
94
+ next if k == :name and ! name.empty?
66
95
  default_answer = case k
67
96
  when :project_page
68
97
  config[:source].nil? ? v : config[:source]
@@ -71,60 +100,150 @@ module FalkorLib #:nodoc:
71
100
  when :issue_url
72
101
  config[:project_page].nil? ? v : "#{config[:project_page]}/issues"
73
102
  when :description
74
- config[:summary].nil? ? v : "#{config[:summary]}"
103
+ config[:summary].nil? ? v : "#{config[:summary]}"
75
104
  when :source
76
- v.empty? ? "https://github.com/#{`whoami`.chomp}/#{config[:name]}" : v
105
+ v.empty? ? "https://github.com/#{`whoami`.chomp}/#{config[:name]}" : v
77
106
  else
78
107
  v
79
108
  end
80
109
  config[k.to_sym] = ask( "\t" + sprintf("%-20s", "Module #{k}"), default_answer)
81
110
  end
82
- name = config[:name].gsub(/.*-/, '')
83
- tags = ask("\tKeywords (comma-separated list of tags)", name)
84
- config[:tags] = tags.split(',')
85
- license = select_from(FalkorLib::Config::Puppet::Modules::DEFAULTS[:licenses],
86
- 'Select the license index for the Puppet module:',
87
- 1)
88
- config[:license] = license.downcase unless license.empty?
89
- puts "\t" + sprintf("%-20s", "Module License:") + config[:license]
90
-
91
- #ap config
92
- # Bootstrap the directory
93
- templatedir = File.join( FalkorLib.templates, 'puppet', 'modules')
94
- init_from_template(templatedir, rootdir, config, {
95
- :erb_exclude => [ 'templates\/[^\/]*\.erb$' ]
96
- })
97
- # Rename the files / element templatename
98
- Dir["#{rootdir}/**/*"].each do |e|
99
- next unless e =~ /templatename/
100
- info "renaming #{e}"
101
- newname = e.gsub(/templatename/, "#{name}")
102
- run %{ mv #{e} #{newname} }
103
- end
111
+ name = config[:name].gsub(/.*-/, '')
112
+ tags = ask("\tKeywords (comma-separated list of tags)", name)
113
+ config[:tags] = tags.split(',')
114
+ license = select_from(FalkorLib::Config::Puppet::Modules::DEFAULTS[:licenses],
115
+ 'Select the license index for the Puppet module:',
116
+ 1)
117
+ config[:license] = license.downcase unless license.empty?
118
+ puts "\t" + sprintf("%-20s", "Module License:") + config[:license]
104
119
 
105
- info "Generating the License file"
106
- Dir.chdir(rootdir) do
107
- run %{licgen #{config[:license]} #{config[:author]}}
108
- end
109
- info "Initialize RVM"
110
- init_rvm(rootdir)
111
- unless FalkorLib::GitFlow.init?(rootdir)
112
- warn "Git [Flow] is not initialized in #{rootdir}."
113
- a = ask("Proceed to git-flow initialization (Y|n)", 'Yes')
114
- FalkorLib::GitFlow.init(rootdir) unless a =~ /n.*/i
115
- end
116
-
117
- # Propose to commit the key files
118
- if FalkorLib::Git.init?(rootdir)
119
- if FalkorLib::GitFlow.init?(rootdir)
120
- info "=> preparing git-flow feature for the newly created module '#{config[:name]}'"
121
- FalkorLib::GitFlow.start('feature', "init_#{name}", rootdir)
120
+ #ap config
121
+ # Bootstrap the directory
122
+ templatedir = File.join( FalkorLib.templates, 'puppet', 'modules')
123
+ init_from_template(templatedir, moduledir, config, {
124
+ :erb_exclude => [ 'templates\/[^\/]*\.erb$' ]
125
+ })
126
+ # Rename the files / element templatename
127
+ Dir["#{moduledir}/**/*"].each do |e|
128
+ next unless e =~ /templatename/
129
+ info "renaming #{e}"
130
+ newname = e.gsub(/templatename/, "#{name}")
131
+ run %{ mv #{e} #{newname} }
132
+ end
133
+
134
+ info "Generating the License file"
135
+ authors = config[:author].empty? ? 'UNKNOWN' : config[:author]
136
+ Dir.chdir(moduledir) do
137
+ run %{ licgen #{config[:license]} #{authors} }
138
+ end
139
+ info "Initialize RVM"
140
+ init_rvm(moduledir)
141
+ unless FalkorLib::GitFlow.init?(moduledir)
142
+ warn "Git [Flow] is not initialized in #{moduledir}."
143
+ a = ask("Proceed to git-flow initialization (Y|n)", 'Yes')
144
+ FalkorLib::GitFlow.init(moduledir) unless a =~ /n.*/i
145
+ end
146
+
147
+ # Propose to commit the key files
148
+ if FalkorLib::Git.init?(moduledir)
149
+ if FalkorLib::GitFlow.init?(moduledir)
150
+ info "=> preparing git-flow feature for the newly created module '#{config[:name]}'"
151
+ FalkorLib::GitFlow.start('feature', "init_#{name}", moduledir)
152
+ end
153
+ [ 'metadata.json', 'LICENSE', '.gitignore', 'Gemfile', 'Rakefile'].each do |f|
154
+ FalkorLib::Git.add(File.join(moduledir, f))
155
+ end
156
+ end
157
+ end # init
158
+
159
+ ####
160
+ # Parse a given modules to collect information
161
+ ##
162
+ def parse(moduledir = Dir.pwd)
163
+ name = File.basename( moduledir )
164
+ error "The module #{name} does not exist" unless File.directory?( moduledir )
165
+ jsonfile = File.join( moduledir, 'metadata.json')
166
+ error "Unable to find #{jsonfile}" unless File.exist?( jsonfile )
167
+ metadata = JSON.parse( IO.read( jsonfile ) )
168
+ metadata["classes"] = classes(moduledir)
169
+ metadata["definitions"] = definitions(moduledir)
170
+ deps = deps(moduledir)
171
+ listed_deps = metadata["dependencies"]
172
+ missed_deps = []
173
+ metadata["dependencies"].each do |dep|
174
+ lib = dep["name"].gsub(/^[^\/-]+[\/-]/,'')
175
+ if deps.include?( lib )
176
+ deps.delete( lib )
177
+ else
178
+ unless lib =~ /stdlib/
179
+ warn "The library '#{dep["name"]}' is not analyzed as part of the #{name} module"
180
+ missed_deps << dep
181
+ end
122
182
  end
123
- [ 'metadata.json', 'LICENSE', '.gitignore', 'Gemfile', 'Rakefile'].each do |f|
124
- FalkorLib::Git.add(File.join(rootdir, f))
183
+ end
184
+ if ! deps.empty?
185
+ deps.each do |l|
186
+ warn "The module '#{l}' is missing in the dependencies thus added"
187
+ login = ask("[Github] login for the module '#{lib}'")
188
+ version = ask("Version requirement (ex: '>=1.0.0 <2.0.0' or '1.2.3' or '1.x')")
189
+ metadata["dependencies"] << {
190
+ "name" => "#{login}/#{lib}",
191
+ "version_requirement" => "#{version}"
192
+ }
125
193
  end
126
- end
127
- end # init
194
+ warn "About to commit these changes in the '#{name}/metadata.json' file"
195
+ really_continue?
196
+ File.open(jsonfile,"w") do |f|
197
+ f.write JSON.pretty_generate( metadata )
198
+ end
199
+ end
200
+ end # parse
201
+
202
+
203
+ #######
204
+ # Find the classes of a given module
205
+ ###
206
+ def classes(moduledir = Dir.pwd)
207
+ _get_classdefs(moduledir, 'classes')
208
+ end
209
+
210
+ #######
211
+ # Find the definitions of a given module
212
+ ###
213
+ def definitions(moduledir = Dir.pwd)
214
+ _get_classdefs(moduledir, 'definitions')
215
+ end
216
+
217
+ #######
218
+ # Find the dependencies of a given module
219
+ ###
220
+ def deps(moduledir = Dir.pwd)
221
+ name = File.basename( moduledir )
222
+ error "The module #{name} does not exist" unless File.directory?( moduledir )
223
+
224
+ result = Array.new
225
+ result2 = Array.new
226
+ resulttmp = Array.new
227
+
228
+ result << name
229
+
230
+ while result != result2 do
231
+ resulttmp = result.dup
232
+ (result - result2).each do |x|
233
+ Dir["#{moduledir}/**/*.pp"].each do |ppfile|
234
+ File.read(ppfile).scan(/^[ \t]*include.*$|^[ \t]*require.*$/).each do |line|
235
+ if line.scan(">").length == 0
236
+ result << line.gsub(/^[ \t]*(include|require) ([\"']|)([0-9a-zA-Z:{$}\-]*)([\"']|)/, '\3').split("::").first
237
+ end
238
+ end
239
+ end
240
+ end
241
+ result.uniq!
242
+ result2 = resulttmp.dup
243
+ end
244
+ result.delete "#{name}"
245
+ result
246
+ end
128
247
 
129
248
 
130
249
  end # module FalkorLib::Puppet::Modules
@@ -1,7 +1,7 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  ################################################################################
3
3
  # puppet_modules.rake - Special tasks for the management of Puppet modules
4
- # Time-stamp: <Lun 2014-08-25 22:54 svarrette>
4
+ # Time-stamp: <Thu 2014-08-28 23:04 svarrette>
5
5
  #
6
6
  # Copyright (c) 2014 Sebastien Varrette <Sebastien.Varrette@uni.lu>
7
7
  # http://varrette.gforge.uni.lu
@@ -26,10 +26,18 @@ namespace :bootstrap do
26
26
  moduledir = File.join( FalkorLib.config[:puppet][:modulesdir], name)
27
27
  dir = ask("Destination directory:", moduledir)
28
28
  error "The module '#{name}' already exists" if File.directory?(dir)
29
- FalkorLib::Puppet::Modules.init(dir, name)
29
+ FalkorLib::Puppet::Modules.init(dir)
30
30
  end
31
31
 
32
32
 
33
33
  end # namespace bootstrap:puppet
34
34
  end # namespace bootstrap
35
35
 
36
+
37
+
38
+ #.....................
39
+ namespace :puppet do
40
+ include FalkorLib::Common
41
+
42
+
43
+ end # namespace puppet
@@ -19,7 +19,7 @@ module FalkorLib #:nodoc:
19
19
  # MAJOR: Defines the major version
20
20
  # MINOR: Defines the minor version
21
21
  # PATCH: Defines the patch version
22
- MAJOR, MINOR, PATCH = 0, 3, 1
22
+ MAJOR, MINOR, PATCH = 0, 3, 2
23
23
 
24
24
  module_function
25
25
 
@@ -2,7 +2,7 @@
2
2
  #########################################
3
3
  # puppet_modules_spec.rb
4
4
  # @author Sebastien Varrette <Sebastien.Varrette@uni.lu>
5
- # Time-stamp: <Mar 2014-08-26 15:04 svarrette>
5
+ # Time-stamp: <Fri 2014-08-29 11:32 svarrette>
6
6
  #
7
7
  # @description Check the Puppet Modules operations
8
8
  #
@@ -19,6 +19,10 @@ describe FalkorLib::Puppet::Modules do
19
19
 
20
20
  dir = Dir.mktmpdir
21
21
  #afile = File.join(dir, 'a_file')
22
+ # before :all do
23
+ # ENV['GIT_AUTHOR_NAME'] = 'travis' if ENV['GIT_AUTHOR_NAME'].nil?
24
+ # ENV['GIT_AUTHOR_EMAIL'] = 'travis@domain.org' if ENV['GIT_AUTHOR_EMAIL'].nil?
25
+ # end
22
26
 
23
27
  after :all do
24
28
  FileUtils.remove_entry_secure dir
@@ -27,10 +31,14 @@ describe FalkorLib::Puppet::Modules do
27
31
  #############################################################
28
32
  context "Test Puppet Module creation within temporary directory " do
29
33
 
34
+ # Module name
35
+ name = 'toto'
36
+ moduledir = File.join(dir, name)
37
+
30
38
  it "#init -- create a puppet module" do
31
- Array.new(18).each { |e| STDIN.should_receive(:gets).and_return('') }
32
- name = 'toto'
33
- FalkorLib::Puppet::Modules.init(dir, name)
39
+ Array.new(26).each { |e| STDIN.should_receive(:gets).and_return('') }
40
+ STDIN.should_receive(:gets).and_return('No')
41
+ FalkorLib::Puppet::Modules.init(moduledir)
34
42
  templatedir = File.join( FalkorLib.templates, 'puppet', 'modules')
35
43
  s = true
36
44
  Dir["#{templatedir}/**/*"].each do |e|
@@ -39,13 +47,41 @@ describe FalkorLib::Puppet::Modules do
39
47
  file = e.gsub(/templatename/, "#{name}")
40
48
  filename = File.basename(file)
41
49
  filename = File.basename(file, '.erb') unless file =~ /templates\/toto-variables\.erb/
42
- f = File.join(dir, relative_dir, filename)
50
+ f = File.join(moduledir, relative_dir, filename)
43
51
  #puts "checking #{f} - #{File.exists?( f )}"
44
52
  s &= File.exists?( f )
45
53
  end
46
54
  s.should be_true
47
55
  end
48
56
 
57
+ it "#classes -- list classes" do
58
+ l = FalkorLib::Puppet::Modules._get_classdefs(moduledir, 'classes')
59
+ c = FalkorLib::Puppet::Modules.classes(moduledir)
60
+ c.should == l
61
+ ref = [
62
+ "toto::params",
63
+ "toto",
64
+ "toto::common",
65
+ "toto::debian",
66
+ "toto::redhat"
67
+ ]
68
+ c.size.should == ref.size
69
+ c.each { |e| ref.should include(e) }
70
+ end
71
+
72
+ it "#definitions -- list definitions" do
73
+ d = FalkorLib::Puppet::Modules.definitions(moduledir)
74
+ d.should == [ "toto::mydef" ]
75
+ end
76
+
77
+ it "#deps -- list dependencies" do
78
+ d = FalkorLib::Puppet::Modules.deps(moduledir)
79
+ d.should == []
80
+ end
81
+
82
+
83
+
84
+
49
85
 
50
86
  end
51
87
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: falkorlib
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sebastien Varrette
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-27 00:00:00.000000000 Z
11
+ date: 2014-08-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake