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 read only once and cached for further queries.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'library/packages/src/lib/y2packager/product_reader.rb', line 33

def installation_package_mapping
  return @installation_package_mapping if @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. We except that one
    # package provide same product installation. So we just pick the first one.
    dependencies = Yast::Pkg.ResolvableDependencies(pkg_name, :package, "").first["deps"]
    install_provide = dependencies.find do |d|
      d["provides"] && d["provides"].match(/system-installation\(\)/)
    end

    # parse product name from provides. Format of provide is
    # `system-installation() = <product_name>`
    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

  @installation_package_mapping
end

Instance Method Details

#all_productsArray<Product>

Available products



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'library/packages/src/lib/y2packager/product_reader.rb', line 62

def all_products
  @all_products ||= available_products.map do |prod|
    prod_pkg = product_package(prod["product_package"], prod["source"])

    if prod_pkg
      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

    Y2Packager::Product.new(
      name: prod["name"], short_name: prod["short_name"], display_name: prod["display_name"],
      version: prod["version"], arch: prod["arch"], category: prod["category"],
      vendor: prod["vendor"], order: displayorder,
      installation_package: installation_package_mapping[prod["name"]]
    )
  end
end

#available_base_productsArray<Y2Packager::Product>

In installation Read the available libzypp base products for installation



83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'library/packages/src/lib/y2packager/product_reader.rb', line 83

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

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

#product_package(name, repo_id) ⇒ Object



97
98
99
100
101
102
# File 'library/packages/src/lib/y2packager/product_reader.rb', line 97

def product_package(name, repo_id)
  return nil unless name
  Yast::Pkg.ResolvableDependencies(name, :package, "").find do |prod|
    prod["source"] == repo_id
  end
end