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
|
def export
|
||||||
@env.ui.info "Exporting VM to #{ovf_path}..."
|
@env.ui.info "Exporting VM to #{ovf_path}..."
|
||||||
@env["vm"].vm.export(ovf_path) do |progress|
|
@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
|
end
|
||||||
ensure
|
|
||||||
@env.logger.clear_progress
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def ovf_path
|
def ovf_path
|
||||||
|
|
|
@ -9,18 +9,14 @@ module Vagrant
|
||||||
def call(env)
|
def call(env)
|
||||||
env.ui.info "Importing base VM (#{env.env.box.ovf_file})"
|
env.ui.info "Importing base VM (#{env.env.box.ovf_file})"
|
||||||
|
|
||||||
begin
|
# Import the virtual machine
|
||||||
# Import the virtual machine
|
env.env.vm.vm = VirtualBox::VM.import(env.env.box.ovf_file) do |progress|
|
||||||
env.env.vm.vm = VirtualBox::VM.import(env.env.box.ovf_file) do |progress|
|
env.ui.report_progress(progress.percent, 100, false)
|
||||||
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
|
|
||||||
end
|
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
|
# Import completed successfully. Continue the chain
|
||||||
@app.call(env)
|
@app.call(env)
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
require 'mario'
|
||||||
|
|
||||||
module Vagrant
|
module Vagrant
|
||||||
# Vagrant UIs handle communication with the outside world (typically
|
# Vagrant UIs handle communication with the outside world (typically
|
||||||
# through a shell). They must respond to the typically logger methods
|
# through a shell). They must respond to the typically logger methods
|
||||||
|
@ -9,7 +11,7 @@ module Vagrant
|
||||||
@env = env
|
@env = env
|
||||||
end
|
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.
|
# By default these methods don't do anything. A silent UI.
|
||||||
define_method(method) { |*args| }
|
define_method(method) { |*args| }
|
||||||
end
|
end
|
||||||
|
@ -26,16 +28,31 @@ module Vagrant
|
||||||
[[:warn, :yellow], [:error, :red], [:info, nil], [:confirm, :green]].each do |method, color|
|
[[:warn, :yellow], [:error, :red], [:info, nil], [:confirm, :green]].each do |method, color|
|
||||||
define_method(method) do |message, prepend_vm_name=true|
|
define_method(method) do |message, prepend_vm_name=true|
|
||||||
message = format_message(message) if prepend_vm_name
|
message = format_message(message) if prepend_vm_name
|
||||||
@shell.say(message, color)
|
@shell.say("#{line_reset}#{message}", color)
|
||||||
end
|
end
|
||||||
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
|
protected
|
||||||
|
|
||||||
def format_message(message)
|
def format_message(message)
|
||||||
name = env.vm_name || "vagrant"
|
name = env.vm_name || "vagrant"
|
||||||
"[#{name}] #{message}"
|
"[#{name}] #{message}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def line_reset
|
||||||
|
reset = "\r"
|
||||||
|
reset += "\e[0K" unless Mario::Platform.windows?
|
||||||
|
reset
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue