Implement clone command in the binary
This commit is contained in:
@ -15,20 +15,7 @@ module SlackBuilder
|
||||
extend Rake::FileUtilsExt
|
||||
|
||||
def self.clone(repo, tarball, tag_prefix = 'v')
|
||||
name_version = File.basename tarball, '.tar.xz'
|
||||
remote_path = tarball[tarball.index('/')..]
|
||||
|
||||
if remote_file_exists?(remote_path)
|
||||
uri = URI hosted_sources(remote_path)
|
||||
|
||||
return download(uri, "slackbuilds/#{tarball}").hexdigest
|
||||
end
|
||||
|
||||
clone_and_archive repo, name_version, tarball, tag_prefix
|
||||
|
||||
sh(*upload_command(tarball, remote_path))
|
||||
|
||||
Digest::MD5.hexdigest File.read("slackbuilds/#{tarball}")
|
||||
`./bin/slackbuilder clone #{repo} #{tarball} #{tag_prefix}`
|
||||
end
|
||||
|
||||
def self.download(uri, target)
|
||||
@ -56,46 +43,6 @@ module SlackBuilder
|
||||
checksum.hexdigest
|
||||
end
|
||||
|
||||
private_class_method def self.redirect_download(location, target)
|
||||
puts 'redirecting...'
|
||||
new_location = URI location
|
||||
|
||||
download new_location, target
|
||||
end
|
||||
|
||||
private_class_method def self.write_chunk(response, checksum, progressbar, io)
|
||||
response.read_body do |chunk|
|
||||
progressbar.progress += chunk.length
|
||||
io << chunk
|
||||
checksum << chunk
|
||||
end
|
||||
end
|
||||
|
||||
private_class_method def self.write_download(target, response)
|
||||
checksum = Digest::MD5.new
|
||||
progressbar = ProgressBar.create title: target, total: response.header.content_length
|
||||
|
||||
File.open target, 'w' do |io|
|
||||
write_chunk response, checksum, progressbar, io
|
||||
end
|
||||
progressbar.finish
|
||||
|
||||
checksum
|
||||
end
|
||||
|
||||
private_class_method def self.start_download(uri, target, http)
|
||||
request = Net::HTTP::Get.new uri
|
||||
|
||||
http.request request do |response|
|
||||
case response
|
||||
when Net::HTTPRedirection
|
||||
return redirect_download response['location'], target
|
||||
else
|
||||
return write_download target, response
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private_class_method def self.upload_command(local_path, remote_path)
|
||||
['scp', "slackbuilds/#{local_path}", CONFIG[:remote_path] + remote_path]
|
||||
end
|
||||
|
Reference in New Issue
Block a user