Class: Machinery::Zypper
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
-
#zypp_base ⇒ Object
Returns the value of attribute zypp_base.
-
#zypp_config ⇒ Object
Returns the value of attribute zypp_config.
-
#zypper_options ⇒ Object
Returns the value of attribute zypper_options.
Class Method Summary collapse
Instance Method Summary collapse
- #add_repo(url, repo_alias) ⇒ Object
- #contains_mountable_repos? ⇒ Boolean
- #download_package(package) ⇒ Object
- #refresh ⇒ Object
- #remove_repo(repo_alias) ⇒ Object
- #version ⇒ Object
Instance Attribute Details
#zypp_base ⇒ Object
Returns the value of attribute zypp_base.
27 28 29 |
# File 'lib/zypper.rb', line 27 def zypp_base @zypp_base end |
#zypp_config ⇒ Object
Returns the value of attribute zypp_config.
26 27 28 |
# File 'lib/zypper.rb', line 26 def zypp_config @zypp_config end |
#zypper_options ⇒ Object
Returns the value of attribute zypper_options.
25 26 27 |
# File 'lib/zypper.rb', line 25 def @zypper_options end |
Class Method Details
.isolated(options = {}, &block) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/zypper.rb', line 30 def isolated( = {}, &block) zypper = Machinery::Zypper.new zypper.zypp_base = Dir.mktmpdir("machinery_zypper") zypper. = [ "--non-interactive", "--no-gpg-checks", "--root", zypper.zypp_base ] if [:arch] zypper.zypp_config = create_zypp_config(zypper.zypp_base, [:arch]) end block.call(zypper) ensure clean_up(zypper) end |
Instance Method Details
#add_repo(url, repo_alias) ⇒ Object
75 76 77 |
# File 'lib/zypper.rb', line 75 def add_repo(url, repo_alias) call_zypper "ar", url, repo_alias end |
#contains_mountable_repos? ⇒ Boolean
100 101 102 103 104 105 106 107 |
# File 'lib/zypper.rb', line 100 def contains_mountable_repos? files = Dir.glob(File.join(@zypp_base, "etc/zypp/repos.d", "*")) files.any? do |file| File.readlines(file).any? do |line| line.start_with?("baseurl=nfs://", "baseurl=nfs4://", "baseurl=smb://", "baseurl=cifs://") end end end |
#download_package(package) ⇒ Object
87 88 89 90 91 92 |
# File 'lib/zypper.rb', line 87 def download_package(package) raw_xml = call_zypper "-x", "download", package, stdout: :capture xml = REXML::Document.new(raw_xml) xml.elements["//localfile"].attributes["path"] if xml.elements["//localfile"] end |
#refresh ⇒ Object
83 84 85 |
# File 'lib/zypper.rb', line 83 def refresh call_zypper "refresh", sudo: contains_mountable_repos? end |
#remove_repo(repo_alias) ⇒ Object
79 80 81 |
# File 'lib/zypper.rb', line 79 def remove_repo(repo_alias) call_zypper "rr", repo_alias end |
#version ⇒ Object
94 95 96 97 98 |
# File 'lib/zypper.rb', line 94 def version version = call_zypper "--version", stdout: :capture found = version.match(/zypper (\d+)\.(\d+)\.(\d+)/) [found[1].to_i, found[2].to_i, found[3].to_i] if found end |