spiceweasel 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -75,6 +75,7 @@ else
75
75
  puts cli.opt_parser.to_s
76
76
  exit(-1)
77
77
  end
78
+ STDOUT.puts "DEBUG: file input: #{input}" if DEBUG
78
79
  end
79
80
 
80
81
  create = String.new()
@@ -40,7 +40,7 @@ class Spiceweasel::CookbookData
40
40
  else
41
41
  raise IOError, "Cannot open or read cookbooks/#{@_name}/metadata.rb!"
42
42
  end
43
- {:name => @_name, :version => @_version, :dependencies => @_dependencies }
43
+ {'name' => @_name, 'version' => @_version, 'dependencies' => @_dependencies }
44
44
  end
45
45
 
46
46
  def name(*args) # Override metadata.rb DSL
@@ -56,7 +56,7 @@ class Spiceweasel::CookbookData
56
56
  if args.length > 0
57
57
  cookbook_version = args.shift
58
58
  end
59
- @_dependencies << {:cookbook => cookbook, :version => cookbook_version}
59
+ @_dependencies << {'cookbook' => cookbook, 'version' => cookbook_version}
60
60
  end
61
61
 
62
62
  def method_missing(m, *args, &block)
@@ -24,20 +24,21 @@ class Spiceweasel::DirectoryExtractor
24
24
  # COOKBOOKS
25
25
  cookbooks = []
26
26
  Dir.glob("cookbooks/*").each do |cookbook_full_path|
27
- cookbook = self.grab_filename_from_path cookbook_full_path
27
+ cookbook = cookbook_full_path.split('/').last
28
28
  STDOUT.puts "DEBUG: dir_ext: cookbook: '#{cookbook}'" if DEBUG
29
29
  cookbook_data = Spiceweasel::CookbookData.new(cookbook)
30
30
  if cookbook_data.is_readable?
31
31
  cookbooks << cookbook_data.read
32
32
  end
33
33
  end
34
- cookbook_names = self.order_cookbooks_by_dependency cookbooks
35
- objects["cookbooks"] = cookbook_names unless cookbook_names.empty?
34
+ STDOUT.puts "DEBUG: dir_ext: cookbooks: '#{cookbooks}'" if DEBUG
35
+ cookbooks = self.order_cookbooks_by_dependency(cookbooks)
36
+ objects["cookbooks"] = cookbooks unless cookbooks.empty?
36
37
 
37
38
  # ROLES
38
39
  roles = []
39
40
  Dir.glob("roles/*.{rb,json}").each do |role_full_path|
40
- role = self.grab_name_from_path role_full_path
41
+ role = self.grab_name_from_path(role_full_path)
41
42
  STDOUT.puts "DEBUG: dir_ext: role: '#{role}'" if DEBUG
42
43
  roles << {role => nil}
43
44
  end
@@ -45,7 +46,7 @@ class Spiceweasel::DirectoryExtractor
45
46
  # ENVIRONMENTS
46
47
  environments = []
47
48
  Dir.glob("environments/*.{rb,json}").each do |environment_full_path|
48
- environment = self.grab_name_from_path environment_full_path
49
+ environment = self.grab_name_from_path(environment_full_path)
49
50
  STDOUT.puts "DEBUG: dir_ext: environment: '#{environment}'" if DEBUG
50
51
  environments << {environment => nil}
51
52
  end
@@ -67,7 +68,7 @@ class Spiceweasel::DirectoryExtractor
67
68
  # TODO: Cant use this yet as node_list.rb doesnt support node from file syntax but expects the node info to be part of the objects passed in
68
69
  # nodes = []
69
70
  # Dir.glob("nodes/*.{rb,json}").each do |node_full_path|
70
- # node = self.grab_name_from_path node_full_path
71
+ # node = self.grab_name_from_path(node_full_path)
71
72
  # nodes << {node => nil}
72
73
  # end
73
74
  # objects["nodes"] = nodes unless nodes.empty?
@@ -75,66 +76,42 @@ class Spiceweasel::DirectoryExtractor
75
76
  objects
76
77
  end
77
78
 
78
- def self.grab_filename_from_path path
79
- path.split('/').last
80
- end
81
-
82
- def self.grab_name_from_path path
83
- name = self.grab_filename_from_path(path).split('.')
79
+ def self.grab_name_from_path(path)
80
+ name = path.split('/').last.split('.')
84
81
  if name.length>1
85
82
  name.pop
86
83
  end
87
84
  name.join('.')
88
85
  end
89
- def self.order_cookbooks_by_dependency cookbooks
90
86
 
