Class: Y2Packager::Product
- Inherits:
-
Object
- Object
- Y2Packager::Product
- Includes:
- ProductLicenseMixin, Yast::Logger
- Defined in:
- library/packages/src/lib/y2packager/product.rb
Overview
Represent a product which is present in a repository. At this time this class is responsible for finding out whether two products instances are the same (for example, coming from different repositories).
Constant Summary collapse
- PKG_BINDINGS_ATTRS =
["name", "short_name", "display_name", "version", "arch", "category", "vendor"].freeze
Constants included from ProductLicenseMixin
Y2Packager::ProductLicenseMixin::DEFAULT_LICENSE_LANG
Instance Attribute Summary collapse
-
#arch ⇒ String
readonly
Architecture.
-
#category ⇒ Symbol
readonly
Category.
-
#display_name ⇒ String
readonly
Display name.
-
#installation_package ⇒ String
readonly
Package including installation.xml for install on top of lean os.
-
#installation_package_repo ⇒ Integer
readonly
Repository for the installation_package.
-
#name ⇒ String
readonly
Name.
-
#order ⇒ Integer
readonly
Display order.
-
#register_target ⇒ String
readonly
Registration target name used for registering the product.
-
#short_name ⇒ String
readonly
Short name.
-
#vendor ⇒ String
readonly
Vendor.
-
#version ⇒ String
readonly
Version.
Class Method Summary collapse
-
.all ⇒ Array<Product>
Return all known available products.
-
.available_base_products ⇒ Array<Product>
Return available base products.
-
.from_h(product) ⇒ Y2Packager::Product
Create a product from pkg-bindings hash data.
-
.from_resolvable(product, installation_package = "", displayorder = nil) ⇒ Y2Packager::Product
Create a product from Y2Packager::Resolvable.
-
.installed_base_product ⇒ Product?
Return the installed base product.
-
.installed_products ⇒ Product?
Return all installed products (including the base product).
-
.reset ⇒ true
Resets cached attributes of the class.
-
.selected_base ⇒ Product
Returns the selected base product.
-
.with_status(*statuses) ⇒ Array<Product>
Return the products with a given status.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Compare two different products.
-
#initialize(name: nil, short_name: nil, display_name: nil, version: nil, arch: nil, category: nil, vendor: nil, order: nil, installation_package: nil, register_target: "") ⇒ Product
constructor
Constructor.
-
#installed? ⇒ Boolean
is the product selected to install?.
-
#label ⇒ String
Return a package label.
-
#release_notes(user_lang, format = :txt) ⇒ ReleaseNotes
Return product's release notes.
-
#relnotes_url ⇒ String?
Return release notes URL.
-
#resolvable_properties ⇒ Hash
Return product's resolvable properties.
-
#restore ⇒ Object
Restore the status of a product.
-
#select ⇒ Boolean
select the product to install.
-
#selected? ⇒ Boolean
is the product selected to install?.
-
#status?(*statuses) ⇒ Boolean
Determine whether a product is in a given status.
-
#version_version ⇒ String
Returns the version number (without the release part).
Methods included from ProductLicenseMixin
#license, #license?, #license_confirmation=, #license_confirmation_required?, #license_confirmed?, #license_content, #license_locales
Constructor Details
#initialize(name: nil, short_name: nil, display_name: nil, version: nil, arch: nil, category: nil, vendor: nil, order: nil, installation_package: nil, register_target: "") ⇒ Product
Constructor
148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'library/packages/src/lib/y2packager/product.rb', line 148 def initialize(name: nil, short_name: nil, display_name: nil, version: nil, arch: nil, category: nil, vendor: nil, order: nil, installation_package: nil, register_target: "") @name = name @short_name = short_name @display_name = display_name @version = version @arch = arch.to_sym if arch @category = category.to_sym if category @vendor = vendor @order = order @installation_package = installation_package @register_target = register_target end |
Instance Attribute Details
#arch ⇒ String (readonly)
Returns Architecture.
37 38 39 |
# File 'library/packages/src/lib/y2packager/product.rb', line 37 def arch @arch end |
#category ⇒ Symbol (readonly)
Returns Category.
39 40 41 |
# File 'library/packages/src/lib/y2packager/product.rb', line 39 def category @category end |
#display_name ⇒ String (readonly)
Returns Display name.
33 34 35 |
# File 'library/packages/src/lib/y2packager/product.rb', line 33 def display_name @display_name end |
#installation_package ⇒ String (readonly)
Returns package including installation.xml for install on top of lean os.
45 46 47 |
# File 'library/packages/src/lib/y2packager/product.rb', line 45 def installation_package @installation_package end |
#installation_package_repo ⇒ Integer (readonly)
Returns repository for the installation_package.
47 48 49 |
# File 'library/packages/src/lib/y2packager/product.rb', line 47 def installation_package_repo @installation_package_repo end |
#name ⇒ String (readonly)
Returns Name.
29 30 31 |
# File 'library/packages/src/lib/y2packager/product.rb', line 29 def name @name end |
#order ⇒ Integer (readonly)
Returns Display order.
43 44 45 |
# File 'library/packages/src/lib/y2packager/product.rb', line 43 def order @order end |
#register_target ⇒ String (readonly)
Returns Registration target name used for registering the product.
49 50 51 |
# File 'library/packages/src/lib/y2packager/product.rb', line 49 def register_target @register_target end |
#short_name ⇒ String (readonly)
Returns Short name.
31 32 33 |
# File 'library/packages/src/lib/y2packager/product.rb', line 31 def short_name @short_name end |
#vendor ⇒ String (readonly)
Returns Vendor.
41 42 43 |
# File 'library/packages/src/lib/y2packager/product.rb', line 41 def vendor @vendor end |
#version ⇒ String (readonly)
Returns Version.
35 36 37 |
# File 'library/packages/src/lib/y2packager/product.rb', line 35 def version @version end |
Class Method Details
.all ⇒ Array<Product>
Return all known available products
90 91 92 |
# File 'library/packages/src/lib/y2packager/product.rb', line 90 def all Y2Packager::ProductReader.new.all_products end |
.available_base_products ⇒ Array<Product>
Return available base products
97 98 99 |
# File 'library/packages/src/lib/y2packager/product.rb', line 97 def available_base_products Y2Packager::ProductReader.new.available_base_products end |
.from_h(product) ⇒ Y2Packager::Product
Create a product from pkg-bindings hash data.
65 66 67 68 |
# File 'library/packages/src/lib/y2packager/product.rb', line 65 def from_h(product) params = PKG_BINDINGS_ATTRS.each_with_object({}) { |a, h| h[a.to_sym] = product[a] } Y2Packager::Product.new(**params) end |
.from_resolvable(product, installation_package = "", displayorder = nil) ⇒ Y2Packager::Product
Create a product from Y2Packager::Resolvable
75 76 77 78 79 80 81 82 83 84 85 |
# File 'library/packages/src/lib/y2packager/product.rb', line 75 def from_resolvable(product, installation_package = "", displayorder = nil) Y2Packager::Product.new( name: product.name, short_name: product.short_name, display_name: product.display_name, version: product.version, arch: product.arch, category: product.category, vendor: product.vendor, order: displayorder, register_target: product.register_target, installation_package: installation_package ) end |
.installed_base_product ⇒ Product?
Return the installed base product
104 105 106 |
# File 'library/packages/src/lib/y2packager/product.rb', line 104 def installed_base_product Y2Packager::ProductReader.new.installed_base_product end |
.installed_products ⇒ Product?
Return all installed products (including the base product)
111 112 113 |
# File 'library/packages/src/lib/y2packager/product.rb', line 111 def installed_products Y2Packager::ProductReader.new.all_installed_products end |
.reset ⇒ true
Resets cached attributes of the class
58 59 60 |
# File 'library/packages/src/lib/y2packager/product.rb', line 58 def reset @forced_base_product = nil end |
.selected_base ⇒ Product
Returns the selected base product
It assumes that at most 1 base product can be selected.
120 121 122 123 124 125 |
# File 'library/packages/src/lib/y2packager/product.rb', line 120 def selected_base products = Y2Packager::ProductReader.new.available_base_products(force_repos: true) selected = products.find(&:selected?) selected ||= products.first selected end |
.with_status(*statuses) ⇒ Array<Product>
Return the products with a given status
131 132 133 |
# File 'library/packages/src/lib/y2packager/product.rb', line 131 def with_status(*statuses) all.select { |p| p.status?(*statuses) } end |
Instance Method Details
#==(other) ⇒ Boolean
Compare two different products
If arch, name, version and vendor match they are considered the same product.
168 169 170 171 172 173 174 175 |
# File 'library/packages/src/lib/y2packager/product.rb', line 168 def ==(other) result = arch == other.arch && name == other.name && version == other.version && vendor == other.vendor log.info("Comparing products: '#{arch}' <=> '#{other.arch}', '#{name}' <=> '#{other.name}', "\ "'#{version}' <=> '#{other.version}', '#{vendor}' <=> '#{other.vendor}' => "\ "result: #{result}") result end |
#installed? ⇒ Boolean
is the product selected to install?
Only the 'name' will be used to find out whether the product is installed, ignoring the architecture, version, vendor or any other property. libzypp will take care of finding the proper product.
196 197 198 |
# File 'library/packages/src/lib/y2packager/product.rb', line 196 def installed? status?(:installed) end |
#label ⇒ String
Return a package label
It will use 'display_name', 'short_name' or 'name'.
228 229 230 |
# File 'library/packages/src/lib/y2packager/product.rb', line 228 def label display_name || short_name || name end |
#release_notes(user_lang, format = :txt) ⇒ ReleaseNotes
Return product's release notes
239 240 241 |
# File 'library/packages/src/lib/y2packager/product.rb', line 239 def release_notes(user_lang, format = :txt) ReleaseNotesReader.new(self).release_notes(user_lang: user_lang, format: format) end |
#relnotes_url ⇒ String?
Return release notes URL
Release notes might not be defined in libzypp and this method returns the URL to get release notes from.
249 250 251 252 253 254 |
# File 'library/packages/src/lib/y2packager/product.rb', line 249 def relnotes_url return nil unless resolvable_properties url = resolvable_properties.relnotes_url url.empty? ? nil : url end |
#resolvable_properties ⇒ Hash
Return product's resolvable properties
Only the 'name' and 'version' will be used to find out the product properties, ignoring the architecture, vendor or any other property. libzypp will take care of finding the proper product.
277 278 279 |
# File 'library/packages/src/lib/y2packager/product.rb', line 277 def resolvable_properties @resolvable_properties ||= Y2Packager::Resolvable.find(kind: :product, name: name, version: version).first end |
#restore ⇒ Object
Restore the status of a product
Only the 'name' will be used to restore the product status, ignoring the architecture, version, vendor or any other property. libzypp will take care of modifying the proper product.
218 219 220 221 |
# File 'library/packages/src/lib/y2packager/product.rb', line 218 def restore log.info "Restoring product #{name} status" Yast::Pkg.ResolvableNeutral(name, :product, true) end |
#select ⇒ Boolean
select the product to install
Only the 'name' will be used to select the product, ignoring the architecture, version, vendor or any other property. libzypp will take care of selecting the proper product.
207 208 209 210 |
# File 'library/packages/src/lib/y2packager/product.rb', line 207 def select log.info "Selecting product #{name} to install" Yast::Pkg.ResolvableInstall(name, :product, "") end |
#selected? ⇒ Boolean
is the product selected to install?
Only the 'name' will be used to find out whether the product is selected, ignoring the architecture, version, vendor or any other property. libzypp will take care of finding the proper product.
184 185 186 |
# File 'library/packages/src/lib/y2packager/product.rb', line 184 def selected? status?(:selected) end |
#status?(*statuses) ⇒ Boolean
Determine whether a product is in a given status
Only the 'name' will be used to find out whether the product status, ignoring the architecture, version, vendor or any other property. libzypp will take care of finding the proper product.
264 265 266 267 268 |
# File 'library/packages/src/lib/y2packager/product.rb', line 264 def status?(*statuses) Y2Packager::Resolvable.find(kind: :product, name: name).any? do |res| statuses.include?(res.status) end end |
#version_version ⇒ String
Returns the version number (without the release part)
284 285 286 |
# File 'library/packages/src/lib/y2packager/product.rb', line 284 def version_version version.split("-").first end |