Skip to content

Commit

Permalink
[rb] appease the linter
Browse files Browse the repository at this point in the history
  • Loading branch information
titusfortner committed Oct 19, 2021
1 parent 9816645 commit 89b7491
Showing 1 changed file with 30 additions and 30 deletions.
60 changes: 30 additions & 30 deletions rb/lib/selenium/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,29 +89,7 @@ def download(required_version = :latest)
redirected = URI.parse released.header['location']

File.open(download_file_name, 'wb') do |destination|
net_http_start('github-releases.githubusercontent.com') do |http|
request = Net::HTTP::Get.new redirected
resp = http.request(request) do |response|
total = response.content_length
progress = 0
segment_count = 0

response.read_body do |segment|
progress += segment.length
segment_count += 1

if (segment_count % 15).zero?
percent = progress.fdiv(total) * 100
print "#{CL_RESET}Downloading #{download_file_name}: #{percent.to_i}% (#{progress} / #{total})"
segment_count = 0
end

destination.write(segment)
end
end

raise Error, "#{resp.code} for #{download_file_name}" unless resp.is_a? Net::HTTPSuccess
end
download_server(redirected, destination)
end
rescue StandardError
FileUtils.rm download_file_name if File.exist? download_file_name
Expand All @@ -129,13 +107,9 @@ def latest
@latest ||= begin
net_http_start('api.github.com') do |http|
json = http.get('/repos/seleniumhq/selenium/releases').body
JSON.parse(json).map { |release|
release['assets']
}.flatten.map { |asset|
asset['name'][/selenium-server-(\d+\.\d+\.\d+)\.jar/, 1]
}.compact.map { |version|
Gem::Version.new(version)
}.max.version
all_assets = JSON.parse(json).map { |release| release['assets'] }.flatten
server_assets = all_assets.map { |asset| asset['name'][/selenium-server-(\d+\.\d+\.\d+)\.jar/, 1] }.compact
server_assets.map { |version| Gem::Version.new(version) }.max.version
end
end
end
Expand All @@ -153,6 +127,32 @@ def net_http_start(address, &block)
Net::HTTP.start(address, use_ssl: true, &block)
end
end

def download_server(uri, destination)
net_http_start('github-releases.githubusercontent.com') do |http|
request = Net::HTTP::Get.new uri
resp = http.request(request) do |response|
total = response.content_length
progress = 0
segment_count = 0

response.read_body do |segment|
progress += segment.length
segment_count += 1

if (segment_count % 15).zero?
percent = progress.fdiv(total) * 100
print "#{CL_RESET}Downloading #{download_file_name}: #{percent.to_i}% (#{progress} / #{total})"
segment_count = 0
end

destination.write(segment)
end
end

raise Error, "#{resp.code} for #{download_file_name}" unless resp.is_a? Net::HTTPSuccess
end
end
end

#
Expand Down

0 comments on commit 89b7491

Please sign in to comment.