Cleanup internal API handling
This commit is contained in:
parent
dbe68ef80c
commit
97d299728d
@ -162,6 +162,20 @@ module Homebrew
|
|||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { params(aliases: T::Hash[String, String], type: String, regenerate: T::Boolean).returns(T::Boolean) }
|
||||||
|
def self.write_aliases_file!(aliases, type, regenerate:)
|
||||||
|
aliases_path = HOMEBREW_CACHE_API/"#{type}_aliases.txt"
|
||||||
|
if !aliases_path.exist? || regenerate
|
||||||
|
aliases_text = aliases.map do |alias_name, real_name|
|
||||||
|
"#{alias_name}|#{real_name}"
|
||||||
|
end
|
||||||
|
aliases_path.write(aliases_text.join("\n"))
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
false
|
||||||
|
end
|
||||||
|
|
||||||
sig {
|
sig {
|
||||||
params(json_data: T::Hash[String, T.untyped])
|
params(json_data: T::Hash[String, T.untyped])
|
||||||
.returns([T::Boolean, T.any(String, T::Array[T.untyped], T::Hash[String, T.untyped])])
|
.returns([T::Boolean, T.any(String, T::Array[T.untyped], T::Hash[String, T.untyped])])
|
||||||
|
|||||||
@ -14,13 +14,6 @@ module Homebrew
|
|||||||
|
|
||||||
DEFAULT_API_FILENAME = "cask.jws.json"
|
DEFAULT_API_FILENAME = "cask.jws.json"
|
||||||
|
|
||||||
sig { returns(String) }
|
|
||||||
def self.api_filename
|
|
||||||
return DEFAULT_API_FILENAME unless ENV.fetch("HOMEBREW_USE_INTERNAL_API", false)
|
|
||||||
|
|
||||||
"cask.#{SimulateSystem.current_tag}.jws.json"
|
|
||||||
end
|
|
||||||
|
|
||||||
private_class_method :cache
|
private_class_method :cache
|
||||||
|
|
||||||
sig { params(token: String).returns(T::Hash[String, T.untyped]) }
|
sig { params(token: String).returns(T::Hash[String, T.untyped]) }
|
||||||
@ -64,7 +57,7 @@ module Homebrew
|
|||||||
|
|
||||||
sig { returns(Pathname) }
|
sig { returns(Pathname) }
|
||||||
def self.cached_json_file_path
|
def self.cached_json_file_path
|
||||||
HOMEBREW_CACHE_API/api_filename
|
HOMEBREW_CACHE_API/DEFAULT_API_FILENAME
|
||||||
end
|
end
|
||||||
|
|
||||||
sig {
|
sig {
|
||||||
@ -72,7 +65,7 @@ module Homebrew
|
|||||||
.returns([T.any(T::Array[T.untyped], T::Hash[String, T.untyped]), T::Boolean])
|
.returns([T.any(T::Array[T.untyped], T::Hash[String, T.untyped]), T::Boolean])
|
||||||
}
|
}
|
||||||
def self.fetch_api!(download_queue: nil, stale_seconds: Homebrew::EnvConfig.api_auto_update_secs.to_i)
|
def self.fetch_api!(download_queue: nil, stale_seconds: Homebrew::EnvConfig.api_auto_update_secs.to_i)
|
||||||
Homebrew::API.fetch_json_api_file api_filename, stale_seconds:, download_queue:
|
Homebrew::API.fetch_json_api_file DEFAULT_API_FILENAME, stale_seconds:, download_queue:
|
||||||
end
|
end
|
||||||
|
|
||||||
sig {
|
sig {
|
||||||
|
|||||||
@ -14,13 +14,6 @@ module Homebrew
|
|||||||
|
|
||||||
DEFAULT_API_FILENAME = "formula.jws.json"
|
DEFAULT_API_FILENAME = "formula.jws.json"
|
||||||
|
|
||||||
sig { returns(String) }
|
|
||||||
def self.api_filename
|
|
||||||
return DEFAULT_API_FILENAME unless ENV.fetch("HOMEBREW_USE_INTERNAL_API", false)
|
|
||||||
|
|
||||||
"internal/formula.#{SimulateSystem.current_tag}.jws.json"
|
|
||||||
end
|
|
||||||
|
|
||||||
private_class_method :cache
|
private_class_method :cache
|
||||||
|
|
||||||
sig { params(name: String).returns(T::Hash[String, T.untyped]) }
|
sig { params(name: String).returns(T::Hash[String, T.untyped]) }
|
||||||
@ -63,7 +56,7 @@ module Homebrew
|
|||||||
|
|
||||||
sig { returns(Pathname) }
|
sig { returns(Pathname) }
|
||||||
def self.cached_json_file_path
|
def self.cached_json_file_path
|
||||||
HOMEBREW_CACHE_API/api_filename
|
HOMEBREW_CACHE_API/DEFAULT_API_FILENAME
|
||||||
end
|
end
|
||||||
|
|
||||||
sig {
|
sig {
|
||||||
@ -71,7 +64,7 @@ module Homebrew
|
|||||||
.returns([T.any(T::Array[T.untyped], T::Hash[String, T.untyped]), T::Boolean])
|
.returns([T.any(T::Array[T.untyped], T::Hash[String, T.untyped]), T::Boolean])
|
||||||
}
|
}
|
||||||
def self.fetch_api!(download_queue: nil, stale_seconds: Homebrew::EnvConfig.api_auto_update_secs.to_i)
|
def self.fetch_api!(download_queue: nil, stale_seconds: Homebrew::EnvConfig.api_auto_update_secs.to_i)
|
||||||
Homebrew::API.fetch_json_api_file api_filename, stale_seconds:, download_queue:
|
Homebrew::API.fetch_json_api_file DEFAULT_API_FILENAME, stale_seconds:, download_queue:
|
||||||
end
|
end
|
||||||
|
|
||||||
sig {
|
sig {
|
||||||
@ -147,13 +140,8 @@ module Homebrew
|
|||||||
def self.write_names_and_aliases(regenerate: false)
|
def self.write_names_and_aliases(regenerate: false)
|
||||||
download_and_cache_data! unless cache.key?("formulae")
|
download_and_cache_data! unless cache.key?("formulae")
|
||||||
|
|
||||||
return unless Homebrew::API.write_names_file!(all_formulae.keys, "formula", regenerate:)
|
Homebrew::API.write_names_file!(all_formulae.keys, "formula", regenerate:)
|
||||||
|
Homebrew::API.write_aliases_file!(all_aliases, "formula", regenerate:)
|
||||||
(HOMEBREW_CACHE_API/"formula_aliases.txt").open("w") do |file|
|
|
||||||
all_aliases.each do |alias_name, real_name|
|
|
||||||
file.puts "#{alias_name}|#{real_name}"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user