between_meals 0.0.10 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 14a2f47358db13a1a9c1fbf6c038fc6c13f9c45a972a42b72abc6c592e41aa86
4
- data.tar.gz: 2be633f930866b32923a3e22a2eb2ccc30aa3e29d748d3ab71b3af49cc650410
3
+ metadata.gz: e58d518baa0534eecc6de15ac0fb0f7f09a6069f6fb870a60c55adf2cf2f8404
4
+ data.tar.gz: 44aaa21c488bea122a228466f0c30f5d0c9eab3ff778b3f60242cccaf2020ee6
5
5
  SHA512:
6
- metadata.gz: 1886e90d8bfaf9488f1dc919e8031aa334b98df14de5a51f7d1a86cad5dd11769cb2460427da2a9cca806537012ff765a43f31394da99e83218c2b2884fa885b
7
- data.tar.gz: aa03b1ec64dea20775f6d9554caef8d295b826db5279e1bda6ecb944e9cf32a3e586370ddccc4c06550e94ad60ebd528c710c08c1869a6ce360cd3bcbbaf6527
6
+ metadata.gz: 7a44420814d8e34888bea5be482a7d8b43d30979c0c8369cb11e0b13ff4cddc36e0a3da29a955d70917ba9b878fa75213640b718658c0f4b6fabbd199e002f8a
7
+ data.tar.gz: 12dece7d9a249c883bef1eb0c6460977998fbc7b7e6ba90ecaf5bb7912d374df72b919bd78b1aece7548e1063664e04b6d80007ad5c68baaf2a587060cc6a0aa
@@ -39,6 +39,14 @@ module BetweenMeals
39
39
  @config = opts[:config] ||
40
40
  "#{@home}/.chef/knife-#{@user}-taste-tester.rb"
41
41
  @knife = opts[:bin] || 'knife'
42
+ @knife_verb_option = ''
43
+ unless @logger.nil?
44
+ if @logger.level == Logger::DEBUG
45
+ @knife_verb_option = '-VV'
46
+ elsif @logger.level == Logger::INFO
47
+ @knife_verb_option = '-V'
48
+ end
49
+ end
42
50
  @berks = opts[:berks_bin] || 'berks'
43
51
  @berks_config = opts[:berks_config]
44
52
  @pem = opts[:pem] ||
@@ -55,7 +63,8 @@ module BetweenMeals
55
63
  def role_upload_all
56
64
  if File.exists?(@role_dir)
57
65
  roles = File.join(@role_dir, "*.#{@role_type}")
58
- exec!("#{@knife} role from file #{roles} -c #{@config}", @logger)
66
+ exec!("#{@knife} role from file #{roles} #{@knife_verb_option} " +
67
+ "-c #{@config}", @logger)
59
68
  end
60
69
  end
61
70
 
@@ -64,22 +73,23 @@ module BetweenMeals
64
73
  roles = roles.map do |x|
65
74
  File.join(@role_dir, "#{x.name}.#{@role_type}")
66
75
  end.join(' ')
67
- exec!("#{@knife} role from file #{roles} -c #{@config}", @logger)
76
+ exec!("#{@knife} role from file #{roles} #{@knife_verb_option} " +
77
+ "-c #{@config}", @logger)
68
78
  end
69
79
  end
70
80
 
71
81
  def role_delete(roles)
72
82
  if roles.any?
73
83
  roles.each do |role|
74
- exec!(
75
- "#{@knife} role delete #{role.name} --yes -c #{@config}", @logger
76
- )
84
+ exec!("#{@knife} role delete #{role.name} #{@knife_verb_option} " +
85
+ "--yes -c #{@config}", @logger)
77
86
  end
78
87
  end
79
88
  end
80
89
 
81
90
  def cookbook_upload_all
82
- exec!("#{@knife} cookbook upload -a -c #{@config}", @logger)
91
+ exec!("#{@knife} cookbook upload -a #{@knife_verb_option} " +
92
+ "-c #{@config}", @logger)
83
93
  end
84
94
 
85
95
  def berks_cookbook_upload_all
@@ -99,7 +109,8 @@ module BetweenMeals
99
109
  def cookbook_upload(cookbooks)
100
110
  if cookbooks.any?
101
111
  cookbooks = cookbooks.map(&:name).join(' ')
102
- exec!("#{@knife} cookbook upload #{cookbooks} -c #{@config}", @logger)
112
+ exec!("#{@knife} cookbook upload #{cookbooks} #{@knife_verb_option} " +
113
+ "-c #{@config}", @logger)
103
114
  end
104
115
  end
105
116
 
@@ -126,7 +137,8 @@ module BetweenMeals
126
137
  if cookbooks.any?
127
138
  cookbooks.each do |cookbook|
128
139
  exec!("#{@knife} cookbook delete #{cookbook.name}" +
129
- " --purge -a --yes -c #{@config}", @logger)
140
+ " --purge -a --yes #{@knife_verb_option} -c #{@config}",
141
+ @logger)
130
142
  end
131
143
  end
132
144
  end
