knife-essentials 0.5.4 → 0.6

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.
@@ -1,4 +1,4 @@
1
- require 'support/file_system_support'
1
+ require 'support/spec_helper'
2
2
  require 'chef_fs/file_system'
3
3
  require 'chef_fs/file_pattern'
4
4
 
@@ -83,28 +83,6 @@ module FileSystemSupport
83
83
  end
84
84
  end
85
85
 
86
- def diffable_leaves_should_yield_paths(a_root, b_root, recurse_depth, expected_paths)
87
- result_paths = []
88
- ChefFS::Diff.diffable_leaves(a_root, b_root, recurse_depth) do |a,b|
89
- a.root.should == a_root
90
- b.root.should == b_root
91
- a.path.should == b.path
92
- result_paths << a.path
93
- end
94
- result_paths.should =~ expected_paths
95
- end
96
-
97
- def diffable_leaves_from_pattern_should_yield_paths(pattern, a_root, b_root, recurse_depth, expected_paths)
98
- result_paths = []
99
- ChefFS::Diff.diffable_leaves_from_pattern(pattern, a_root, b_root, recurse_depth) do |a,b|
100
- a.root.should == a_root
101
- b.root.should == b_root
102
- a.path.should == b.path
103
- result_paths << a.path
104
- end
105
- result_paths.should =~ expected_paths
106
- end
107
-
108
86
  def list_should_yield_paths(fs, pattern_str, *expected_paths)
109
87
  result_paths = []
110
88
  ChefFS::FileSystem.list(fs, pattern(pattern_str)) { |result| result_paths << result.path }
@@ -0,0 +1,8 @@
1
+ require 'support/file_system_support'
2
+
3
+ RSpec.configure do |config|
4
+ config.filter_run :focus => true
5
+ config.run_all_when_everything_filtered = true
6
+ config.treat_symbols_as_metadata_keys_with_true_values = true
7
+ end
8
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knife-essentials
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.4
4
+ version: '0.6'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-18 00:00:00.000000000Z
12
+ date: 2012-05-19 00:00:00.000000000Z
13
13
  dependencies: []
14
14
  description: Universal knife verbs that work with your Chef repository
15
15
  email: jkeiser@opscode.com
@@ -28,8 +28,8 @@ files:
28
28
  - lib/chef/knife/raw.rb
29
29
  - lib/chef/knife/show.rb
30
30
  - lib/chef/knife/upload.rb
31
+ - lib/chef/sandbox_uploader.rb
31
32
  - lib/chef_fs/command_line.rb
32
- - lib/chef_fs/diff.rb
33
33
  - lib/chef_fs/file_pattern.rb
34
34
  - lib/chef_fs/file_system/base_fs_dir.rb
35
35
  - lib/chef_fs/file_system/base_fs_object.rb
@@ -62,6 +62,7 @@ files:
62
62
  - spec/chef_fs/file_system/data_bags_dir_spec.rb
63
63
  - spec/chef_fs/file_system_spec.rb
64
64
  - spec/support/file_system_support.rb
65
+ - spec/support/spec_helper.rb
65
66
  homepage: http://www.opscode.com
66
67
  licenses: []
67
68
  post_install_message:
