Class: Y2Packager::LicensesFetchers::Archive

Inherits:
Base
  • Object
show all
Defined in:
library/packages/src/lib/y2packager/licenses_fetchers/archive.rb

Overview

Base class for licenses fetchers based on some kind of license archive.

It takes care of looking up the licenses in the unpacked archive and manages a temporary cache directory.

The actual unpacking and provisioning of the archive file itself must be done in a derived class.

Direct Known Subclasses

Rpm, Tarball

Constant Summary collapse

NO_ACCEPTANCE_FILE =

Acceptance is not needed if the file exists

"no-acceptance-needed".freeze
FALLBACK_LICENSE_FILE =

Fallback license file

"LICENSE.TXT".freeze

Constants inherited from Base

Base::DEFAULT_LANG

Instance Attribute Summary

Attributes inherited from Base

#product_name

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#content, #found?, #initialize

Constructor Details

This class inherits a constructor from Y2Packager::LicensesFetchers::Base

Class Method Details

.finalize(dir) ⇒ Object

Explicit destructor to clean up temporary dir

Parameters:

  • dir (String)

    Temporary directory where licenses were unpacked



66
67
68
# File 'library/packages/src/lib/y2packager/licenses_fetchers/archive.rb', line 66

def self.finalize(dir)
  proc { FileUtils.remove_entry_secure(dir) }
end

Instance Method Details

#confirmation_required?Boolean

Determine whether the license should be accepted or not

Returns:

  • (Boolean)

    true if the license acceptance is required



57
58
59
60
61
# File 'library/packages/src/lib/y2packager/licenses_fetchers/archive.rb', line 57

def confirmation_required?
  unpack_archive

  find_path_for(archive_dir, NO_ACCEPTANCE_FILE).nil?
end

#localesArray<String>

Return available locales for product's license

Returns:

  • (Array<String>)

    Language codes ("de_DE", "en_US", etc.)



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'library/packages/src/lib/y2packager/licenses_fetchers/archive.rb', line 38

def locales
  return [] if !archive_exists?

  @locales ||=
    begin
      unpack_archive

      license_files = Dir.glob(File.join(archive_dir, "**", "LICENSE.*.TXT"), File::FNM_CASEFOLD)
      # NOTE: despite the use of the case-insensitive flag, the captured group will be
      # returned as it is.
      languages = license_files.map { |path| path[/LICENSE.(\w*).TXT/i, 1] }
      languages << DEFAULT_LANG
      languages.compact.uniq
    end
end