@@ -149,7 +161,8 @@ module BetweenMeals
149
161
  File.join(@databag_dir, dbname, "#{x.item}.json")
150
162
  end.join(' ')
151
163
  exec!(
152
- "#{@knife} data bag from file #{dbname} #{dbitems} -c #{@config}",
164
+ "#{@knife} data bag from file #{dbname} #{dbitems} " +
165
+ "#{@knife_verb_option} -c #{@config}",
153
166
  @logger,
154
167
  )
155
168
  end
@@ -161,7 +174,7 @@ module BetweenMeals
161
174
  databags.group_by(&:name).each do |dbname, dbs|
162
175
  dbs.each do |db|
163
176
  exec!("#{@knife} data bag delete #{dbname} #{db.item}" +
164
- " --yes -c #{@config}", @logger)
177
+ " --yes #{@knife_verb_option} -c #{@config}", @logger)
165
178
  end
166
179
  delete_databag_if_empty(dbname)
167
180
  end
@@ -186,8 +199,11 @@ BLOCK
186
199
  cfg << " \"#{dir}\",\n"
187
200
  end
188
201
  cfg << "]\n"
189
- unless File.directory?(File.dirname(@config))
202
+ begin
190
203
  Dir.mkdir(File.dirname(@config), 0o755)
204
+ rescue Errno::EEXIST
205
+ # not an error if it's already there.
206
+ nil
191
207
  end
192
208
  if !File.exists?(@config) ||
193
209
  ::Digest::MD5.hexdigest(cfg) !=
@@ -228,8 +244,11 @@ IAMAEpsWX2s2A6phgMCx7kH6wMmoZn3hb7Thh9+PfR8Jtp2/7k+ibCeF4gEWUCs5
228
244
  -----END PRIVATE KEY-----
229
245
  BLOCK
230
246
 
231
- unless File.directory?(File.dirname(@pem))
247
+ begin
232
248
  Dir.mkdir(File.dirname(@pem), 0o755)
249
+ rescue Errno::EEXIST
250
+ # not an error if it's already there.
251
+ nil
233
252
  end
234
253
 
235
254
  unless File.exists?(@pem)
@@ -242,22 +261,25 @@ IAMAEpsWX2s2A6phgMCx7kH6wMmoZn3hb7Thh9+PfR8Jtp2/7k+ibCeF4gEWUCs5
242
261
 
243
262
  def create_databag_if_missing(databag)
244
263
  s = Mixlib::ShellOut.new("#{@knife} data bag list" +
245
- " --format json -c #{@config}").run_command
264
+ " --format json #{@knife_verb_option} " +
265
+ "-c #{@config}").run_command
246
266
  s.error!
247
267
  db = JSON.parse(s.stdout)
248
268
  unless db.include?(databag)
249
- exec!("#{@knife} data bag create #{databag} -c #{@config}", @logger)
269
+ exec!("#{@knife} data bag create #{databag} #{@knife_verb_option} " +
270
+ "-c #{@config}", @logger)
250
271
  end
251
272
  end
252
273
 
253
274
  def delete_databag_if_empty(databag)
254
275
  s = Mixlib::ShellOut.new("#{@knife} data bag show #{databag}" +
255
- " --format json -c #{@config}").run_command
276
+ " --format json #{@knife_verb_option} " +
277
+ "-c #{@config}").run_command
256
278
  s.error!
257
279
  db = JSON.parse(s.stdout)
258
280
  if db.empty?
259
- exec!("#{@knife} data bag delete #{databag} --yes -c #{@config}",
260
- @logger)
281
+ exec!("#{@knife} data bag delete #{databag} --yes " +
282
+ "#{@knife_verb_option} -c #{@config}", @logger)
261
283
  end
262
284
  end
263
285
  end
@@ -154,53 +154,54 @@ module BetweenMeals
154
154
 
155
155
  # rubocop:disable MultilineBlockChain
156
156
  changes.lines.map do |line|
157
- case line
158
- when /^A\s+(\S+)$/
157
+ parts = line.chomp.split("\t")
158
+ case parts[0]
159
+ when 'A'
159
160
  # A path
160
161
  {
161
162
  :status => :modified,
162
- :path => Regexp.last_match(1),
163
+ :path => parts[1],
163
164
  }
164
- when /^C(?:\d*)\s+(\S+)\s+(\S+)/
165
+ when /^C(?:\d*)/
165
166
  # C<numbers> path1 path2
166
167
  {
167
168
  :status => :modified,
168
- :path => Regexp.last_match(2),
169
+ :path => parts[2],
169
170
  }
170
- when /^D\s+(\S+)$/
171
+ when 'D'
171
172
  # D path
172
173
  {
173
174
  :status => :deleted,
174
- :path => Regexp.last_match(1),
175
+ :path => parts[1],
175
176
  }
176
- when /^M(?:\d*)\s+(\S+)$/
177
+ when /^M(?:\d*)/
177
178
  # M<numbers> path
178
179
  {
179
180
  :status => :modified,
180
- :path => Regexp.last_match(1),
181
+ :path => parts[1],
181
182
  }
