Sha256: c82d656f7a366586c51599792d89888e2e260cf1fa874eeb4d219501719e770e

Contents?: true

Size: 1019 Bytes

Versions: 6

Compression:

Stored size: 1019 Bytes

Contents

class LinuxAdmin
  class Rpm < Package
    RPM_CMD = '/usr/bin/rpm'

    def self.list_installed
      out = run!("rpm -qa --qf \"%{NAME} %{VERSION}-%{RELEASE}\n\"").output
      out.split("\n").each_with_object({}) do |line, pkg_hash|
        name, ver = line.split(" ")
        pkg_hash[name] = ver
      end
    end

    def self.info(pkg)
      params = { "-qi" => pkg}
      in_description = false
      out = run!(RPM_CMD, :params => params).output
      out.split("\n").each.with_object({}) do |line, rpm|
        tag,value = line.split(':')
        tag = tag.strip
        if tag == 'Description'
          in_description = true
        elsif in_description
          rpm['description'] ||= ""
          rpm['description'] << line + " "
        else
          tag = tag.downcase.gsub(/\s/, '_')
          rpm[tag] = value.strip
        end
      end
    end

    def self.upgrade(pkg)
      cmd     = "rpm -U"
      params  = { nil => pkg }

      run(cmd, :params => params).exit_status == 0
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
linux_admin-0.5.7 lib/linux_admin/rpm.rb
linux_admin-0.5.6 lib/linux_admin/rpm.rb
linux_admin-0.5.5 lib/linux_admin/rpm.rb
linux_admin-0.5.4 lib/linux_admin/rpm.rb
linux_admin-0.5.3 lib/linux_admin/rpm.rb
linux_admin-0.5.2 lib/linux_admin/rpm.rb