Skip to content

Commit

Permalink
Merge 810d447 into a80e11f
Browse files Browse the repository at this point in the history
  • Loading branch information
imobachgs committed Oct 13, 2021
2 parents a80e11f + 810d447 commit ef47c7d
Show file tree
Hide file tree
Showing 19 changed files with 1,092 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package/yast2-packager.spec
Expand Up @@ -17,7 +17,7 @@


Name: yast2-packager
Version: 4.4.10
Version: 4.4.11
Release: 0
Summary: YaST2 - Package Library
License: GPL-2.0-or-later
Expand Down
47 changes: 47 additions & 0 deletions src/lib/y2packager/control_product_spec.rb
@@ -0,0 +1,47 @@
# Copyright (c) [2021] SUSE LLC
#
# All Rights Reserved.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of version 2 of the GNU General Public License as published
# by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, contact SUSE LLC.
#
# To contact SUSE LLC about this file by physical or electronic mail, you may
# find current contact information at www.suse.com.

require "y2packager/product_spec"

module Y2Packager
# Describes a product for installation that comes from the XML definition
#
# These products are not backed by a libzypp product at the beginning of the
# installation. The corresponding product should become available as soon as
# the product is registered.
class ControlProductSpec < ProductSpec
# @return [String] License URL
attr_reader :license_url
# @return [String] Registration target name used for registering the product
attr_reader :register_target

# @param register_target [String] The registration target name used
# for registering the product, the $arch variable is replaced
# by the current machine architecture
# @param license_url [String] License URL
def initialize(name:, version:, arch:, display_name:, order:, license_url:, register_target:)
super(name: name, version: version, display_name: display_name, arch: arch,
order: order, base: true)

# expand the "$arch" placeholder
@register_target = register_target&.gsub("$arch", arch) || ""
@license_url = license_url
end
end
end
49 changes: 49 additions & 0 deletions src/lib/y2packager/libzypp_product_spec.rb
@@ -0,0 +1,49 @@
# Copyright (c) [2021] SUSE LLC
#
# All Rights Reserved.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of version 2 of the GNU General Public License as published
# by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, contact SUSE LLC.
#
# To contact SUSE LLC about this file by physical or electronic mail, you may
# find current contact information at www.suse.com.

require "y2packager/product_spec"
require "y2packager/product"

Yast.import "Pkg"
Yast.import "AddOnProduct"

module Y2Packager
# Describes a product for installation that comes from the libzypp database
class LibzyppProductSpec < ProductSpec
def to_product
@to_product ||= Y2Packager::Product.available_base_products.find { |p| p.name == name }
end

def select
super

# reset both YaST and user selection (when going back or any products
# selected by YaST in the previous steps)
Yast::Pkg.PkgApplReset
Yast::Pkg.PkgReset
to_product.select

# Reselecting existing add-on-products for installation again
Yast::AddOnProduct.selected_installation_products.each do |product|
log.info "Reselecting add-on product #{product} for installation"
Yast::Pkg.ResolvableInstall(product, :product, "")
end
end
end
end
29 changes: 15 additions & 14 deletions src/lib/y2packager/product_finder.rb
Expand Up @@ -10,8 +10,7 @@
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
# ------------------------------------------------------------------------------

require "y2packager/product_location"
require "y2packager/product_location_details"
require "y2packager/repo_product_spec"

module Y2Packager
# This class finds products in a Solv pool
Expand Down Expand Up @@ -51,7 +50,8 @@ def products(selected_base, media_names)
# a product was found in this directory?
next if ret.any? { |p| p.dir == dir }

ret << ProductLocation.new(name, dir)
# FIXME: it won't work
ret << RepoProductSpec.new(name: name, dir: dir)
end

