lib/vagrant-mutate/box_loader.rb in vagrant-mutate-0.2.6 vs lib/vagrant-mutate/box_loader.rb in vagrant-mutate-0.3.0

- old
+ new

@@ -23,17 +23,19 @@ else raise Errors::ProviderNotSupported, :provider => provider_name, :direction => 'output' end end - def load(box_arg) + def load(box_arg, provider_name) if box_arg =~ /:\/\// box = load_from_url(box_arg) elsif File.file?(box_arg) box = load_from_file(box_arg) + elsif box_arg =~ /\// + raise Errors::CloudNotSupported else - box = load_from_boxes_path(box_arg) + box = load_from_boxes_path(box_arg, provider_name) end if box.supported_input return box else @@ -86,13 +88,12 @@ provider_name = determine_provider(dir) box = create_box(provider_name, name, dir) end - def load_from_boxes_path(identifier) - @logger.info "Loading box #{identifier} from vagrants box path" - provider_name, name = parse_identifier(identifier) + def load_from_boxes_path(name, provider_name) + @logger.info "Loading box #{name} from vagrants box path" if provider_name dir = verify_input_dir(provider_name, name) else provider_name, dir = find_input_dir(name) end @@ -127,12 +128,13 @@ raise Errors::ProviderNotSupported, :provider => provider_name, :direction => 'input or output' end end def create_output_dir(name, provider_name) - # e.g. $HOME/.vagrant.d/boxes/fedora-19/libvirt - out_dir = File.join( @env.boxes_path, name, provider_name ) + # e.g. $HOME/.vagrant.d/boxes/fedora-19/0/libvirt + # TODO support versioned boxes + out_dir = File.join( @env.boxes_path, name, '0', provider_name ) begin FileUtils.mkdir_p(out_dir) rescue => e raise Errors::CreateBoxDirFailed, :error_message => e.message end @@ -140,11 +142,11 @@ return out_dir end def unpack(file) @env.ui.info "Extracting box file to a temporary directory." - unless File.exists? file + unless File.exist? file raise Errors::BoxNotFound, :box => file end tmp_dir = Dir.mktmpdir(nil, @env.tmp_path) @tmp_files << tmp_dir result = Vagrant::Util::Subprocess.execute( @@ -156,11 +158,11 @@ return tmp_dir end def determine_provider(dir) metadata_file = File.join(dir, 'metadata.json') - if File.exists? metadata_file + if File.exist? metadata_file begin metadata = JSON.load( File.new( metadata_file, 'r') ) rescue => e raise Errors::DetermineProviderFailed, :error_message => e.message end @@ -170,35 +172,23 @@ @logger.info "No metadata found, so assuming input provider is virtualbox" return 'virtualbox' end end - def parse_identifier(identifier) - split_id = identifier.split('/') - case split_id.length - when 2 - @logger.info "Parsed provider name as #{split_id[0]} and box name as #{split_id[1]}" - return split_id[0], split_id[1] - when 1 - @logger.info "Parsed provider name as not given and box name as #{identifier}" - return nil, identifier - else - raise Errors::ParseIdentifierFailed, :identifier => identifier - end - end - def verify_input_dir(provider_name, name) - input_dir = File.join( @env.boxes_path, name, provider_name) + # TODO support versioned boxes + input_dir = File.join( @env.boxes_path, name, '0', provider_name) if File.directory?(input_dir) @logger.info "Found input directory #{input_dir}" return input_dir else raise Errors::BoxNotFound, :box => input_dir end end def find_input_dir(name) - box_parent_dir = File.join( @env.boxes_path, name) + # TODO support versioned boxes + box_parent_dir = File.join( @env.boxes_path, name, '0') if Dir.exist?(box_parent_dir) providers = Dir.entries(box_parent_dir).reject { |entry| entry =~ /^\./ } @logger.info "Found potential providers #{providers}" else