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



282
283
284
285
286
287
288
289
# File 'library/packages/src/modules/Product.rb', line 282

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



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



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

def FindBaseProducts
  return unless load_zypp

  log.info "Looking for base products"

  products = Pkg.ResolvableProperties("", :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 { |p| p["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

  deep_copy(products)
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



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'library/packages/src/modules/Product.rb', line 140

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