Class: Y2Packager::Product

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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) ⇒ Product

Constructor

Parameters:

  • name (String) (defaults to: nil)

    Name

  • short_name (String) (defaults to: nil)

    Short name

  • display_name (String) (defaults to: nil)

    Display name

  • version (String) (defaults to: nil)

    Version

  • arch (String) (defaults to: nil)

    Architecture

  • category (Symbol) (defaults to: nil)

    Category (:base, :addon)

  • vendor (String) (defaults to: nil)

    Vendor

  • order (Integer) (defaults to: nil)

    Display order

  • installation_package (String) (defaults to: nil)

    Installation package name


176
177
178
179
180
181
182
183
184
185
186
187
# File 'library/packages/src/lib/y2packager/product.rb', line 176

def initialize(name: nil, short_name: nil, display_name: nil, version: nil, arch: nil,
  category: nil, vendor: nil, order: nil, installation_package: nil)
  @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
end

Instance Attribute Details

#archString (readonly)

Returns Architecture.

Returns:

  • (String)

    Architecture


37
38
39
# File 'library/packages/src/lib/y2packager/product.rb', line 37

def arch
  @arch
end

#categorySymbol (readonly)

Returns Category.

Returns:

  • (Symbol)

    Category


39
40
41
# File 'library/packages/src/lib/y2packager/product.rb', line 39

def category
  @category
end

#display_nameString (readonly)

Returns Display name.

Returns:

  • (String)

    Display name


33
34
35
# File 'library/packages/src/lib/y2packager/product.rb', line 33

def display_name
  @display_name
end

#installation_packageString (readonly)

Returns package including installation.xml for install on top of lean os.

Returns:

  • (String)

    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_repoInteger (readonly)

Returns repository for the installation_package.

Returns:

  • (Integer)

    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

#nameString (readonly)

Returns Name.

Returns:

  • (String)

    Name


29
30
31
# File 'library/packages/src/lib/y2packager/product.rb', line 29

def name
  @name
end

#orderInteger (readonly)

Returns Display order.

Returns:

  • (Integer)

    Display order


43
44
45
# File 'library/packages/src/lib/y2packager/product.rb', line 43

def order
  @order
end

#short_nameString (readonly)

Returns Short name.

Returns:

  • (String)

    Short name


31
32
33
# File 'library/packages/src/lib/y2packager/product.rb', line 31

def short_name
  @short_name
end

#vendorString (readonly)

Returns Vendor.

Returns:

  • (String)

    Vendor


41
42
43
# File 'library/packages/src/lib/y2packager/product.rb', line 41

def vendor
  @vendor
end

#versionString (readonly)

Returns Version.

Returns:

  • (String)

    Version


35
36
37
# File 'library/packages/src/lib/y2packager/product.rb', line 35

def version
  @version
end

Class Method Details

.allArray<Product>

Return all known available products

Returns:

  • (Array<Product>)

    Known available products


99
100
101
# File 'library/packages/src/lib/y2packager/product.rb', line 99

def all
  Y2Packager::ProductReader.new.all_products
end

.available_base_productsArray<Product>

Return available base products

Returns:

  • (Array<Product>)

    Available base products


106
107
108
# File 'library/packages/src/lib/y2packager/product.rb', line 106

def available_base_products
  Y2Packager::ProductReader.new.available_base_products
end

.forced_base_productY2Packager::Product?

Returns, if any, the base product which must be selected

A base product can be forced to be selected through the select_product element in the software section of the control.xml file (bsc#1124590, bsc#1143943).

either, it wasn't selected or the selected wasn't found among the available ones.

Returns:


153
154
155
156
157
158
159
160
161
162
# File 'library/packages/src/lib/y2packager/product.rb', line 153

def forced_base_product
  Yast.import "ProductFeatures"

  return @forced_base_product if @forced_base_product

  forced_product_name = Yast::ProductFeatures.GetStringFeature("software", "select_product")
  return if forced_product_name.to_s.empty?

  @forced_base_product = available_base_products.find { |p| p.name == forced_product_name }
end

.from_h(product) ⇒ Y2Packager::Product

Create a product from pkg-bindings hash data.

Parameters:

  • product (Hash)

    the pkg-bindings product hash

Returns:


63
64
65
66
# File 'library/packages/src/lib/y2packager/product.rb', line 63

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_product_control_product(product) ⇒ Y2Packager::Product

Create a product from Y2Packager::ProductControlProduct

Parameters:

Returns:


87
88
89
90
91
92
93
94
# File 'library/packages/src/lib/y2packager/product.rb', line 87

def from_product_control_product(product)
  Y2Packager::Product.new(
    name: product.name, display_name: product.label,
    version: product.version, arch: product.arch,
    short_name: product.name,
    installation_package: ""
  )
end

.from_resolvable(product, installation_package = "", displayorder = nil) ⇒ Y2Packager::Product

Create a product from Y2Packager::Resolvable

Parameters:

  • product (Y2Packager::Resolvable)

    product

  • installation_package (String) (defaults to: "")

    installation package name

  • displayorder (Integer) (defaults to: nil)

    display order from the package provides

Returns:


73
74
75
76
77
78
79
80
81
82
# File 'library/packages/src/lib/y2packager/product.rb', line 73

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,
    installation_package: installation_package
  )
