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


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)


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

def arch
  @arch
end

#categorySymbol (readonly)


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

def category
  @category
end

#display_nameString (readonly)


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

def display_name
  @display_name
end

#installation_packageString (readonly)


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

def installation_package
  @installation_package
end

#nameString (readonly)


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

def name
  @name
end

#orderInteger (readonly)


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

def order
  @order
end

#short_nameString (readonly)


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

def short_name
  @short_name
end

#vendorString (readonly)


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

def vendor
  @vendor
end

#versionString (readonly)


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


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


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.


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


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.


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.

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


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.


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


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


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


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


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


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.


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.


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.


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