mirror of
https://github.com/chromebrew/chromebrew.git
synced 2026-01-09 15:37:56 -05:00
Add lib/package_utils.rb to provide a number of package convenience functions. (#9617)
This commit is contained in:
committed by
GitHub
parent
f2fae48a7f
commit
8b19dcd05a
33
lib/package_utils.rb
Normal file
33
lib/package_utils.rb
Normal file
@@ -0,0 +1,33 @@
|
||||
require 'json'
|
||||
require_relative 'const'
|
||||
|
||||
class PackageUtils
|
||||
def self.installed?(pkg_name)
|
||||
device_json = JSON.load_file(File.join(CREW_CONFIG_PATH, 'device.json'))
|
||||
return device_json['installed_packages'].any? { |elem| elem['name'] == pkg_name }
|
||||
end
|
||||
|
||||
def self.compatible?(pkg)
|
||||
return pkg.compatibility.casecmp?('all') || pkg.compatibility.include?(ARCH)
|
||||
end
|
||||
|
||||
def self.get_url(pkg, build_from_source: false)
|
||||
if !build_from_source && pkg.binary_sha256&.key?(ARCH.to_sym)
|
||||
return "https://gitlab.com/api/v4/projects/26210301/packages/generic/#{pkg.name}/#{pkg.version}_#{ARCH}/#{pkg.name}-#{pkg.version}-chromeos-#{ARCH}.#{pkg.binary_compression}"
|
||||
elsif pkg.source_url.is_a?(Hash) && pkg.source_url&.key?(ARCH.to_sym)
|
||||
return pkg.source_url[ARCH.to_sym]
|
||||
else
|
||||
return pkg.source_url
|
||||
end
|
||||
end
|
||||
|
||||
def self.get_sha256(pkg, build_from_source: false)
|
||||
if !build_from_source && pkg.binary_sha256&.key?(ARCH.to_sym)
|
||||
return pkg.binary_sha256[ARCH.to_sym]
|
||||
elsif pkg.source_sha256.is_a?(Hash) && pkg.source_sha256&.key?(ARCH.to_sym)
|
||||
return pkg.source_sha256[ARCH.to_sym]
|
||||
else
|
||||
return pkg.source_sha256
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user