Sha256: fb79f8bc5d835a916c9be1b27b674cbc9a9d793b321b2d93b2791174f17c4a7b

Contents?: true

Size: 1.21 KB

Versions: 4

Compression:

Stored size: 1.21 KB

Contents

require 'bundler/gem_tasks'
require 'rspec/core/rake_task'

desc 'Download files for running integration tests against'
task :get_tifs do
  require 'net/ftp'
  require 'fileutils'

  base_dest_dir = 'spec/support/images/osgeo/geotiff'

  Net::FTP.open('downloads.osgeo.org') do |ftp|
    ftp.login
    ftp.binary = true

    base_dir = 'geotiff/samples'
    _, dirs = files_and_dirs(base_dir, ftp)

    dirs.each do |dir_name|
      path = "#{base_dir}/#{dir_name}"
      files, dirs = files_and_dirs(path, ftp)
      dest_dir = "#{base_dest_dir}/#{dir_name}"

      FileUtils.mkdir_p(dest_dir) unless Dir.exist?(dest_dir)

      files.each do |file|
        src_file = "#{path}/#{file}"
        dest_file = "#{dest_dir}/#{file}"

        puts "Getting file '#{src_file}' to '#{dest_file}'..."
        ftp.get("#{src_file}", "#{dest_file}")
      end
    end
  end
end

# @return [Array{files => Array, dirs => Array}]
def files_and_dirs(in_dir, ftp)
  dirs = []
  files = []

  puts "Getting stuff from #{in_dir}..."

  ftp.list("#{in_dir}/*") do |item|
    item_name = item.split(' ').last

    if item.start_with? 'd'
      dirs << item_name
    else
      files << item_name
    end
  end

  [files, dirs]
end


RSpec::Core::RakeTask.new

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ffi-gdal-0.0.4 Rakefile
ffi-gdal-0.0.3 Rakefile
ffi-gdal-0.0.2 Rakefile
ffi-gdal-0.0.1 Rakefile