Skip to content

Commit

Permalink
Initial implementation for the addon licenses
Browse files Browse the repository at this point in the history
  • Loading branch information
lslezak committed Feb 13, 2018
1 parent 73437d8 commit d11fc04
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/modules/ProductLicense.rb
@@ -1,6 +1,7 @@
# encoding: utf-8
require "yast"
require "uri"
require "fileutils"

# Yast namespace
module Yast
Expand Down Expand Up @@ -1233,6 +1234,8 @@ def SearchForLicense_AddOnProduct(src_id, _fallback_dir)

# no license present
if license_file.nil?
return if product_license(src_id, @tmpdir)

Builtins.y2milestone("No license present")
@license_dir = nil
@tmpdir = nil
Expand Down Expand Up @@ -1624,6 +1627,42 @@ def beta_seen?(id)
def beta_seen!(id)
@beta_file_already_seen[id] = true
end

# @return [Boolean] true if a license has been found
def product_license(id, tmpdir)
# make sure the resolvables are loaded into the libzypp pool
Pkg.SourceLoad

products = Pkg.ResolvableProperties("", :product, "")
products.reject!{|p| p["source"] != id}

names = products.map{|p| p["name"]}.uniq
log.info("Found products from source #{id}: #{names.inspect}")
found_license = false

names.each do |name|
# FIXME: extract all license translations
lang = "en"
license = Pkg.PrdGetLicenseToConfirm(name, lang)

if license && !license.empty?
found_license = true
log.info("Found license for language '#{lang}' (#{license.size} characters)")

::FileUtils.mkdir_p(tmpdir)
path = File.join(tmpdir, "license.#{lang}.txt")
File.write(path, license)
log.info("Saved to file #{path}")

# FIXME: write also the generic license.txt with the English license?
@license_dir = tmpdir
# FIXME: use the real location
@license_file_print = "license.tar.gz"
end
end

found_license
end
end

ProductLicense = ProductLicenseClass.new
Expand Down

0 comments on commit d11fc04

Please sign in to comment.