Class: HammerCLIForemanBootdisk::DownloadCommand

Inherits:
HammerCLIForeman::Command
  • Object
show all
Defined in:
lib/hammer_cli_foreman_bootdisk/commands.rb

Instance Method Summary collapse

Instance Method Details



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/hammer_cli_foreman_bootdisk/commands.rb', line 10

def print_data(record)
  server_filename = $1 if record.headers[:content_disposition] =~ /filename=["']?([^\s,;"']+)/
  file = options[HammerCLI.option_accessor_name('file')] || server_filename || 'bootdisk.iso'
  if !options[HammerCLI.option_accessor_name('force')] && File.exist?(file) && !File.file?(file)
    raise(HammerCLIForeman::OperationNotSupportedError, _("Destination %s already exists and isn't a regular file, use '--force' if you are sure you wish to write to it") % file)
  end

  if options[HammerCLI.option_accessor_name('sudo')]
    temp_file = Tempfile.new('bootdisk')
    begin
      File.open(temp_file, 'w') { |f| f.write(record) }
      system('sudo', 'dd', "if=#{temp_file.path}", "of=#{file}", 'bs=1024')
    ensure
      temp_file.close
      temp_file.unlink
    end
  else
    File.open(file, 'w') { |f| f.write(record) }
  end
  print_message (success_message % file) if success_message
end

#request_optionsObject



32
33
34
# File 'lib/hammer_cli_foreman_bootdisk/commands.rb', line 32

def request_options
  {:response => :raw}
end