Navigation Menu

Skip to content

Commit

Permalink
Fix indent level
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Jan 6, 2015
1 parent ba429a2 commit b610cf0
Showing 1 changed file with 75 additions and 75 deletions.
150 changes: 75 additions & 75 deletions lib/droonga/serf/downloader.rb
Expand Up @@ -26,92 +26,92 @@
module Droonga
class Serf
class Downloader
include Loggable
include Loggable

class DownloadFailed < StandardError
end

MAX_RETRY_COUNT = 5
RETRY_INTERVAL = 10
class DownloadFailed < StandardError
end

def initialize(output_path)
@output_path = output_path
@retry_count = 0
end
MAX_RETRY_COUNT = 5
RETRY_INTERVAL = 10

def download
detect_platform
version = "0.6.3"
url_base = "https://dl.bintray.com/mitchellh/serf"
base_name = "#{version}_#{@os}_#{@architecture}.zip"
connection = Faraday.new(url_base) do |builder|
builder.response(:follow_redirects)
builder.adapter(Faraday.default_adapter)
def initialize(output_path)
@output_path = output_path
@retry_count = 0
end
response = connection.get(base_name)
absolete_output_path = @output_path.expand_path
Dir.mktmpdir do |dir|
Archive::Zip.extract(StringIO.new(response.body),
dir,
:directories => false)
FileUtils.mv("#{dir}/serf", absolete_output_path.to_s)
FileUtils.chmod(0755, absolete_output_path.to_s)
end
rescue Archive::Zip::UnzipError => archive_error
logger.warn("Downloaded zip file is broken.")
if @retry_count < MAX_RETRY_COUNT
@retry_count += 1
sleep(RETRY_INTERVAL * @retry_count)
download
else
raise DownloadFailed.new("Couldn't download serf executable. Try it later.")
end
rescue Faraday::ConnectionFailed => network_error
logger.warn("Connection failed.")
if @retry_count < MAX_RETRY_COUNT
@retry_count += 1
sleep(RETRY_INTERVAL * @retry_count)
download
else
raise DownloadFailed.new("Couldn't download serf executable. Try it later.")

def download
detect_platform
version = "0.6.3"
url_base = "https://dl.bintray.com/mitchellh/serf"
base_name = "#{version}_#{@os}_#{@architecture}.zip"
connection = Faraday.new(url_base) do |builder|
builder.response(:follow_redirects)
builder.adapter(Faraday.default_adapter)
end
response = connection.get(base_name)
absolete_output_path = @output_path.expand_path
Dir.mktmpdir do |dir|
Archive::Zip.extract(StringIO.new(response.body),
dir,
:directories => false)
FileUtils.mv("#{dir}/serf", absolete_output_path.to_s)
FileUtils.chmod(0755, absolete_output_path.to_s)
end
rescue Archive::Zip::UnzipError => archive_error
logger.warn("Downloaded zip file is broken.")
if @retry_count < MAX_RETRY_COUNT
@retry_count += 1
sleep(RETRY_INTERVAL * @retry_count)
download
else
raise DownloadFailed.new("Couldn't download serf executable. Try it later.")
end
rescue Faraday::ConnectionFailed => network_error
logger.warn("Connection failed.")
if @retry_count < MAX_RETRY_COUNT
@retry_count += 1
sleep(RETRY_INTERVAL * @retry_count)
download
else
raise DownloadFailed.new("Couldn't download serf executable. Try it later.")
end
end
end

private
def detect_platform
detect_os
detect_architecture
end
private
def detect_platform
detect_os
detect_architecture
end

def detect_os
case RUBY_PLATFORM
when /linux/
@os = "linux"
when /freebsd/
@os = "freebsd"
when /darwin/
@os = "darwin"
when /mswin|mingw/
@os = "windows"
else
raise "Unsupported OS: #{RUBY_PLATFORM}"
def detect_os
case RUBY_PLATFORM
when /linux/
@os = "linux"
when /freebsd/
@os = "freebsd"
when /darwin/
@os = "darwin"
when /mswin|mingw/
@os = "windows"
else
raise "Unsupported OS: #{RUBY_PLATFORM}"
end
end
end

def detect_architecture
case RUBY_PLATFORM
when /x86_64|x64/
@architecture = "amd64"
when /i\d86/
@architecture = "386"
else
raise "Unsupported architecture: #{RUBY_PLATFORM}"
def detect_architecture
case RUBY_PLATFORM
when /x86_64|x64/
@architecture = "amd64"
when /i\d86/
@architecture = "386"
else
raise "Unsupported architecture: #{RUBY_PLATFORM}"
end
end
end

def log_tag
"serf-downloader"
end
def log_tag
"serf-downloader"
end
end
end
endi

0 comments on commit b610cf0

Please sign in to comment.