Commit 92c1befe authored by Francis Chong's avatar Francis Chong

add http downloader - that download repo with http and then decompress them

parent 6559e58a
require 'fileutils' require 'fileutils'
require 'yaml'
module Pod module Pod
class Command class Command
......
...@@ -6,6 +6,7 @@ module Pod ...@@ -6,6 +6,7 @@ module Pod
autoload :GitHub, 'cocoapods/downloader/git' autoload :GitHub, 'cocoapods/downloader/git'
autoload :Mercurial, 'cocoapods/downloader/mercurial' autoload :Mercurial, 'cocoapods/downloader/mercurial'
autoload :Subversion, 'cocoapods/downloader/subversion' autoload :Subversion, 'cocoapods/downloader/subversion'
autoload :Http, 'cocoapods/downloader/http'
extend Executable extend Executable
...@@ -40,6 +41,8 @@ module Pod ...@@ -40,6 +41,8 @@ module Pod
Mercurial.new(target_path, url, options) Mercurial.new(target_path, url, options)
elsif url = options.delete(:svn) elsif url = options.delete(:svn)
Subversion.new(target_path, url, options) Subversion.new(target_path, url, options)
elsif url = options.delete(:http)
Http.new(target_path, url, options)
else else
raise "Unsupported download strategy `#{options.inspect}'." raise "Unsupported download strategy `#{options.inspect}'."
end end
......
require 'open-uri'
require 'tempfile'
require 'zlib'
require 'yaml'
module Pod
class Downloader
class Http < Downloader
executable :curl
executable :unzip
executable :tar
attr_accessor :download_file_path
def download
type = options[:type] || type_with_url(url)
filename = filename_with_type type
@download_path = target_path + filename
download_file @download_path
extract_with_type @download_path, type
end
def clean
FileUtils.rm @download_path
end
private
def type_with_url(url)
if url =~ /.zip$/
:zip
elsif url =~ /.tgz$/
:tgz
elsif url =~ /.tar$/
:tar
else
nil
end
end
def filename_with_type(type=:zip)
case type
when :zip
"file.zip"
when :tgz
"file.tgz"
when :tar
"file.tar"
else
raise "Pod::Downloader::Http Unsupported file type: #{type}"
end
end
def download_file(full_filename)
curl "-L -o '#{full_filename}' '#{url}'"
end
def extract_with_type(full_filename, type=:zip)
case type
when :zip
unzip "'#{full_filename}' -d #{target_path}"
when :tgz
tar "xfz '#{full_filename}' -d #{target_path}"
when :tar
tar "xf '#{full_filename}' -d #{target_path}"
else
raise "Http Downloader: Unsupported file type"
end
end
end
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment