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



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)



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

def name
  @name
end

#repo_idInteger (readonly)



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

def repo_id
  @repo_id
end

#versionString (readonly)



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



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



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



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.

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