Revision d3b04f42
Added by Thomas McKay about 6 years ago
lib/hammer_cli_import/configfile.rb | ||
---|---|---|
136 | 136 |
# inside of working-directory |
137 | 137 |
def generate_module_template_for(name) |
138 | 138 |
module_name = name |
139 |
pwd = Dir.pwd |
|
139 | 140 |
Dir.chdir(option_working_directory) |
140 | 141 |
gen_cmd = "puppet module generate #{name}" |
141 | 142 |
Open3.popen3(gen_cmd) do |stdin, stdout, _stderr| |
142 |
stdout.sync = true |
|
143 |
ConfigFileImportCommand.interview_questions.each do |q| |
|
144 |
rd = '' |
|
145 |
until rd.include? '?' |
|
146 |
rd = stdout.readline |
|
147 |
#debug "Read #{rd}" |
|
143 |
begin |
|
144 |
stdout.sync = true |
|
145 |
ConfigFileImportCommand.interview_questions.each do |q| |
|
146 |
rd = '' |
|
147 |
until rd.include? '?' |
|
148 |
rd = stdout.readline |
|
149 |
debug "Read #{rd}" |
|
150 |
end |
|
151 |
answer = @interview_answers[q].gsub('#{module_name}', module_name) |
|
152 |
stdin.puts(answer) |
|
148 | 153 |
end |
149 |
answer = @interview_answers[q].gsub('#{module_name}', module_name) |
|
150 |
stdin.puts(answer) |
|
154 |
rescue EOFError => e |
|
155 |
debug 'Done reading' |
|
156 |
break |
|
151 | 157 |
end |
152 |
rd = '' |
|
153 | 158 |
begin |
159 |
rd = '' |
|
154 | 160 |
rd = stdout.readline while rd |
155 | 161 |
rescue EOFError |
156 | 162 |
debug 'Done reading' |
157 | 163 |
end |
158 | 164 |
end |
165 |
Dir.chdir(pwd) |
|
159 | 166 |
|
160 | 167 |
# Now that we have generated the module, add a 'description' to the |
161 | 168 |
# metadata.json file found at option_working_dir/<name>/metadata.json |
162 | 169 |
metadata_path = File.join(File.join(option_working_directory, name), 'metadata.json') |
163 |
answer = @interview_answers['description'].gsub('#{module_name}', module_name) |
|
164 |
sed_cmd = "sed -i '\/\"summary\":\/a \\ \\ \"description\": \"#{answer}\",' #{metadata_path}" |
|
165 |
debug "About to issue #{sed_cmd}" |
|
166 |
system sed_cmd |
|
167 |
report_summary :wrote, :puppet_modules |
|
170 |
if File.exist? metadata_path |
|
171 |
answer = @interview_answers['description'].gsub('#{module_name}', module_name) |
|
172 |
sed_cmd = "sed -i '\/\"summary\":\/a \\ \\ \"description\": \"#{answer}\",' #{metadata_path}" |
|
173 |
debug "About to issue #{sed_cmd}" |
|
174 |
system sed_cmd |
|
175 |
report_summary :wrote, :puppet_modules |
|
176 |
else |
|
177 |
info "Failed puppet module #{name}: metadata.json not created" |
|
178 |
report_summary :failed, :puppet_modules |
|
179 |
end |
|
168 | 180 |
end |
169 | 181 |
|
170 | 182 |
def build_puppet_module(module_name) |
171 | 183 |
module_dir = File.join(option_working_directory, module_name) |
184 |
return nil unless File.exist? module_dir |
|
172 | 185 |
Dir.chdir(module_dir) |
173 | 186 |
gen_cmd = 'puppet module build' |
174 | 187 |
Open3.popen3(gen_cmd) do |_stdin, stdout, _stderr| |
... | ... | |
284 | 297 |
def export_files |
285 | 298 |
progress 'Writing converted files' |
286 | 299 |
@modules.each do |mname, files| |
300 |
module_dir = File.join(option_working_directory, mname) |
|
301 |
next unless File.exist? module_dir |
|
287 | 302 |
info "Found module #{mname}" |
288 | 303 |
dsl = '' |
289 | 304 |
|
290 |
module_dir = File.join(option_working_directory, mname) |
|
291 | 305 |
fdir = File.join(module_dir, 'files') |
292 | 306 |
Dir.mkdir(fdir) |
293 | 307 |
tdir = File.join(module_dir, 'templates') |
... | ... | |
359 | 373 |
|
360 | 374 |
# Build the puppet-module for upload |
361 | 375 |
module_dir = build_puppet_module(mname) |
376 |
next if module_dir.nil? |
|
362 | 377 |
|
363 | 378 |
# Build/find the product |
364 | 379 |
product_hash = mk_product_hash(data, prod_name) |
... | ... | |
372 | 387 |
[data['org_id'].to_i, data['channel_id'].to_i]) |
373 | 388 |
|
374 | 389 |
# Find the built-module .tar.gz |
375 |
built_module_path = File.join(File.join(module_dir, 'pkg'),
|
|
390 |
built_module_path = File.join('pkg',
|
|
376 | 391 |
"#{mname}-#{@interview_answers['version']}.tar.gz") |
377 | 392 |
info "Uploading #{built_module_path}" |
378 | 393 |
|
Also available in: Unified diff
fixes #14616 - correct handling of EOF error