Module: RPMUtils

Defined in:
lib/rpm-utils.rb

Class Method Summary collapse

Class Method Details

.find_rpms(name_regexp) ⇒ Object

Return a list of packages matched by the regexp May return an empty []


32
33
34
# File 'lib/rpm-utils.rb', line 32

def find_rpms(name_regexp)
  pkgs = `rpm -qa | grep -E '#{regexp}'`.split
end

.parse_rpm_name(rpm) ⇒ Object


9
10
11
12
13
14
15
16
17
18
# File 'lib/rpm-utils.rb', line 9

def parse_rpm_name(rpm)
  fname = rpm.strip.chomp.gsub /\.rpm$/, ''
  tokens = fname.split('-')
  arch_rel = tokens.pop.split('.')
  arch = arch_rel.pop
  release = arch_rel.join('.')
  version = tokens.pop
  name = tokens.join '-'
  return name, version, release, arch
end

.rpm_installed?(pkg_name) ⇒ Boolean

Returns:

  • (Boolean)

36
37
38
39
# File 'lib/rpm-utils.rb', line 36

def rpm_installed?(pkg_name)
  return true if not `rpm -q #{pkg_name}|grep -v "not installed"`.empty?
  false
end

.valid_rpm_name?(rpm) ⇒ Boolean

Returns:

  • (Boolean)

20
21
22
23
24
25
26
# File 'lib/rpm-utils.rb', line 20

def valid_rpm_name?(rpm)
  return false if rpm !~ /\.rpm$/
  parse_rpm_name(rpm).each do |c|
    return false if (c.nil? or c.empty?)
  end
  true
end