Class: Y2Packager::ProductReader
- Inherits:
-
Object
- Object
- Y2Packager::ProductReader
- Includes:
- Yast::Logger
- Defined in:
- library/packages/src/lib/y2packager/product_reader.rb
Overview
Read the product information from libzypp
Class Method Summary collapse
-
.installation_package_mapping ⇒ Hash<String,String>
Installation packages map.
Instance Method Summary collapse
-
#all_installed_products ⇒ Array<Y2Packager::Product>
All installed products.
-
#all_products(force_repos: false) ⇒ Array<Product>
Available products.
-
#available_base_products(force_repos: false) ⇒ Array<Y2Packager::Product>
In installation Read the available libzypp base products for installation.
-
#installed_base_product ⇒ Y2Packager::Product?
Read the installed base product.
- #product_package(name, _repo_id = nil) ⇒ Object
Class Method Details
.installation_package_mapping ⇒ Hash<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.
39 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 |
# File 'library/packages/src/lib/y2packager/product_reader.rb', line 39 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_products ⇒ Array<Y2Packager::Product>
All installed products
142 143 144 145 146 |
# File 'library/packages/src/lib/y2packager/product_reader.rb', line 142 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
76 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 |
# File 'library/packages/src/lib/y2packager/product_reader.rb', line 76 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 @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
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'library/packages/src/lib/y2packager/product_reader.rb', line 115 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_product ⇒ Y2Packager::Product?
Read the installed base product
133 134 135 136 137 138 |
# File 'library/packages/src/lib/y2packager/product_reader.rb', line 133 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
148 149 150 151 152 153 154 155 |
# File 'library/packages/src/lib/y2packager/product_reader.rb', line 148 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 |