87
+ def self.order_cookbooks_by_dependency(cookbooks)
91
88
  # Weak algorithm, not particularly elegant, ignores version info as unlikely to have two versions of a cookbook anyway
92
- ordered_cookbooks = []
93
-
94
- left_to_sort = cookbooks
95
- num_sorted_cookbooks_this_iteration = -1
96
-
97
- while left_to_sort.size > 0 && num_sorted_cookbooks_this_iteration != 0
98
-
99
- unsorted_cookbooks = left_to_sort
100
- left_to_sort = []
101
- num_sorted_cookbooks_this_iteration
102
- unsorted_cookbooks.each do |cookbook|
103
- name = cookbook[:name]
104
- dependencies = cookbook[:dependencies]
105
-
106
- next if ordered_cookbooks.include? name
107
-
108
- if dependencies.nil?
109
- ordered_cookbooks << name
110
- num_sorted_cookbooks_this_iteration += 1
111
- next
112
- end
113
-
114
- dependencies_satisfied_yet = true
115
- dependencies.each {|dependency| dependencies_satisfied_yet = false unless ordered_cookbooks.include? dependency[:cookbook]}
116
- if dependencies_satisfied_yet
117
- ordered_cookbooks << name
118
- num_sorted_cookbooks_this_iteration += 1
119
- next
120
- end
121
-
122
- left_to_sort << cookbook
123
-
89
+ # We're going to find the cookbooks with their dependencies matched and keep going until all we have is unmatched deps
90
+
91
+ sorted_cookbooks = []
92
+ unsorted_cookbooks = cookbooks
93
+ scount = 0
94
+ #keep looping until no more cookbooks are left or can't remove remainders
95
+ while unsorted_cookbooks.any? and scount < cookbooks.length
96
+ cookbook = unsorted_cookbooks.shift
97
+ #if all the cookbook dependencies are in sorted_cookbooks
98
+ if sorted_cookbooks.eql?(sorted_cookbooks | cookbook['dependencies'].collect {|x| x['cookbook']})
99
+ sorted_cookbooks.push(cookbook['name'])
100
+ scount = 0
101
+ else #put it back in the list
102
+ unsorted_cookbooks.push(cookbook)
103
+ scount = scount + 1
124
104
  end
125
-
105
+ STDOUT.puts "DEBUG: dir_ext: sorted_cookbooks: '#{sorted_cookbooks}' #{scount}" if DEBUG
126
106
  end
127
-
128
- if left_to_sort.size > 0
129
- STDERR.puts "ERROR: Dependencies not satisfied or circular dependencies between cookbooks: #{left_to_sort}"
107
+ if scount > 0
108
+ remainders = unsorted_cookbooks.collect {|x| x['name']}
109
+ deps = unsorted_cookbooks.collect {|x| x['dependencies'].collect {|x| x['cookbook']}}
110
+ STDERR.puts "ERROR: Dependencies not satisfied or circular dependencies in cookbook(s): #{remainders} depend(s) on #{deps}"
130
111
  exit(-1)
112
+ else
113
+ #hack to get the format same as yaml/json parse
114
+ return sorted_cookbooks.collect {|x| {x => nil} }
131
115
  end
132
- output_cookbooks = []
133
- ordered_cookbooks.each do |cookbook|
134
- output_cookbooks << {cookbook => nil}
135
- end
136
- output_cookbooks
137
-
138
116
  end
139
-
140
117
  end
@@ -17,5 +17,5 @@
17
17
  #
18
18
 
19
19
  module Spiceweasel
20
- VERSION = "1.1.0"
20
+ VERSION = "1.1.1"
21
21
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spiceweasel
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-05-22 00:00:00.000000000Z
13
+ date: 2012-05-23 00:00:00.000000000Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: json
17
- requirement: &70140549239420 !ruby/object:Gem::Requirement
17
+ requirement: &70318502093180 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: '0'
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *70140549239420
25
+ version_requirements: *70318502093180
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: mixlib-cli
28
- requirement: &70140549239000 !ruby/object:Gem::Requirement
28
+ requirement: &70318502092760 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *70140549239000
36
+ version_requirements: *70318502092760
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: rspec
39
- requirement: &70140549238580 !ruby/object:Gem::Requirement
39
+ requirement: &70318502092340 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ! '>='
@@ -44,7 +44,7 @@ dependencies:
44
44
  version: '0'
45
45
  type: :development
46
46
  prerelease: false
47
- version_requirements: *70140549238580
47
+ version_requirements: *70318502092340
48
48
  description: Provides a CLI tool for generating knife commands to build Chef-managed
49
49
  infrastructure from a simple YAML or JSON file.
50
50
  email: