-
Notifications
You must be signed in to change notification settings - Fork 0
/
guardian-make-todo
53 lines (45 loc) · 1.75 KB
/
guardian-make-todo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env ruby
require 'smarter_csv'
require 'yaml'
require 'smarter_csv'
#####
##
## Create a todo file like this:
#
# ---
# :todo_base: directive_name_1
# :source: "/$DOCKER_PATH/directive_name_1"
# :workspace: workspace/directive_name_1
# :compressed_destination: zip-workspace/directive_name_1/directive_name_1.zip
# :verification_destination: verify-workspace/directive_name_1
# :cleanup_directories: workspace/directive_name_1|zip-workspace/directive_name_1|verify-workspace/directive_name_1
# :glacier_description: '{"owner":"katherly","description":"directive_name_1"}'
# :glacier_vault: vault_name
# :application: bulwark
# :method: gitannex
# :verify_compressed_archive: 'true'
#
#
#
#####
def validate_args!
raise ArgumentError.new('Please supply a CSV file') if ARGV[0].nil?
raise ArgumentError.new('Please supply a destination directory') if ARGV[1].nil?
raise ArgumentError.new("#{ARGV[0]} not found") if File.exist?(ARGV[0]) == false
raise ArgumentError.new("#{ARGV[1]} not found") if File.directory?(ARGV[1]) == false
end
HEADERS = %i{ todo_base source workspace compressed_destination verification_destination cleanup_directories glacier_description glacier_vault application method verify_compressed_archive }
# Input columns are:
# todo_base source zip_dest compressed_source glacier_description glacier_vault
def create_todo_file(args = {}, dest_dir)
todo_base = args[:todo_base]
todo_path = File.join dest_dir, "#{todo_base}.todo"
data = HEADERS.inject({}) { |h,header| h.merge(header => args[header]) }
File.open(todo_path, 'w+') { |f| f.puts YAML::dump data }
end
validate_args!
file = ARGV[0]
dest_dir = ARGV[1]
SmarterCSV.process(file).each do |row|
create_todo_file(row, dest_dir)
end