Class: Yast::ProductClass

Inherits:
Module
  • Object
show all
Includes:
Logger
Defined in:
library/packages/src/modules/Product.rb

Constant Summary collapse

OS_RELEASE_PROPERTIES =

Values loaded from os-release file

[
  :name, :short_name, :version
].freeze
DROPPED_METHODS =

All these methods have been dropped

[
  :vendor, :dist, :distproduct, :distversion, :shortlabel
].freeze

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object (private)

Handles using dropped methods



296
297
298
299
300
301
302
303
# File 'library/packages/src/modules/Product.rb', line 296

def method_missing(method_name, *args, &block)
  if DROPPED_METHODS.include? method_name
    log.error "Method Product.#{method_name} dropped"
    raise "Method Product.#{method_name} has been dropped"
  else
    super
  end
end

Instance Method Details

#find_property(key = __callee__) ⇒ Object Also known as: name, short_name, version, run_you, flags, relnotesurl, relnotesurl_all, product_of_relnotes

Loads and returns base product property

Parameters:

  • key (Symbol) (defaults to: __callee__)

    (optional)



50
51
52
53
# File 'library/packages/src/modules/Product.rb', line 50

def find_property(key = __callee__)
  load_product_data(key)
  get_property(key)
end

#FindBaseProductsArray <Hash>

Returns list Hashes of selected (installation) or installed (running system) base products got from libzypp

Returns:

  • (Array <Hash>)

    with product definitions



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'library/packages/src/modules/Product.rb', line 93

def FindBaseProducts
  return unless load_zypp

  log.info "Looking for base products"

  products = Y2Packager::Resolvable.find(kind: :product) || []

  # For all (not only base) products
  # FIXME: filling release notes is a nasty side effect of searching the base product,
  # it should be handled separately...
  required_status = use_installed_products? ? :installed : :selected
  fill_up_relnotes(products.select { |p| p.status == required_status })

  # list of products defined by the "system-installation()" provides
  system_products = Y2Packager::ProductReader.installation_package_mapping.keys
  selected = Pkg.IsAnyResolvable(:product, :to_install)

  # Use only base products
  products.select! do |p|
    # The category "base" is not set during installation yet, it is set
    # only for _installed_ base product (otherwise "addon" is reported).
    if use_installed_products?
      p.category == "base"
    elsif system_products && !system_products.empty?
      # the base product is marked by "system-installation()" provides
      status = selected ? :selected : :available
      system_products.include?(p.name) && p.status == status
    else
      # Use the product from the initial repository as a fallback
      p.source == 0
    end
  end

  log.info "Found #{products.size} base product(s): #{products.map(&:name).inspect}"

  if products.empty?
    log.error "No base product found"
    # Logging all information about the product evaluation
    ::Installation::InstallationInfo.instance.write(
      "No base product found",
      additional_info: { "required_product_status" => required_status }
    )
    raise "No base product found"
  elsif products.size > 1
    log.warn "More than one base product found!"
  end

  # returns a hash in order to not change the interface
  products.map do |p|
    { "name"            => p.name,
      "short_name"      => p.short_name,
      "display_name"    => p.display_name,
      "version"         => p.version,
      "arch"            => p.arch,
      "category"        => p.category,
      "vendor"          => p.vendor,
      "status"          => p.status,
      "relnotes_url"    => p.relnotes_url,
      "register_target" => p.register_target }
  end
end

#mainObject



38
39
40
41
42
43
44
45
# File 'library/packages/src/modules/Product.rb', line 38

def main
  Yast.import "Pkg"
  Yast.import "Mode"
  Yast.import "Stage"
  Yast.import "OSRelease"
  Yast.import "PackageLock"
  Yast.import "PackageSystem"
end

#ReadProductsObject

Reads products from libzypp and fills the internal products cache that can be read by other methods in this library



157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'library/packages/src/modules/Product.rb', line 157

def ReadProducts
  # Do not read any product information from zypp on a running system
  return if Mode.config

  Builtins.y2milestone("Product.#{__method__} started")
  return unless load_zypp

  base_product = FindBaseProducts().fetch(0, {})

  set_property(
    :name,
    base_product.fetch("display_name",
      base_product.fetch("summary",
        base_product.fetch("name", "")))
  )

  set_property(:short_name, base_product.fetch("short_name", name))
  set_property(:version, base_product.fetch("version", "").split("-")[0])
  set_property(:relnotesurl, base_product.fetch("relnotes_url", ""))
  set_property(:flags, base_product.fetch("flags", []))
  set_property(:run_you, flags.include?("no_you"))

  nil
end