182
- when /^R(?:\d*)\s+(\S+)\s+(\S+)/
183
+ when /^R(?:\d*)/
183
184
  # R<numbers> path1 path2
184
185
  [
185
186
  {
186
187
  :status => :deleted,
187
- :path => Regexp.last_match(1),
188
+ :path => parts[1],
188
189
  },
189
190
  {
190
191
  :status => :modified,
191
- :path => Regexp.last_match(2),
192
+ :path => parts[2],
192
193
  },
193
194
  ]
194
- when /^T\s+(\S+)$/
195
+ when 'T'
195
196
  # T path
196
197
  [
197
198
  {
198
199
  :status => :deleted,
199
- :path => Regexp.last_match(1),
200
+ :path => parts[1],
200
201
  },
201
202
  {
202
203
  :status => :modified,
203
- :path => Regexp.last_match(1),
204
+ :path => parts[1],
204
205
  },
205
206
  ]
206
207
  else
@@ -166,41 +166,42 @@ module BetweenMeals
166
166
  # = origin of the previous file (with --copies)
167
167
 
168
168
  changes.lines.map do |line|
169
- case line
170
- when /^A (\S+)$/
169
+ parts = line.chomp.split(nil, 2)
170
+ case parts[0]
171
+ when 'A'
171
172
  {
172
173
  :status => :added,
173
- :path => Regexp.last_match(1),
174
+ :path => parts[1],
174
175
  }
175
- when /^C (\S+)$/
176
+ when 'C'
176
177
  {
177
178
  :status => :clean,
178
- :path => Regexp.last_match(1),
179
+ :path => parts[1],
179
180
  }
180
- when /^R (\S+)$/
181
+ when 'R'
181
182
  {
182
183
  :status => :deleted,
183
- :path => Regexp.last_match(1),
184
+ :path => parts[1],
184
185
  }
185
- when /^M (\S+)$/
186
+ when 'M'
186
187
  {
187
188
  :status => :modified,
188
- :path => Regexp.last_match(1),
189
+ :path => parts[1],
189
190
  }
190
- when /^! (\S+)$/
191
+ when '!'
191
192
  {
192
193
  :status => :missing,
193
- :path => Regexp.last_match(1),
194
+ :path => parts[1],
194
195
  }
195
- when /^\? (\S+)$/
196
+ when '?'
196
197
  {
197
198
  :status => :untracked,
198
- :path => Regexp.last_match(1),
199
+ :path => parts[1],
199
200
  }
200
- when /^I (\S+)$/
201
+ when 'I'
201
202
  {
202
203
  :status => :ignored,
203
- :path => Regexp.last_match(1),
204
+ :path => parts[1],
204
205
  }
205
206
  else
206
207
  fail 'Failed to parse repo diff line.'
@@ -102,7 +102,7 @@ module BetweenMeals
102
102
  # http://svnbook.red-bean.com/en/1.0/re26.html
103
103
  changes.lines.map do |line|
104
104
  case line
105
- when /^([\w ])\w?\s+(\S+)$/
105
+ when /^([\w ])\w?\s+(.+)$/
106
106
  {
107
107
  :status => Regexp.last_match(1) == 'D' ? :deleted : :modified,
108
108
  :path => Regexp.last_match(2).sub("#{@repo_path}/", ''),
@@ -38,16 +38,17 @@ module BetweenMeals
38
38
  info("Executed in #{format('%.2f', Time.now - t0)}s")
39
39
  end
40
40
 
41
- def exec!(command, logger = nil)
41
+ def exec!(command, logger = nil, stream = nil)
42
42
  @@logger = logger if logger
43
- c = execute(command)
43
+ c = execute(command, stream)
44
44
  c.error!
45
45
  return c.status.exitstatus, c.stdout
46
46
  end
47
47
 
48
- def exec(command, logger = nil)
48
+ def exec(command, logger = nil, stream = nil)
49
49
  @@logger = logger if logger
50
- c = execute(command)
50
+
51
+ c = execute(command, stream)
51
52
  return c.status.exitstatus, c.stdout
52
53
  end
53
54
 
@@ -57,9 +58,9 @@ module BetweenMeals
57
58
  @@logger&.info(msg)
58
59
  end
59
60
 
60
- def execute(command)
61
+ def execute(command, stream)
61
62
  info("Running: #{command}")
62
- c = Mixlib::ShellOut.new(command)
63
+ c = Mixlib::ShellOut.new(command, :live_stream => stream)
63
64
  c.run_command
64
65
  c.stdout.lines.each do |line|
65
66
  info("STDOUT: #{line.strip}")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: between_meals
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Phil Dibowitz
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-08-02 00:00:00.000000000 Z
12
+ date: 2020-05-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: colorize
@@ -150,7 +150,7 @@ files:
150
150
  - lib/between_meals/util.rb
151
151
  homepage: https://github.com/facebook/between-meals
152
152
  licenses:
153
- - Apache
153
+ - Apache-2.0
154
154
  metadata: {}
155
155
  post_install_message:
156
156
  rdoc_options: []