Downloader progress reporter now uses the environment logger

This commit is contained in:
Mitchell Hashimoto 2010-05-20 22:37:39 -07:00
parent 6e7af31616
commit b2c2d2a4cc
7 changed files with 19 additions and 17 deletions

View File

@ -18,7 +18,7 @@ module Vagrant
[Downloaders::HTTP, Downloaders::File].each do |dler|
if dler.match?(@runner.uri)
logger.info "Downloading via #{dler}..."
@downloader = dler.new
@downloader = dler.new(@runner.env)
end
end
@ -52,7 +52,7 @@ module Vagrant
yield tempfile
end
end
def file_options
# create, write only, fail if the file exists, binary if windows
File::WRONLY|File::EXCL|File::CREAT|(Mario::Platform.windows? ? File::BINARY : 0)

View File

@ -2,8 +2,6 @@ module Vagrant
module Actions
module VM
class Export < Base
include Util::ProgressMeter
attr_reader :temp_dir
def execute!
@ -36,10 +34,10 @@ module Vagrant
def export
logger.info "Exporting VM to #{ovf_path}..."
@runner.vm.export(ovf_path) do |progress|
update_progress(progress.percent, 100, false)
logger.report_progress(progress.percent, 100, false)
end
complete_progress
logger.clear_progress
end
end
end

View File

@ -2,18 +2,16 @@ module Vagrant
module Actions
module VM
class Import < Base
include Util::ProgressMeter
def execute!
@runner.invoke_around_callback(:import) do
Busy.busy do
logger.info "Importing base VM (#{@runner.env.box.ovf_file})..."
# Use the first argument passed to the action
@runner.vm = VirtualBox::VM.import(@runner.env.box.ovf_file) do |progress|
update_progress(progress.percent, 100, false)
logger.report_progress(progress.percent, 100, false)
end
complete_progress
logger.clear_progress
raise ActionException.new(:virtualbox_import_failure) unless @runner.vm
end

View File

@ -5,6 +5,13 @@ module Vagrant
class Base
include Vagrant::Util
# The environment which this downloader is operating.
attr_reader :env
def initialize(env)
@env = env
end
# Called prior to execution so any error checks can be done
def prepare(source_url); end
@ -13,4 +20,4 @@ module Vagrant
def download!(source_url, destination_file); end
end
end
end
end

View File

@ -3,8 +3,6 @@ module Vagrant
# Downloads a file from an HTTP URL to a temporary file. This
# downloader reports its progress to stdout while downloading.
class HTTP < Base
include Util::ProgressMeter
def self.match?(uri)
# URI.parse barfs on '<drive letter>:\\files \on\ windows'
# TODO temprorary
@ -26,7 +24,7 @@ module Vagrant
# Progress reporting is limited to every 25 segments just so
# we're not constantly updating
if segment_count % 25 == 0
update_progress(progress, total)
env.logger.report_progress(progress, total)
segment_count = 0
end
@ -35,7 +33,7 @@ module Vagrant
end
end
complete_progress
env.logger.clear_progress
end
end
end

View File

@ -142,7 +142,7 @@ class Test::Unit::TestCase
tempfile = mock("tempfile")
tempfile.stubs(:write)
[downloader_klass.new, tempfile]
[downloader_klass.new(mock_environment), tempfile]
end
end

View File

@ -7,7 +7,8 @@ class BaseDownloaderTest < Test::Unit::TestCase
context "base instance" do
setup do
@base = Vagrant::Downloaders::Base.new
@env = mock_environment
@base = Vagrant::Downloaders::Base.new(@env)
end
should "implement prepare which does nothing" do