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, register_target: "") ⇒ 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

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

    Register target



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

#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

#register_targetString (readonly)

Returns Registration target name used for registering the product.

Returns:

  • (String)

    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_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



90
91
92
# File 'library/packages/src/lib/y2packager/product.rb', line 90

def all
  Y2Packager::ProductReader.new.all_products
end

.available_base_productsArray<Product>

Return available base products

Returns:

  • (Array<Product>)

    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.

Parameters:

  • product (Hash)

    the pkg-bindings product hash

Returns:



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

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:



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_productProduct?

Return the installed base product

Returns:

  • (Product, nil)

    Installed base product or nil if not found



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_productsProduct?

Return all installed products (including the base product)

Returns:

  • (Product, nil)

    Installed products



111
112
113
# File 'library/packages/src/lib/y2packager/product.rb', line 111

def installed_products
  Y2Packager::ProductReader.new.all_installed_products
end

.resettrue

Resets cached attributes of the class

Returns:

  • (true)


58
59
60
# File 'library/packages/src/lib/y2packager/product.rb', line 58

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



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

Parameters:

  • statuses (Array<Symbol>)

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

Returns:

  • (Array<Product>)

    Products with the 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.

Returns:

  • (Boolean)

    true if both products are the same; false otherwise



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.

Returns:

  • (Boolean)

    true if it is installed

See Also:



196
197
198
# File 'library/packages/src/lib/y2packager/product.rb', line 196

def installed?
  status?(:installed)
end

#labelString

Return a package label

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

Returns:

  • (String)

    Package label



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

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:



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_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.



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_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



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

#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.



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

#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



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.

Returns:

  • (Boolean)

    true if it is selected



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.

Parameters:

  • statuses (Array<Symbol>)

    Status to compare with.

Returns:

  • (Boolean)

    true if it is in the given status



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_versionString

Returns the version number (without the release part)

Returns:

  • (String)

    Version number



284
285
286
# File 'library/packages/src/lib/y2packager/product.rb', line 284

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