@@ -1,167 +0,0 @@
1
- require 'chef_fs/file_system'
2
- require 'chef/json_compat'
3
- require 'tempfile'
4
- require 'fileutils'
5
- require 'digest/md5'
6
- require 'set'
7
-
8
- module ChefFS
9
- class Diff
10
- def self.calc_checksum(value)
11
- return nil if value == nil
12
- Digest::MD5.hexdigest(value)
13
- end
14
-
15
- def self.diff_files_quick(old_file, new_file)
16
- #
17
- # Short-circuit expensive comparison (could be an extra network
18
- # request) if a pre-calculated checksum is there
19
- #
20
- if new_file.respond_to?(:checksum)
21
- new_checksum = new_file.checksum
22
- end
23
- if old_file.respond_to?(:checksum)
24
- old_checksum = old_file.checksum
25
- end
26
-
27
- old_value = :not_retrieved
28
- new_value = :not_retrieved
29
-
30
- if old_checksum || new_checksum
31
- if !old_checksum
32
- old_value = read_file_value(old_file)
33
- if old_value
34
- old_checksum = calc_checksum(old_value)
35
- end
36
- end
37
- if !new_checksum
38
- new_value = read_file_value(new_file)
39
- if new_value
40
- new_checksum = calc_checksum(new_value)
41
- end
42
- end
43
-
44
- # If the checksums are the same, they are the same. Return.
45
- return [ false, old_value, new_value ] if old_checksum == new_checksum
46
- end
47
-
48
- return [ nil, old_value, new_value ]
49
- end
50
-
51
- def self.diff_files(old_file, new_file)
52
- different, old_value, new_value = diff_files_quick(old_file, new_file)
53
- if different != nil
54
- return different
55
- end
56
-
57
- #
58
- # Grab the values if we don't have them already from calculating checksum
59
- #
60
- old_value = read_file_value(old_file) if old_value == :not_retrieved
61
- new_value = read_file_value(new_file) if new_value == :not_retrieved
62
-
63
- return false if old_value == new_value
64
- return false if old_value && new_value && context_aware_diff(old_file, new_file, old_value, new_value) == false
65
- return [ true, old_value, new_value ]
66
- end
67
-
68
- def self.context_aware_diff(old_file, new_file, old_value, new_value)
69
- if old_file.content_type == :json || new_file.content_type == :json
70
- begin
71
- new_value = Chef::JSONCompat.from_json(new_value).to_hash
72
- old_value = Chef::JSONCompat.from_json(old_value).to_hash
73
- return old_value != new_value
74
- rescue JSON::ParserError
75
- end
76
- end
77
- return nil
78
- end
79
-
80
- # Gets all common leaves, recursively, starting from the results of
81
- # a pattern search on two roots.
82
- #
83
- # ==== Attributes
84
- #
85
- # * +pattern+ - a ChefFS::FilePattern representing the search you want to
86
- # do on both roots.
87
- # * +a_root+ - the first root.
88
- # * +b_root+ -
89
- # * +recurse_depth+ - the maximum number of directories to recurse from each
90
- # pattern result. +0+ will cause pattern results to be immediately returned.
91
- # +nil+ means recurse infinitely to find all leaves.
92
- #
93
- def self.diffable_leaves_from_pattern(pattern, a_root, b_root, recurse_depth)
94
- # Make sure everything on the server is also on the filesystem, and diff
95
- found_paths = Set.new
96
- ChefFS::FileSystem.list(a_root, pattern) do |a|
97
- found_paths << a.path
98
- b = ChefFS::FileSystem.resolve_path(b_root, a.path)
99
- diffable_leaves(a, b, recurse_depth) do |a_leaf, b_leaf, leaf_recurse_depth|
100
- yield [ a_leaf, b_leaf, leaf_recurse_depth ]
101
- end
102
- end
103
-
104
- # Check the outer regex pattern to see if it matches anything on the
105
- # filesystem that isn't on the server
106
- ChefFS::FileSystem.list(b_root, pattern) do |b|
107
- if !found_paths.include?(b.path)
108
- a = ChefFS::FileSystem.resolve_path(a_root, b.path)
109
- yield [ a, b, recurse_depth ]
110
- end
111
- end
112
- end
113
-
114
- # Gets all common leaves, recursively, from a pair of directories or files. It
115
- # recursively descends into all children of +a+ and +b+, yielding equivalent
116
- # pairs (common children with the same name) when it finds:
117
- # * +a+ or +b+ is not a directory.
118
- # * Both +a+ and +b+ are empty.
119
- # * It reaches +recurse_depth+ depth in the tree.
120
- #
121
- # This method will *not* check whether files exist, nor will it actually diff
122
- # the contents of files.
123
- #
124
- # ==== Attributes
125
- #
126
- # +a+ - the first directory to recursively scan
127
- # +b+ - the second directory to recursively scan, in tandem with +a+
128
- # +recurse_depth - the maximum number of directories to go down. +0+ will
129
- # cause +a+ and +b+ to be immediately returned. +nil+ means recurse
130
- # infinitely.
131
- #
132
- def self.diffable_leaves(a, b, recurse_depth)
133
- # If both are directories, recurse into them and diff the children instead of returning ourselves.
134
- if recurse_depth != 0 && a.dir? && b.dir?
135
- a_children_names = Set.new
136
- a.children.each do |a_child|
137
- a_children_names << a_child.name
138
- diffable_leaves(a_child, b.child(a_child.name), recurse_depth ? recurse_depth - 1 : nil) do |a_leaf, b_leaf, leaf_recurse_depth|
139
- yield [ a_leaf, b_leaf, leaf_recurse_depth ]
140
- end
141
- end
142
-
143
- # Check b for children that aren't in a
144
- b.children.each do |b_child|
145
- if !a_children_names.include?(b_child.name)
146
- yield [ a.child(b_child.name), b_child, recurse_depth ]
147
- end
148
- end
149
- return
150
- end
151
-
152
- # Otherwise, this is a leaf we must diff.
153
- yield [a, b]
154
- end
155
-
156
- private
157
-
158
- def self.read_file_value(file)
159
- begin
160
- return file.read
161
- rescue ChefFS::FileSystem::NotFoundError
162
- return nil
163
- end
164
- end
165
- end
166
- end
167
-