Class: Y2Packager::Product

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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)

    Name

  • short_name (String)

    Short name

  • display_name (String)

    Display name

  • version (String)

    Version

  • arch (String)

    Architecture

  • category (Symbol)

    Category (:base, :addon)

  • vendor (String)

    Vendor

  • order (Integer)

    Display order

  • installation_package (String)

    Installation package name



88
89
90
91
92
93
94
95
96
97
98
99
# File 'library/packages/src/lib/y2packager/product.rb', line 88

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



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

def arch
  @arch
end

#categorySymbol (readonly)

Returns Category

Returns:

  • (Symbol)

    Category



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

def category
  @category
end

#display_nameString (readonly)

Returns Display name

Returns:

  • (String)

    Display name



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

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



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

def installation_package
  @installation_package
end

#nameString (readonly)

Returns Name

Returns:

  • (String)

    Name



26
27
28
# File 'library/packages/src/lib/y2packager/product.rb', line 26

def name
  @name
end

#orderInteger (readonly)

Returns Display order

Returns:

  • (Integer)

    Display order



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

def order
  @order
end

#short_nameString (readonly)

Returns Short name

Returns:

  • (String)

    Short name



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

def short_name
  @short_name
end

#vendorString (readonly)

Returns Vendor

Returns:

  • (String)

    Vendor



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

def vendor
  @vendor
end

#versionString (readonly)

Returns Version

Returns:

  • (String)

    Version



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

def version
  @version
end

Class Method Details

.allArray<Product>

Return all known products

Returns:

  • (Array<Product>)

    Known products



48
49
50
# File 'library/packages/src/lib/y2packager/product.rb', line 48

def all
  Y2Packager::ProductReader.new.all_products
end

.available_base_productsArray<Product>

Return available base products

Returns:

  • (Array<Product>)

    Available base products



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

def available_base_products
  Y2Packager::ProductReader.new.available_base_products
end

.selected_baseProduct

Returns the selected base product

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

Returns:

  • (Product)

    Selected base product



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

def selected_base
  available_base_products.find(&: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



72
73
74
# File 'library/packages/src/lib/y2packager/product.rb', line 72

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



107
108
109
110
111
112
113
114
# File 'library/packages/src/lib/y2packager/product.rb', line 107

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:



135
136
137
# File 'library/packages/src/lib/y2packager/product.rb', line 135

def installed?
  status?(:installed)
end

#labelString

Return a package label

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

Returns:

  • (String)

    Package label



167
168
169
# File 'library/packages/src/lib/y2packager/product.rb', line 167

def label
  display_name || short_name || name
end

#license(lang) ⇒ String?

Return the license to confirm

It will return the empty string (“”) if the license does not exist or if it was already confirmed.

Parameters:

  • lang (String)

    Language

Returns:

  • (String, nil)

    Product's license; nil if the product was not found.



178
179
180
# File 'library/packages/src/lib/y2packager/product.rb', line 178

def license(lang)
  Yast::Pkg.PrdGetLicenseToConfirm(name, lang)
end

#license?(lang) ⇒ Boolean

Determines whether the product has a license

Parameters:

  • lang (String)

    Language

Returns:

  • (Boolean)

    true if the product has a license



186
187
188
189
190
# File 'library/packages/src/lib/y2packager/product.rb', line 186

def license?(lang)
  content = license(lang)
  return false unless content
  content != ""
end

#license_confirmation=(confirmed) ⇒ Object

Set license confirmation for the product

Parameters:

  • confirmed (Boolean)

    determines whether the license should be accepted or not



202
203
204
205
206
207
208
# File 'library/packages/src/lib/y2packager/product.rb', line 202

def license_confirmation=(confirmed)
  if confirmed
    Yast::Pkg.PrdMarkLicenseConfirmed(name)
  else
    Yast::Pkg.PrdMarkLicenseNotConfirmed(name)
  end
end

#license_confirmation_required?Boolean

Determine whether the license should be accepted or not

Returns:

  • (Boolean)

    true if the license acceptance is required



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

def license_confirmation_required?
  Yast::Pkg.PrdNeedToAcceptLicense(name)
end

#license_confirmed?Boolean

Determine whether the license is confirmed

Returns:

  • (Boolean)

    true if the license was confirmed (or acceptance was not needed)



213
214
215
# File 'library/packages/src/lib/y2packager/product.rb', line 213

def license_confirmed?
  Yast::Pkg.PrdHasLicenseConfirmed(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:



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

def release_notes(user_lang, format = :txt)
  ReleaseNotesReader.new(self).release_notes(user_lang: user_lang, format: format)
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.



157
158
159
160
# File 'library/packages/src/lib/y2packager/product.rb', line 157

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



146
147
148
149
# File 'library/packages/src/lib/y2packager/product.rb', line 146

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



123
124
125
# File 'library/packages/src/lib/y2packager/product.rb', line 123

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



236
237
238
239
240
# File 'library/packages/src/lib/y2packager/product.rb', line 236

def status?(*statuses)
  Yast::Pkg.ResolvableProperties(name, :product, "").any? do |res|
    statuses.include?(res["status"])
  end
end