end

.installed_base_productProduct?

Return the installed base product

Returns:

  • (Product, nil)

    Installed base product or nil if not found


113
114
115
# File 'library/packages/src/lib/y2packager/product.rb', line 113

def installed_base_product
  Y2Packager::ProductReader.new.installed_base_product
end

.installed_productsProduct?

Return all installed products (including the base product)

Returns:

  • (Product, nil)

    Installed products


120
121
122
# File 'library/packages/src/lib/y2packager/product.rb', line 120

def installed_products
  Y2Packager::ProductReader.new.all_installed_products
end

.resettrue

Resets cached attributes of the class

Returns:

  • (true)

56
57
58
# File 'library/packages/src/lib/y2packager/product.rb', line 56

def reset
  @forced_base_product = nil
end

.selected_baseProduct

Returns the selected base product

It assumes that at most 1 base product can be selected.

Returns:

  • (Product)

    Selected base product


129
130
131
132
133
134
# File 'library/packages/src/lib/y2packager/product.rb', line 129

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

Parameters:

  • statuses (Array<Symbol>)

    Product status (:available, :installed, :selected, etc.)

Returns:

  • (Array<Product>)

    Products with the given status


140
141
142
# File 'library/packages/src/lib/y2packager/product.rb', line 140

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.

Returns:

  • (Boolean)

    true if both products are the same; false otherwise


195
196
197
198
199
200
201
202
# File 'library/packages/src/lib/y2packager/product.rb', line 195

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.

Returns:

  • (Boolean)

    true if it is installed

See Also:


223
224
225
# File 'library/packages/src/lib/y2packager/product.rb', line 223

def installed?
  status?(:installed)
end

#labelString

Return a package label

It will use 'display_name', 'short_name' or 'name'.

Returns:

  • (String)

    Package label


255
256
257
# File 'library/packages/src/lib/y2packager/product.rb', line 255

def label
  display_name || short_name || name
end

#release_notes(user_lang, format = :txt) ⇒ ReleaseNotes

Return product's release notes

Parameters:

  • format (Symbol) (defaults to: :txt)

    Release notes format (use :txt as default)

  • user_lang (String)

    Preferred language (use current language as default)

Returns:

  • (ReleaseNotes)

    Release notes for product, language and format

See Also:


266
267
268
# File 'library/packages/src/lib/y2packager/product.rb', line 266

def release_notes(user_lang, format = :txt)
  ReleaseNotesReader.new(self).release_notes(user_lang: user_lang, format: format)
end

#relnotes_urlString?

Return release notes URL

Release notes might not be defined in libzypp and this method returns the URL to get release notes from.

Returns:

  • (String, nil)

    Release notes URL or nil if it is not defined.


276
277
278
279
280
281
# File 'library/packages/src/lib/y2packager/product.rb', line 276

def relnotes_url
  return nil unless resolvable_properties

  url = resolvable_properties.relnotes_url
  url.empty? ? nil : url
end

#resolvable_propertiesHash

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.

Returns:

  • (Hash)

    properties


304
305
306
# File 'library/packages/src/lib/y2packager/product.rb', line 304

def resolvable_properties
  @resolvable_properties ||= Y2Packager::Resolvable.find(kind: :product, name: name, version: version).first
end

#restoreObject

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.


245
246
247
248
# File 'library/packages/src/lib/y2packager/product.rb', line 245

def restore
  log.info "Restoring product #{name} status"
  Yast::Pkg.ResolvableNeutral(name, :product, true)
end

#selectBoolean

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.

Returns:

  • (Boolean)

    true if the product has been sucessfully selected


234
235
236
237
# File 'library/packages/src/lib/y2packager/product.rb', line 234

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.

Returns:

  • (Boolean)

    true if it is selected


211
212
213
# File 'library/packages/src/lib/y2packager/product.rb', line 211

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.

Parameters:

  • statuses (Array<Symbol>)

    Status to compare with.

Returns:

  • (Boolean)

    true if it is in the given status


291
292
293
294
295
# File 'library/packages/src/lib/y2packager/product.rb', line 291

def status?(*statuses)
  Y2Packager::Resolvable.find(kind: :product, name: name).any? do |res|
    statuses.include?(res.status)
  end
end

#version_versionString

Returns the version number (without the release part)

Returns:

  • (String)

    Version number


311
312
313
# File 'library/packages/src/lib/y2packager/product.rb', line 311

def version_version
  version.split("-").first
end