Class: Packages::PackageDownloader

Inherits:
Object
  • Object
show all
Includes:
Yast::I18n, Yast::Logger
Defined in:
library/packages/src/lib/packages/package_downloader.rb

Overview

Note:

For downloading files outside of a libzypp repository use the

Downloads a package from a known package manager (libzypp) repository.

FileFromUrl::get_file_from_url method: https://github.com/yast/yast-installation/blob/fba82c3c9abfc44e3d31c8658bf96079d74e0298/src/lib/transfer/file_from_url.rb#L89

Examples:

Downloading a package

begin
  downloader = PackageDownloader.new(3, "yast2")
  tmp = Tempfile.new("downloaded-package-")
  downloader.download(tmp.path)
  # do something with the package...
ensure
  tmp.close
  tmp.unlink
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repo_id, package_name) ⇒ PackageDownloader

Constructor

Parameters:

  • repo_id (Integer)

    Repository ID

  • package_name (String)

    Name of the package to download



55
56
57
58
59
60
# File 'library/packages/src/lib/packages/package_downloader.rb', line 55

def initialize(repo_id, package_name)
  textdomain "base"

  @repo_id = repo_id
  @package_name = package_name
end

Instance Attribute Details

#package_nameString (readonly)

Returns Name of the package.

Returns:

  • (String)

    Name of the package



49
50
51
# File 'library/packages/src/lib/packages/package_downloader.rb', line 49

def package_name
  @package_name
end

#repo_idInteger (readonly)

Returns Repository ID.

Returns:

  • (Integer)

    Repository ID



47
48
49
# File 'library/packages/src/lib/packages/package_downloader.rb', line 47

def repo_id
  @repo_id
end

Instance Method Details

#download(path) ⇒ Object

Download the package locally to the given path.

It is responsibility of the caller to remove the downloaded package when it is not needed anymore.

Parameters:

  • path (#to_s)

    path where the downloaded package will be stored

Raises:

  • PackageNotFound



70
71
72
73
74
75
76
# File 'library/packages/src/lib/packages/package_downloader.rb', line 70

def download(path)
  log.info("Downloading package #{package_name} from repo #{repo_id} to #{path}")
  return if Yast::Pkg.ProvidePackage(repo_id, package_name, path.to_s)

  log.error("Package #{package_name} could not be retrieved.")
  raise Y2Packager::PackageFetchError
end