Add a report progress feature to the UI
This commit is contained in:
parent
9ab5a7c2b1
commit
3fdcd50ea0
|
@ -39,10 +39,8 @@ module Vagrant
|
|||
def export
|
||||
@env.ui.info "Exporting VM to #{ovf_path}..."
|
||||
@env["vm"].vm.export(ovf_path) do |progress|
|
||||
@env.logger.report_progress(progress.percent, 100, false)
|
||||
@env.ui.report_progress(progress.percent, 100, false)
|
||||
end
|
||||
ensure
|
||||
@env.logger.clear_progress
|
||||
end
|
||||
|
||||
def ovf_path
|
||||
|
|
|
@ -9,18 +9,14 @@ module Vagrant
|
|||
def call(env)
|
||||
env.ui.info "Importing base VM (#{env.env.box.ovf_file})"
|
||||
|
||||
begin
|
||||
# Import the virtual machine
|
||||
env.env.vm.vm = VirtualBox::VM.import(env.env.box.ovf_file) do |progress|
|
||||
env.logger.report_progress(progress.percent, 100, false)
|
||||
end
|
||||
|
||||
# Flag as erroneous and return if import failed
|
||||
return env.error!(:virtualbox_import_failure) if !env['vm'].vm
|
||||
ensure
|
||||
env.logger.clear_progress
|
||||
# Import the virtual machine
|
||||
env.env.vm.vm = VirtualBox::VM.import(env.env.box.ovf_file) do |progress|
|
||||
env.ui.report_progress(progress.percent, 100, false)
|
||||
end
|
||||
|
||||
# Flag as erroneous and return if import failed
|
||||
return env.error!(:virtualbox_import_failure) if !env['vm'].vm
|
||||
|
||||
# Import completed successfully. Continue the chain
|
||||
@app.call(env)
|
||||
end
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
require 'mario'
|
||||
|
||||
module Vagrant
|
||||
# Vagrant UIs handle communication with the outside world (typically
|
||||
# through a shell). They must respond to the typically logger methods
|
||||
|
@ -9,7 +11,7 @@ module Vagrant
|
|||
@env = env
|
||||
end
|
||||
|
||||
[:warn, :error, :info, :confirm, :say_with_vm].each do |method|
|
||||
[:warn, :error, :info, :confirm, :say_with_vm, :report_progress].each do |method|
|
||||
# By default these methods don't do anything. A silent UI.
|
||||
define_method(method) { |*args| }
|
||||
end
|
||||
|
@ -26,16 +28,31 @@ module Vagrant
|
|||
[[:warn, :yellow], [:error, :red], [:info, nil], [:confirm, :green]].each do |method, color|
|
||||
define_method(method) do |message, prepend_vm_name=true|
|
||||
message = format_message(message) if prepend_vm_name
|
||||
@shell.say(message, color)
|
||||
@shell.say("#{line_reset}#{message}", color)
|
||||
end
|
||||
end
|
||||
|
||||
def report_progress(progress, total, show_parts=true)
|
||||
percent = (progress.to_f / total.to_f) * 100
|
||||
line = "Progress: #{percent.to_i}%"
|
||||
line << " (#{data[:progress]} / #{data[:total]})" if data[:show_parts]
|
||||
line = "#{line_reset}#{line}"
|
||||
|
||||
@shell.say(line, nil, false)
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def format_message(message)
|
||||
name = env.vm_name || "vagrant"
|
||||
"[#{name}] #{message}"
|
||||
end
|
||||
|
||||
def line_reset
|
||||
reset = "\r"
|
||||
reset += "\e[0K" unless Mario::Platform.windows?
|
||||
reset
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue