Sha256: fec520ffec2e5208f94966344f2cbfcf22ecb73c2eca4539363e0f26f1210f40

Contents?: true

Size: 1.57 KB

Versions: 4

Compression:

Stored size: 1.57 KB

Contents

require 'pe_build'
require 'pe_build/action'
require 'vagrant'
require 'fileutils'

class PEBuild::Action::Download
  # Downloads a PE build to a temp directory

  def initialize(app, env)
    @app, @env = app, env
    load_variables
  end

  def call(env)
    @env = env
    perform_download
    @app.call(@env)
  end

  private

  # Determine system state and download a PE build accordingly.
  #
  # If we are applying actions within the context of a single box, then we
  # should try to prefer and box level configuration options first. If
  # anything is unset then we should fall back to the global settings.
  def load_variables
    if @env[:box_name]
      @root     = @env[:vm].pe_build.download_root
      @version  = @env[:vm].pe_build.version
      @filename = @env[:vm].pe_build.version
    end

    @root     ||= @env[:global_config].pe_build.download_root
    @version  ||= @env[:global_config].pe_build.version
    @filename ||= @env[:global_config].pe_build.filename

    @archive_path = File.join(PEBuild.archive_directory, @filename)
  end

  # @return [String] The full URL to download, based on the config
  def url
    [@root, @version, @filename].join('/')
  end

  def perform_download
    if File.exist? @archive_path
      @env[:ui].info "#{@filename} cached, skipping download."
    else
      FileUtils.mkdir_p PEBuild.archive_directory unless File.directory? PEBuild.archive_directory
      cmd = %{curl -L -A "Vagrant/PEBuild (v#{PEBuild::VERSION})" -O #{url}}
      @env[:ui].info "Executing '#{cmd}'"
      Dir.chdir(PEBuild.archive_directory) { %x{#{cmd}} }
    end
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
vagrant-pe_build-0.0.2 lib/pe_build/action/download.rb
vagrant-pe_build-0.0.1 lib/pe_build/action/download.rb
oscar-0.2.0alpha2 lib/pe_build/action/download.rb
oscar-0.2.0alpha1 lib/pe_build/action/download.rb