Class: Y2Packager::Package

Inherits:
Object
  • Object
show all
Includes:
Yast::Logger
Defined in:
library/packages/src/lib/y2packager/package.rb

Overview

This class represents a libzypp package and it offers an API to common operations.

The idea is extending this class with new methods when needed.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, repo_id, version) ⇒ Package

Constructor

Parameters:

  • name (String)

    Package name

  • repo_id (Integer)

    Repository ID

  • version (String)

    Package version



53
54
55
56
57
# File 'library/packages/src/lib/y2packager/package.rb', line 53

def initialize(name, repo_id, version)
  @name = name
  @repo_id = repo_id
  @version = version
end

Instance Attribute Details

#nameString (readonly)

Returns Package name

Returns:

  • (String)

    Package name



29
30
31
# File 'library/packages/src/lib/y2packager/package.rb', line 29

def name
  @name
end

#repo_idInteger (readonly)

Returns Id of the repository where the package lives

Returns:

  • (Integer)

    Id of the repository where the package lives



31
32
33
# File 'library/packages/src/lib/y2packager/package.rb', line 31

def repo_id
  @repo_id
end

#versionString (readonly)

Returns Package version

Returns:

  • (String)

    Package version



33
34
35
# File 'library/packages/src/lib/y2packager/package.rb', line 33

def version
  @version
end

Class Method Details

.find(name) ⇒ Array<Package>?

Find packages by name

Parameters:

  • name (String)

    Package name

Returns:

  • (Array<Package>, nil)

    Packages named like `name`. It returns `nil` if some problem occurs interacting with libzypp.



41
42
43
44
45
# File 'library/packages/src/lib/y2packager/package.rb', line 41

def find(name)
  props = Yast::Pkg.ResolvableProperties(name, :package, "")
  return nil if props.nil?
  props.map { |i| new(i["name"], i["source"], i["version"]) }
end

Instance Method Details

#download_to(path) ⇒ Object

Download a package to the given path

Parameters:

  • path (String, Pathname)

    Path to download the package to

See Also:



73
74
75
76
# File 'library/packages/src/lib/y2packager/package.rb', line 73

def download_to(path)
  downloader = Packages::PackageDownloader.new(repo_id, name)
  downloader.download(path.to_s)
end

#extract_to(directory) ⇒ Object

Download and extract the package to the given directory

Parameters:

  • directory (String, Pathname)

    Path to extract the package to

See Also:



82
83
84
85
86
87
88
89
90
# File 'library/packages/src/lib/y2packager/package.rb', line 82

def extract_to(directory)
  tmpfile = Tempfile.new("downloaded-package-#{name}-")
  download_to(tmpfile.path)
  extractor = Packages::PackageExtractor.new(tmpfile.path)
  extractor.extract(directory.to_s)
ensure
  tmpfile.close
  tmpfile.unlink
end

#statusSymbol

Return package status

Ask libzypp about package status.

Returns:

  • (Symbol)

    Package status (:installed, :available, etc.)

See Also:

  • Yast::Pkg.PkgProperties


65
66
67
# File 'library/packages/src/lib/y2packager/package.rb', line 65

def status
  Yast::Pkg.PkgProperties(name)["status"]
end