Add lib/package_utils.rb to provide a number of package convenience functions. (#9617)

This commit is contained in:
Maximilian Downey Twiss
2024-04-11 04:00:04 +10:00
committed by GitHub
parent f2fae48a7f
commit 8b19dcd05a
10 changed files with 193 additions and 72 deletions

View File

@@ -1,12 +1,11 @@
require 'json'
require_relative '../lib/const'
require_relative '../lib/convert_size'
require_relative '../lib/package_utils'
class Command
def self.files(pkg)
# Check if the package is even installed first, as this is the most likely reason we cannot find a filelist.
device_json = JSON.load_file(File.join(CREW_CONFIG_PATH, 'device.json'))
if device_json['installed_packages'].none? { |entry| entry['name'] == pkg.name }
unless PackageUtils.installed?(pkg.name)
puts "Package #{pkg.name} is not installed.".lightred
return
end

View File

@@ -3,6 +3,7 @@ require 'json'
require_relative '../lib/color'
require_relative '../lib/const'
require_relative '../lib/package'
require_relative '../lib/package_utils'
class Command
def self.list(available, installed, compatible, incompatible, verbose)
@@ -17,7 +18,7 @@ class Command
pkg_name = File.basename(filename, '.rb')
next if installed_packages.key?(pkg_name)
pkg = Package.load_package(filename)
puts pkg_name if pkg.compatible?
puts pkg_name if PackageUtils.compatible?(pkg)
end
elsif installed
if verbose
@@ -36,14 +37,14 @@ class Command
Dir["#{CREW_PACKAGES_PATH}/*.rb"].each do |filename|
pkg_name = File.basename(filename, '.rb')
pkg = Package.load_package(filename)
puts pkg_name.lightgreen if pkg.compatible? && installed_packages.key?(pkg_name)
puts pkg_name if pkg.compatible?
puts pkg_name.lightgreen if PackageUtils.compatible?(pkg) && installed_packages.key?(pkg_name)
puts pkg_name if PackageUtils.compatible?(pkg)
end
elsif incompatible
Dir["#{CREW_PACKAGES_PATH}/*.rb"].each do |filename|
pkg_name = File.basename(filename, '.rb')
pkg = Package.load_package(filename)
puts pkg_name.lightred unless pkg.compatible?
puts pkg_name.lightred unless PackageUtils.compatible?(pkg)
end
end
end

View File

@@ -1,13 +1,14 @@
require 'fileutils'
require 'json'
require_relative '../lib/const'
require_relative '../lib/package_utils'
class Command
def self.remove(pkg, verbose)
device_json = JSON.load_file(File.join(CREW_CONFIG_PATH, 'device.json'))
# Make sure the package is actually installed before we attempt to remove it.
if device_json['installed_packages'].none? { |entry| entry['name'] == pkg.name }
unless PackageUtils.installed?(pkg.name)
puts "Package #{pkg.name} isn't installed.".lightred
return
end