palletjack 0.6.2 → 0.6.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/.rubocop.yml +7 -2
- data/.rubocop_todo.yml +2 -1
- data/lib/palletjack/tool.rb +77 -39
- data/lib/palletjack/version.rb +1 -1
- data/palletjack.gemspec +1 -0
- data.tar.gz.sig +0 -0
- metadata +2 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a311c5f84cc62a899d75d2d568f1f3080708d102
|
4
|
+
data.tar.gz: bb4564952042bbe43374456a43b2570c8fde909a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 52fb77bb8e144ecefad11a4122ccf2e17783879b0bccab0075d1ffc35c3ab9b3d0ab98132132256eae2f03c941c3118b69707a28b63057fd52160353e28fe159
|
7
|
+
data.tar.gz: 113b72574d9fe43009d09d525a0fd02a477fa122a8ad7d5e021677612ac68dd3736d6115ea4b2d5201232991897ae0b4fcda4b4a19a59c9a04c16d95fb2b0e35
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/.rubocop.yml
CHANGED
@@ -2,5 +2,10 @@ inherit_from: .rubocop_todo.yml
|
|
2
2
|
|
3
3
|
Style/IndentArray:
|
4
4
|
EnforcedStyle: consistent
|
5
|
-
Style/MethodName:
|
6
|
-
EnforcedStyle: snake_case
|
5
|
+
Style/MethodName:
|
6
|
+
EnforcedStyle: snake_case
|
7
|
+
Style/SymbolArray:
|
8
|
+
EnforcedStyle: brackets
|
9
|
+
Lint/HandleExceptions:
|
10
|
+
Exclude:
|
11
|
+
- 'spec/palletjack-tool_spec.rb'
|
data/.rubocop_todo.yml
CHANGED
@@ -77,7 +77,7 @@ Metrics/BlockLength:
|
|
77
77
|
# Offense count: 3
|
78
78
|
# Configuration parameters: CountComments.
|
79
79
|
Metrics/ClassLength:
|
80
|
-
Max:
|
80
|
+
Max: 147
|
81
81
|
|
82
82
|
# Offense count: 13
|
83
83
|
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
|
@@ -323,6 +323,7 @@ Style/GuardClause:
|
|
323
323
|
Style/HashSyntax:
|
324
324
|
Exclude:
|
325
325
|
- 'Rakefile'
|
326
|
+
- 'exe/palletjack-pallet'
|
326
327
|
- 'tools/Rakefile'
|
327
328
|
- 'tools/exe/palletjack2pxelinux'
|
328
329
|
|
data/lib/palletjack/tool.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'palletjack'
|
2
2
|
require 'fileutils'
|
3
|
+
require 'pathname'
|
3
4
|
require 'optparse'
|
4
5
|
require 'singleton'
|
5
6
|
require 'rugged'
|
@@ -137,14 +138,18 @@ module PalletJack
|
|
137
138
|
'warehouse directory', String) {|dir|
|
138
139
|
@options[:warehouse] = dir }
|
139
140
|
@parser.on_tail('-h', '--help', 'display usage information') {
|
140
|
-
raise
|
141
|
+
raise OptionParser::ParseError }
|
141
142
|
|
142
143
|
parse_options(@parser)
|
143
144
|
|
144
145
|
@parser.parse!(argv)
|
145
146
|
@option_checks.each {|check| check.call }
|
146
|
-
rescue
|
147
|
-
|
147
|
+
rescue OptionParser::ParseError => error
|
148
|
+
if error.args.empty?
|
149
|
+
abort(usage)
|
150
|
+
else
|
151
|
+
abort("#{error}\n\n#{usage}")
|
152
|
+
end
|
148
153
|
end
|
149
154
|
|
150
155
|
# Additional option parsing
|
@@ -188,9 +193,9 @@ module PalletJack
|
|
188
193
|
# end
|
189
194
|
|
190
195
|
def required_option(*opts)
|
191
|
-
@option_checks << lambda do
|
192
|
-
raise
|
193
|
-
end
|
196
|
+
@option_checks << (lambda do
|
197
|
+
raise OptionParser::ParseError unless opts.any? {|opt| options[opt]}
|
198
|
+
end)
|
194
199
|
end
|
195
200
|
|
196
201
|
# Require the presence of no more than one of the given options.
|
@@ -208,9 +213,9 @@ module PalletJack
|
|
208
213
|
# end
|
209
214
|
|
210
215
|
def exclusive_options(*opts)
|
211
|
-
@option_checks << lambda do
|
212
|
-
raise
|
213
|
-
end
|
216
|
+
@option_checks << (lambda do
|
217
|
+
raise OptionParser::ParseError if opts.count {|opt| options[opt]} > 1
|
218
|
+
end)
|
214
219
|
end
|
215
220
|
|
216
221
|
# Usage information from option parser
|
@@ -255,9 +260,7 @@ module PalletJack
|
|
255
260
|
# Build a filesystem path from path components
|
256
261
|
#
|
257
262
|
# Symbols are looked up in the options dictionary.
|
258
|
-
# All
|
259
|
-
# resulting list is fed to File#join to produce a
|
260
|
-
# local filesystem compliant path.
|
263
|
+
# All components are converted to Pathname and concatenated.
|
261
264
|
#
|
262
265
|
# Example:
|
263
266
|
# parser.on(...) {|dir| options[:output] = dir }
|
@@ -266,14 +269,16 @@ module PalletJack
|
|
266
269
|
# config_path :output, 'subdir2'
|
267
270
|
|
268
271
|
def config_path(*path)
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
272
|
+
path.map { |item|
|
273
|
+
case item
|
274
|
+
when Pathname
|
275
|
+
item
|
276
|
+
when Symbol
|
277
|
+
Pathname.new(options.fetch(item))
|
278
|
+
else
|
279
|
+
Pathname.new(item.to_s)
|
280
|
+
end
|
281
|
+
}.reduce(&:+)
|
277
282
|
end
|
278
283
|
|
279
284
|
# :call-seq:
|
@@ -300,8 +305,12 @@ module PalletJack
|
|
300
305
|
# config_file :option, 'fragment', 'base.ext' {|file| ... }
|
301
306
|
# config_file ..., mode:0600 {|file| ...}
|
302
307
|
#
|
303
|
-
# Creates a configuration file
|
304
|
-
# and calls the given block with the file
|
308
|
+
# Creates a temporary configuration file with an undefined name,
|
309
|
+
# with default mode:0644, and calls the given block with the file
|
310
|
+
# as argument. After the block has run, the file is atomically
|
311
|
+
# renamed to the given destination file name. If any errors occur,
|
312
|
+
# the temporary file is deleted without overwriting the
|
313
|
+
# destination file.
|
305
314
|
#
|
306
315
|
# Uses config_path to construct the path, so any symbols will
|
307
316
|
# be looked up in the options hash.
|
@@ -315,9 +324,25 @@ module PalletJack
|
|
315
324
|
# end
|
316
325
|
|
317
326
|
def config_file(*path, mode: 0644, &block)
|
318
|
-
|
319
|
-
|
320
|
-
|
327
|
+
filename = config_path(*path)
|
328
|
+
begin
|
329
|
+
temp_filename = "#{filename}.tmp.#{Process.pid}.#{rand(1_000_000)}"
|
330
|
+
temp_file = File.new(temp_filename,
|
331
|
+
File::CREAT | File::EXCL | File::RDWR)
|
332
|
+
rescue Errno::EEXIST
|
333
|
+
retry
|
334
|
+
end
|
335
|
+
|
336
|
+
begin
|
337
|
+
temp_file.flock(File::LOCK_EX)
|
338
|
+
block.call(temp_file)
|
339
|
+
temp_file.flush
|
340
|
+
File.rename(temp_filename, filename)
|
341
|
+
rescue
|
342
|
+
File.unlink(temp_filename) rescue nil
|
343
|
+
raise
|
344
|
+
ensure
|
345
|
+
temp_file.close
|
321
346
|
end
|
322
347
|
end
|
323
348
|
|
@@ -337,29 +362,41 @@ module PalletJack
|
|
337
362
|
config_dir :warehouse, kind, name
|
338
363
|
end
|
339
364
|
|
340
|
-
#
|
365
|
+
# :call-seq:
|
366
|
+
# pallet_box kind, name, box, 'key.path' => value, ...
|
367
|
+
# pallet_box kind, name, box { { key: { path: value, ... } } }
|
368
|
+
#
|
369
|
+
# Write keys to a box file inside a pallet
|
370
|
+
#
|
371
|
+
# Any key.path assignments given as parameters, and the hash value
|
372
|
+
# returned from a block will be merged into the named box file.
|
341
373
|
#
|
342
|
-
# The block should return a hash representing the contents of the box.
|
343
374
|
# All keys will be stringified, so we can use key: short forms for
|
344
375
|
# declaration of the box contents.
|
345
376
|
#
|
346
377
|
# Uses config_file to create the file, so any symbols will
|
347
|
-
# be looked up in the options hash.
|
348
|
-
#
|
349
|
-
# N.B! If the box already exists, it will be overwritten!
|
350
|
-
#--
|
351
|
-
# FIXME: should new values be merged with existing box data instead?
|
352
|
-
#++
|
378
|
+
# be looked up in the options hash, except for the box name.
|
353
379
|
#
|
354
380
|
# Example:
|
355
381
|
#
|
356
382
|
# pallet_box 'domain', :domain, 'dns' do
|
357
383
|
# { dns:{ ns:options[:soa_ns].split(',') } }
|
358
384
|
# end
|
385
|
+
#--
|
386
|
+
# FIXME: Box I/O should probably be managed by PalletJack::Pallet,
|
387
|
+
# but that requires some redesign work.
|
388
|
+
#++
|
389
|
+
|
390
|
+
def pallet_box(kind, name, box, keyvalues = {}, &block)
|
391
|
+
box_path = config_path(:warehouse, kind, name, "#{box}.yaml")
|
392
|
+
contents = KVDAG::KeyPathHashProxy.new
|
393
|
+
|
394
|
+
contents.merge! YAML::load_file(box_path) if box_path.file?
|
395
|
+
keyvalues.each { |key, value| contents[key] = value }
|
396
|
+
contents.merge! block.call if block_given?
|
359
397
|
|
360
|
-
|
361
|
-
|
362
|
-
box_file << block.call.deep_stringify_keys.to_yaml
|
398
|
+
config_file box_path do |box_file|
|
399
|
+
box_file << contents.deep_stringify_keys.to_yaml
|
363
400
|
end
|
364
401
|
end
|
365
402
|
|
@@ -378,7 +415,8 @@ module PalletJack
|
|
378
415
|
|
379
416
|
def pallet_links(kind, name, links = {})
|
380
417
|
links.each do |link_type, parent|
|
381
|
-
|
418
|
+
link_base = config_path(:warehouse, kind, name)
|
419
|
+
link_path = config_path(link_base, link_type)
|
382
420
|
|
383
421
|
begin
|
384
422
|
File.delete(link_path)
|
@@ -387,9 +425,9 @@ module PalletJack
|
|
387
425
|
end
|
388
426
|
unless parent.empty?
|
389
427
|
parent_kind, parent_name = parent
|
390
|
-
parent_path = config_path(
|
428
|
+
parent_path = config_path(:warehouse, parent_kind, parent_name)
|
391
429
|
|
392
|
-
File.symlink(parent_path, link_path)
|
430
|
+
File.symlink(parent_path.relative_path_from(link_base), link_path)
|
393
431
|
end
|
394
432
|
end
|
395
433
|
end
|
data/lib/palletjack/version.rb
CHANGED
data/palletjack.gemspec
CHANGED
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: palletjack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Calle Englund
|
@@ -31,7 +31,7 @@ cert_chain:
|
|
31
31
|
f8wtQllq82VF0AXUYeLtTh1f+DW3WW5BO1e2OCu5eOV7dbyaVPaNK/+rHjCN8kM/
|
32
32
|
DGZSwUoNADmVkQ==
|
33
33
|
-----END CERTIFICATE-----
|
34
|
-
date: 2017-
|
34
|
+
date: 2017-04-28 00:00:00.000000000 Z
|
35
35
|
dependencies:
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: activesupport
|
metadata.gz.sig
CHANGED
Binary file
|