Class: Y2Packager::Package
- Inherits:
-
Object
- Object
- Y2Packager::Package
- Includes:
- Yast::Logger
- Defined in:
- library/packages/src/lib/y2packager/package.rb
Overview
This class represents a libzypp package and it offers an API to common operations.
The idea is extending this class with new methods when needed.
Instance Attribute Summary collapse
-
#name ⇒ String
readonly
Package name.
-
#repo_id ⇒ Integer
readonly
Id of the repository where the package lives.
-
#version ⇒ String
readonly
Package version.
Class Method Summary collapse
-
.find(name) ⇒ Array<Package>?
Find packages by name.
-
.last_version(name, statuses: [:available, :selected]) ⇒ Y2Packager::Package?
Find the highest version of requested package with given statuses.
Instance Method Summary collapse
-
#download_to(path) ⇒ Object
Download a package to the given path.
-
#extract_to(directory) ⇒ Object
Download and extract the package to the given directory.
-
#initialize(name, repo_id, version) ⇒ Package
constructor
Constructor.
-
#status ⇒ Symbol
Return package status.
Constructor Details
#initialize(name, repo_id, version) ⇒ Package
Constructor
73 74 75 76 77 |
# File 'library/packages/src/lib/y2packager/package.rb', line 73 def initialize(name, repo_id, version) @name = name @repo_id = repo_id @version = version end |
Instance Attribute Details
#name ⇒ String (readonly)
Returns Package name.
30 31 32 |
# File 'library/packages/src/lib/y2packager/package.rb', line 30 def name @name end |
#repo_id ⇒ Integer (readonly)
Returns Id of the repository where the package lives.
32 33 34 |
# File 'library/packages/src/lib/y2packager/package.rb', line 32 def repo_id @repo_id end |
#version ⇒ String (readonly)
Returns Package version.
34 35 36 |
# File 'library/packages/src/lib/y2packager/package.rb', line 34 def version @version end |
Class Method Details
.find(name) ⇒ Array<Package>?
Find packages by name
42 43 44 45 46 47 48 49 |
# File 'library/packages/src/lib/y2packager/package.rb', line 42 def find(name) resolvables = Yast::Pkg.Resolvables({ kind: :package, name: name }, [:name, :source, :version]) return nil if resolvables.nil? resolvables.map { |i| new(i["name"], i["source"], i["version"]) } end |
.last_version(name, statuses: [:available, :selected]) ⇒ Y2Packager::Package?
Find the highest version of requested package with given statuses
57 58 59 60 61 62 63 64 65 |
# File 'library/packages/src/lib/y2packager/package.rb', line 57 def last_version(name, statuses: [:available, :selected]) packages = find(name) return nil unless packages packages .select { |i| statuses.include?(i.status) } .max { |a, b| Yast::Pkg.CompareVersions(a.version, b.version) } end |
Instance Method Details
#download_to(path) ⇒ Object
Download a package to the given path
106 107 108 109 |
# File 'library/packages/src/lib/y2packager/package.rb', line 106 def download_to(path) downloader = Packages::PackageDownloader.new(repo_id, name) downloader.download(path.to_s) end |
#extract_to(directory) ⇒ Object
Download and extract the package to the given directory
117 118 119 120 121 122 123 124 125 |
# File 'library/packages/src/lib/y2packager/package.rb', line 117 def extract_to(directory) tmpfile = Tempfile.new("downloaded-package-#{name}-") download_to(tmpfile.path) extractor = Packages::PackageExtractor.new(tmpfile.path) extractor.extract(directory.to_s) ensure tmpfile.close tmpfile.unlink end |
#status ⇒ Symbol
Return package status
Ask libzypp about package status.
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'library/packages/src/lib/y2packager/package.rb', line 85 def status resolvables = Yast::Pkg.Resolvables({ kind: :package, name: name, version: version, source: repo_id }, [:status]) log.warn "Found multiple resolvables: #{resolvables}" if resolvables.size > 1 resolvable = resolvables.first if !resolvable log.warn "Resolvable not found: #{name}-#{version} from repo #{repo_id}" return nil end resolvable["status"] end |