Class: Zypper

Inherits:
Object
  • Object
show all
Defined in:
lib/zypper.rb

Overview

Zypper is a wrapper class around the zypper package manager

Zypper offers access to the system-wide zypper environment, but it also allows for running zypper in an isolated environment using ‘Zypper.isolated’. That way Machinery can safely add repositories and download packages without polluting the host.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#zypp_configObject

Returns the value of attribute zypp_config.



26
27
28
# File 'lib/zypper.rb', line 26

def zypp_config
  @zypp_config
end

#zypper_optionsObject

Returns the value of attribute zypper_options.



25
26
27
# File 'lib/zypper.rb', line 25

def zypper_options
  @zypper_options
end

Class Method Details

.isolated(options = {}, &block) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/zypper.rb', line 29

def isolated(options = {}, &block)
  Dir.mktmpdir("machinery_zypper") do |zypper_base|
    zypper = Zypper.new

    zypper.zypper_options = [
      "--non-interactive",
      "--no-gpg-checks",
      "--root", zypper_base
    ]

    if options[:arch]
      zypper.zypp_config = create_zypp_config(zypper_base, options[:arch])
    end

    block.call(zypper)
  end
end

Instance Method Details

#add_repo(url, repo_alias) ⇒ Object



64
65
66
# File 'lib/zypper.rb', line 64

def add_repo(url, repo_alias)
  call_zypper "ar", url, repo_alias
end

#download_package(package) ⇒ Object



76
77
78
79
80
81
# File 'lib/zypper.rb', line 76

def download_package(package)
  raw_xml = call_zypper "-x", "download", package, :stdout => :capture

  xml = Nokogiri::XML(raw_xml)
  xml.xpath("//localfile/@path").to_s
end

#refreshObject



72
73
74
# File 'lib/zypper.rb', line 72

def refresh
  call_zypper "refresh"
end

#remove_repo(repo_alias) ⇒ Object



68
69
70
# File 'lib/zypper.rb', line 68

def remove_repo(repo_alias)
  call_zypper "rr", repo_alias
end