Class: Y2Packager::ProductReader

Inherits:
Object
  • Object
show all
Includes:
Yast::Logger
Defined in:
library/packages/src/lib/y2packager/product_reader.rb

Overview

Read the product information from libzypp

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.installation_package_mappingHash<String,String>

Installation packages map

This map contains the correspondence between products and the installation package for each product.

The information is always read again. Reason is that that url can be invalid, but user fix it later. This way it cache invalid result. See bsc#1086840 ProductReader instance cache it properly, but caching for installation life-time should be prevented.

Returns:

  • (Hash<String,String>)

    product name -> installation package name


40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'library/packages/src/lib/y2packager/product_reader.rb', line 40

def installation_package_mapping
  installation_packages = Yast::Pkg.PkgQueryProvides("system-installation()")
  log.info "Installation packages: #{installation_packages.inspect}"

  installation_package_mapping = {}
  installation_packages.each do |list|
    pkg_name = list.first    # There can be more instances of same package in different version.
    # Prefer the selected or the available package, they should provide newer data
    # than the installed one.

    packages = Yast::Pkg.Resolvables({ name: pkg_name, kind: :package }, [:dependencies, :status])
    package = packages.find { |p| p["status"] == :selected } ||
      packages.find { |p| p["status"] == :available } ||
      packages.first

    dependencies = package["deps"]
    install_provides = dependencies.find_all do |d|
      d["provides"]&.match(/system-installation\(\)/)
    end

    # parse product name from provides. Format of provide is
    # `system-installation() = <product_name>`
    install_provides.each do |install_provide|
      product_name = install_provide["provides"][/system-installation\(\)\s*=\s*(\S+)/, 1]
      log.info "package #{pkg_name} install product #{product_name}"
      installation_package_mapping[product_name] = pkg_name
    end

  end

  installation_package_mapping
end

Instance Method Details

#all_installed_productsArray<Y2Packager::Product>

All installed products

Returns:


149
150
151
152
153
# File 'library/packages/src/lib/y2packager/product_reader.rb', line 149

def all_installed_products
  installed_products.map do |p|
    Y2Packager::Product.from_resolvable(p, installation_package_mapping[p.name])
  end
end

#all_products(force_repos: false) ⇒ Array<Product>

Available products

Returns:

  • (Array<Product>)

    Available products


77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
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
# File 'library/packages/src/lib/y2packager/product_reader.rb', line 77

def all_products(force_repos: false)
  linuxrc_special_products = if Yast::Linuxrc.InstallInf("specialproduct")
    linuxrc_string(Yast::Linuxrc.InstallInf("specialproduct")).split(",")
  else
    []
  end

  return @all_products if @all_products && !force_repos

  if Yast::Stage.initial && Y2Packager::MediumType.online? && !force_repos
    return Y2Packager::ProductControlProduct.products.each_with_object([]) do |p, result|
      result << Y2Packager::Product.from_product_control_product(p)
    end
  end

  @all_products = []

  available_products.each do |prod|
    prod_pkg = product_package(prod.product_package)

    if prod_pkg      # remove special products if they have not been defined in linuxrc

      prod_pkg.deps.find { |dep| dep["provides"] =~ /\Aspecialproduct\(\s*(.*?)\s*\)\z/ }
      special_product_tag = linuxrc_string(Regexp.last_match[1]) if Regexp.last_match
      if special_product_tag && !linuxrc_special_products.include?(special_product_tag)
        log.info "Special product #{prod.name} has not been defined via linuxrc. --> do not offer it"
        next
      end

      # Evaluating display order
      prod_pkg.deps.find { |dep| dep["provides"] =~ /\Adisplayorder\(\s*([0-9]+)\s*\)\z/ }
      displayorder = Regexp.last_match[1].to_i if Regexp.last_match
    end

    @all_products << Y2Packager::Product.from_resolvable(
      prod, installation_package_mapping[prod.name], displayorder
    )
  end

  @all_products
end

#available_base_products(force_repos: false) ⇒ Array<Y2Packager::Product>

In installation Read the available libzypp base products for installation

Returns:

  • (Array<Y2Packager::Product>)

    the found available base products, the products are sorted by the 'displayorder' provides value


122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'library/packages/src/lib/y2packager/product_reader.rb', line 122

def available_base_products(force_repos: false)
  # If no product contains a 'system-installation()' tag but there is only 1 product,
  # we assume that it is the base one.
  products = all_products(force_repos: force_repos)
  if products.size == 1 && installation_package_mapping.empty?
    log.info "Assuming that #{products.inspect} is the base product."
    return products
  end

  log.info "all products #{products}"  # only installable products

  products = products.select(&:installation_package).sort(&::Y2Packager::PRODUCT_SORTER)
  log.info "available base products #{products}"
  products
end

#installed_base_productY2Packager::Product?

Read the installed base product

Returns:


140
141
142
143
144
145
# File 'library/packages/src/lib/y2packager/product_reader.rb', line 140

def installed_base_product
  base = base_product
  return nil unless base

  Y2Packager::Product.from_resolvable(base, installation_package_mapping[base.name])
end

#product_package(name, _repo_id = nil) ⇒ Object


155
156
157
158
159
160
161
162
# File 'library/packages/src/lib/y2packager/product_reader.rb', line 155

def product_package(name, _repo_id = nil)
  return nil unless name

  # find the highest version
  Y2Packager::Resolvable.find(kind: :package, name: name).reduce(nil) do |a, p|
    (!a || (Yast::Pkg.CompareVersions(a.version, p.version) < 0)) ? p : a
  end
end