ret
Expand Down Expand Up @@ -129,21 +129,22 @@ def create_products(product_solvable, found_base_products, selected_base, media_
product_name = p.str[/\Aproduct\(\)\s*=\s*(\S+)/, 1]
next unless product_name

details = ProductLocationDetails.new(
base: found_base_products.include?(product_name),
depends_on: find_dependencies(product_solvable, selected_base),
description: product_solvable.lookup_str(Solv::SOLVABLE_DESCRIPTION) || "",
order: display_order(product_solvable),
product: product_name,
product_package: product_solvable.name,
summary: product_solvable.lookup_str(Solv::SOLVABLE_SUMMARY) || ""
)

dir = product_solvable.repo.name
media_name_pair = media_names.find { |r| r[1] == dir }
media_name = media_name_pair ? media_name_pair.first : dir

ret << ProductLocation.new(media_name, dir, product: details)
ret << RepoProductSpec.new(
media_name: media_name,
name: product_name,
display_name: product_solvable.lookup_str(Solv::SOLVABLE_SUMMARY) || "",
base: found_base_products.include?(product_name),
description: product_solvable.lookup_str(Solv::SOLVABLE_DESCRIPTION) || "",
depends_on: find_dependencies(product_solvable, selected_base),
order: display_order(product_solvable),
dir: dir,
arch: product_solvable.arch,
version: product_solvable.evr.split("-").first
)
end

ret
Expand Down
105 changes: 105 additions & 0 deletions src/lib/y2packager/product_spec.rb
@@ -0,0 +1,105 @@
# Copyright (c) [2021] SUSE LLC
#
# All Rights Reserved.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of version 2 of the GNU General Public License as published
# by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, contact SUSE LLC.
#
# To contact SUSE LLC about this file by physical or electronic mail, you may
# find current contact information at www.suse.com.

require "y2packager/product_license_mixin"

module Y2Packager
# Describes a product that the user can select for installation
#
# The installer allows selecting different products for installation. The list of products can be
# read from different places (the libzypp database, the control.xml file, etc.). This class
# represents those products, read from different places.
#
# Bear in mind that, once selected, the product is mapped to a proper Y2Packager::Product class,
# backed by libzypp.
class ProductSpec
include ProductLicenseMixin

# @return [String] Name. It corresponds to the libzypp resolvable.
attr_reader :name

# @return [String] Name to display to the user
attr_reader :display_name
alias_method :label, :display_name

# @return [String] Version
attr_reader :version

# @return [String] Architecture
attr_reader :arch

# @return [Integer] Order in which the product is shown
attr_reader :order

attr_reader :base

class << self
# Returns the specs for the base products
#
# The found product specs are cached. Set the +reload+ param to +true+
# to force reading them again.
#
# @param reload [Boolean] Force reloading the list of products
# @return [Array<Y2Packager::ProductSpec>] List of product specs
# @see Y2Packager::ProductSpecReader
def base_products(reload: false)
return @products if @products && !reload

require "y2packager/product_spec_reader"
@products = Y2Packager::ProductSpecReader.new.products.select(&:base)
end

# Returns the selected base product spec
#
# @return [ProductSpec,nil] Returns the select base product spec. It returns nil
# if no product is selected.
def selected_base
base_products.find(&:selected?)
end

# Resets the products cache
def reset
@products = nil
end
end

# Constructor
# @param name [String] product name (the identifier, e.g. "SLES")
# @param version [String] version ("15.2")
# @param arch [String] The architecture ("x86_64")
# @param display_name [String] The user visible name ("SUSE Linux Enterprise Server 15 SP2")
def initialize(name:, version:, arch:, display_name:, order: 1, base: true)
@name = name
@version = version
@arch = arch
@display_name = display_name
@order = order
@base = base
@selected = false
end

def selected?
@selected
end

def select
@selected = true
end
end
end
71 changes: 71 additions & 0 deletions src/lib/y2packager/product_spec_reader.rb
@@ -0,0 +1,71 @@
# Copyright (c) [2021] SUSE LLC
#
# All Rights Reserved.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of version 2 of the GNU General Public License as published
# by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, contact SUSE LLC.
#
# To contact SUSE LLC about this file by physical or electronic mail, you may
# find current contact information at www.suse.com.

require "y2packager/product_spec_readers/full"
require "y2packager/product_spec_readers/libzypp"
require "y2packager/product_spec_readers/control"
require "y2packager/medium_type"

module Y2Packager
# Reads product specification from different sources
class ProductSpecReader
include Yast::Logger

# Returns the list of product specifications.
#
# @return [Y2Packager::ProductSpec] List of product specifications
def products
# products_from_control || products_from_offline || products_from_libzypp

case Y2Packager::MediumType.type
when :online
products_from_control
when :offline
products_from_offline
else
products_from_libzypp
end
end

private

# @raise RuntimeError
def products_from_control
control_products = Y2Packager::ProductSpecReaders::Control.new.products
raise "The control file does not define any base product!" if control_products.empty?

log.info "Products from control file: #{control_products.map(&:name).join(", ")}"
control_products
end

def products_from_offline
repo_products = Y2Packager::ProductSpecReaders::Full.new.products(
Yast::InstURL.installInf2Url("")
)
log.info "Products from medium: #{repo_products.map(&:name).join(", ")}"
repo_products
end

def products_from_libzypp
libzypp_products = Y2Packager::ProductSpecReaders::Libzypp.new.products
log.info "Products from libzypp: #{libzypp_products.map(&:name).join(", ")}"
libzypp_products
end
end
end

0 comments on commit ef47c7d

Please sign in to comment.