Class: GithubBottle

Inherits:
Object
  • Object
show all
Defined in:
lib/homebrew/github/bottles.rb

Defined Under Namespace

Classes: Error

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project_basepath, authorization = nil) ⇒ GithubBottle

Returns a new instance of GithubBottle.



25
26
27
28
29
30
31
32
33
# File 'lib/homebrew/github/bottles.rb', line 25

def initialize(project_basepath, authorization=nil)
  @authorization = authorization
  @project_basepath = project_basepath
  @project_basepath << "/" unless project_basepath.end_with?("/")

  @has_checked_bottle = false
  @has_bottle = false
  @bottle_asset_id = -1
end

Instance Attribute Details

#bottle_asset_idObject

Returns the value of attribute bottle_asset_id.



37
38
39
# File 'lib/homebrew/github/bottles.rb', line 37

def bottle_asset_id
  @bottle_asset_id
end

#project_basepathObject

Returns the value of attribute project_basepath.



36
37
38
# File 'lib/homebrew/github/bottles.rb', line 36

def project_basepath
  @project_basepath
end

#release_uriObject

Returns the value of attribute release_uri.



35
36
37
# File 'lib/homebrew/github/bottles.rb', line 35

def release_uri
  @release_uri
end

Instance Method Details

#bottled?(formula) ⇒ Boolean

Returns:

  • (Boolean)


88
89
90
91
92
93
94
95
96
# File 'lib/homebrew/github/bottles.rb', line 88

def bottled?(formula)
  if @has_checked_bottle
    return @has_bottle
  end

  @has_checked_bottle = true
  @has_bottle = inner_bottled?(formula)
  return @has_bottle
end

#file_pattern(formula) ⇒ Object



39
40
41
42
# File 'lib/homebrew/github/bottles.rb', line 39

def file_pattern(formula)
  # bottle_tag is defined in bottles, required above
  "#{formula.name}-#{formula.pkg_version}.#{bottle_tag}.bottle.tar.gz"
end

#pour(cache_root, formula) ⇒ Object



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/homebrew/github/bottles.rb', line 98

def pour(cache_root, formula)
  asset_uri = URI(@project_basepath + "releases/assets/#{@bottle_asset_id}")

  here_cache = (cache_root/formula.name)
  here_cache.mkpath
  file = file_pattern formula
  cache_file = here_cache/file

  ohai "brew-github-bottles: Downloading #{asset_uri}"

  # Get the asset from github
  req = Net::HTTP::Get.new(asset_uri)

  unless @authorization.nil?
    req["Authorization"] = @authorization
  end

  req["Accept"] = "application/octet-stream"

  res = send_request(asset_uri, req)

  data = ""
  begin
    case res
      when Net::HTTPSuccess then
        data = res.body
      when Net::HTTPRedirection then
        # Follow the redirect, which already includes the credentials
        res = Net::HTTP.get_response(URI(res['location']))
        unless Net::HTTPOK === res
          raise
        end
        data = res.body
      else
        raise
    end
  rescue StandardError => e
    raise Error, "brew-github-bottles: Failed to download resource \"#{formula.name}\" - (#{e.message})"
  end

  open cache_file, "w" do |io|
    io.write data
  end

  bottle_install_dir = formula.prefix
  bottle_install_dir.mkpath

  ohai "brew-github-bottles: Pouring #{file} to #{bottle_install_dir}"

  # TODO: Use Minitar instead?
  system "tar", "-xf", cache_file.to_s, "-C", bottle_install_dir.to_s, "--strip-components=2"
  true
end