Class: Y2Packager::Product

Inherits:
Object
  • Object
show all
Includes:
Yast::Logger
Defined in:
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, status: nil, category: nil, vendor: nil, order: nil, installation_package: nil) ⇒ Product

Constructor


92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'src/lib/y2packager/product.rb', line 92

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

Instance Attribute Details

#archString (readonly)


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

def arch
  @arch
end

#categorySymbol (readonly)


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

def category
  @category
end

#display_nameString (readonly)


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

def display_name
  @display_name
end

#installation_packageString (readonly)


45
46
47
# File 'src/lib/y2packager/product.rb', line 45

def installation_package
  @installation_package
end

#nameString (readonly)


27
28
29
# File 'src/lib/y2packager/product.rb', line 27

def name
  @name
end

#orderInteger (readonly)


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

def order
  @order
end

#short_nameString (readonly)


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

def short_name
  @short_name
end

#statusSymbol (readonly)


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

def status
  @status
end

#vendorString (readonly)


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

def vendor
  @vendor
end

#versionString (readonly)


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

def version
  @version
end

Class Method Details

.allArray<Product>

Return all known products


51
52
53
# File 'src/lib/y2packager/product.rb', line 51

def all
  Y2Packager::ProductReader.new.all_products
end

.available_base_productsArray<Product>

Return available base products


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

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.


67
68
69
# File 'src/lib/y2packager/product.rb', line 67

def selected_base
  available_base_products.find(&:selected?)
end

.with_status(*statuses) ⇒ Array<Product>

Return the products with a given status


75
76
77
# File 'src/lib/y2packager/product.rb', line 75

def with_status(*statuses)
  all.select { |s| statuses.include?(s.status) }
end

Instance Method Details

#==(other) ⇒ Boolean

Compare two different products

If arch, name, version and vendor match they are considered the same product.


112
113
114
115
116
117
118
119
# File 'src/lib/y2packager/product.rb', line 112

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

#labelString

Return a package label

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


162
163
164
# File 'src/lib/y2packager/product.rb', line 162

def label
  display_name || short_name || name
end

#license(lang = nil) ⇒ String?

Return the license to confirm

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


172
173
174
175
# File 'src/lib/y2packager/product.rb', line 172

def license(lang = nil)
  license_lang = lang || Yast::Language.language
  Yast::Pkg.PrdGetLicenseToConfirm(name, license_lang)
end

#license?Boolean

Determines whether the product has a license


180
181
182
183
# File 'src/lib/y2packager/product.rb', line 180

def license?
  return false unless license
  license != ""
end

#license_confirmation=(confirmed) ⇒ Object

Set license confirmation for the product


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

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


188
189
190
# File 'src/lib/y2packager/product.rb', line 188

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

#license_confirmed?Boolean

Determine whether the license is confirmed


206
207
208
# File 'src/lib/y2packager/product.rb', line 206

def license_confirmed?
  Yast::Pkg.PrdHasLicenseConfirmed(name)
end

#release_notes(format = :txt, user_lang = Yast::Language.language) ⇒ ReleaseNotes

Return product's release notes


217
218
219
# File 'src/lib/y2packager/product.rb', line 217

def release_notes(format = :txt, user_lang = Yast::Language.language)
  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.


152
153
154
155
# File 'src/lib/y2packager/product.rb', line 152

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.


141
142
143
144
# File 'src/lib/y2packager/product.rb', line 141

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.


128
129
130
131
132
# File 'src/lib/y2packager/product.rb', line 128

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