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


290
291
292
293
294
295
296
297
# File 'library/packages/src/modules/Product.rb', line 290

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)


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

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


92
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
# File 'library/packages/src/modules/Product.rb', line 92

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


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

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


151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'library/packages/src/modules/Product.rb', line 151

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