require "tempfile" require "core/transports" module Buildr # :call-seq: # download(url_or_uri) => task # download(path=>url_or_uri) =>task # # Create a task that will download a file from a URL. # # Takes a single argument, a hash with one pair. The key is the file being # created, the value if the URL to download. The task executes only if the # file does not exist; the URL is not checked for updates. # # The task will show download progress on the console; if there are MD5/SHA1 # checksums on the server it will verify the download before saving it. # # For example: # download "image.jpg"=>"http://example.com/theme/image.jpg" def download(args) if String === args || URI === args # Given only a download URL, download into a temporary file. # You can infer the file from task name. temp = Tempfile.new(File.basename(args.to_s)) task = file_create(temp.path) do |task| Transports.download task.source, task.name end task.sources << args else # Download to a file created by the task. fail unless args.keys.size == 1 url = args.values.first task = file_create(args.keys.first) do |task| mkpath File.dirname(task.name), :verbose=>false Transports.download task.source, task.name end task.sources << url end task end end