Skip to content

Commit

Permalink
Extract add-ons file parse to a separate method
Browse files Browse the repository at this point in the history
  • Loading branch information
imobachgs committed Aug 11, 2016
1 parent 3eda4fc commit 70a060f
Showing 1 changed file with 30 additions and 14 deletions.
44 changes: 30 additions & 14 deletions src/modules/AddOnProduct.rb
Expand Up @@ -1676,20 +1676,12 @@ def AddPreselectedAddOnProducts(filelist)
log.info "Base URL: #{URL.HidePassword(base_url)}"

# Processes all add_on_products files found
filelist.each do |add_on_products_file|
filename = Ops.get(add_on_products_file, "file", "")
type = Ops.get(add_on_products_file, "type", "")
add_products = []
# new xml format
if type == "xml"
add_products = ParseXMLBasedAddOnProductsFile(filename, base_url)
# old fallback
elsif type == "plain"
add_products = ParsePlainAddOnProductsFile(filename, base_url)
else
log.error "Unsupported type: #{type}"
next false
end
filelist.each do |file|
add_products = parse_add_on_products_file(
file.fetch("file", ""), file.fetch("type", ""), base_url
)
next unless add_products

log.info "Adding products: #{add_products}"
add_products.each do |one_product|
url = one_product.fetch("url", "")
Expand Down Expand Up @@ -2258,6 +2250,30 @@ def add_repo_from_cd(url, pth, priority)

AddRepo(result, pth, priority)
end

# Parse a add-on products file
#
# @param filename [String] File path
# @param type [String] File type ("xml" or "plain")
# @param base_url [String] Product's base URL
# @return [Hash] Add-on specification (allowed keys
# are "name", "url", "path", "install_products",
# "ask_user", "selected" and "priority").
#
# @see ParseXMLBasedAddOnProductsFile
# @see ParsePlainAddOnProductsFile
# @see AddPreselectedAddOnProducts
def parse_add_on_products_file(filename, type, base_url)
case type.downcase
when "xml"
ParseXMLBasedAddOnProductsFile(filename, base_url)
when "plain"
ParsePlainAddOnProductsFile(filename, base_url)
else
log.error "Unsupported type: #{type}"
false
end
end
end

AddOnProduct = AddOnProductClass.new
Expand Down

0 comments on commit 70a060f

Please sign in to comment.