Class: Suse
- Inherits:
-
Object
- Object
- Suse
- Defined in:
- lib/distros/suse.rb
Overview
Copyright © 2011 Cornelius Schumacher <[email protected]>
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#version ⇒ Object
Returns the value of attribute version.
Instance Method Summary collapse
- #get_package_name(manifest) ⇒ Object
- #install(manifest, options = {}) ⇒ Object
- #installed(handler) ⇒ Object
- #is_it_me? ⇒ Boolean
- #uninstall(manifest) ⇒ Object
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
19 20 21 |
# File 'lib/distros/suse.rb', line 19 def name @name end |
#version ⇒ Object
Returns the value of attribute version.
19 20 21 |
# File 'lib/distros/suse.rb', line 19 def version @version end |
Instance Method Details
#get_package_name(manifest) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/distros/suse.rb', line 86 def get_package_name manifest package_section = manifest.packages.openSUSE if !package_section STDERR.puts "No packages section in metadata" else name_section = package_section[name] if !name_section STDERR.puts "No section '#{name}' found in packages section." else version_section = name_section[version] if !version_section STDERR.puts "No section '#{version}' found in section '#{name}'" else package_name = version_section["package_name"] if !package_name || package_name.empty? STDERR.puts "No package name found" else return package_name end end end end nil end |
#install(manifest, options = {}) ⇒ Object
75 76 77 78 79 80 81 82 83 84 |
# File 'lib/distros/suse.rb', line 75 def install manifest, = {} package_name = get_package_name manifest = Array.new if [:dry_run] .push "--dry-run" end if package_name system "sudo zypper install #{.join(" ")} #{package_name}" end end |
#installed(handler) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/distros/suse.rb', line 37 def installed handler packages = Hash.new `rpmqpack`.each_line do |package| packages[package.chomp] = true end unknown = 0 installed = Array.new handler.manifests.each do |manifest| unknown += 1 package_section = manifest.packages.openSUSE next unless package_section name_section = package_section[name] next unless name_section version_section = name_section[version] next unless version_section if packages.has_key? version_section["package_name"] installed.push manifest unknown -= 1 end end if unknown > 0 STDERR.puts "Warning: #{unknown} libraries don't have package information" end installed end |
#is_it_me? ⇒ Boolean
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/distros/suse.rb', line 21 def is_it_me? begin File.open "/etc/SuSE-release" do |file| if file.readline =~ /^openSUSE/ @name = "openSUSE" file.readline =~ /VERSION = (.*)/ @version = $1 end end true rescue Errno::ENOENT false end end |
#uninstall(manifest) ⇒ Object
68 69 70 71 72 73 |
# File 'lib/distros/suse.rb', line 68 def uninstall manifest package_name = get_package_name manifest if package_name system "sudo zypper rm #{package_name}" end end |