Class: RPMdb

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

Overview

module RPM

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root = '') ⇒ RPMdb

def each



163
164
165
# File 'lib/rpm.rb', line 163

def initialize(root='')
  @db = RPM::DB.new false, root
end

Class Method Details

.open(root = '') ⇒ Object



80
81
82
# File 'lib/rpm.rb', line 80

def RPMdb.open(root='')
  RPMdb.new root
end

Instance Method Details

#closeObject

def RPMdb.open(root=”)



84
85
86
87
# File 'lib/rpm.rb', line 84

def close
  @db = nil
  GC.start
end

#eachObject

def requires(name)

Raises:

  • (RuntimeError)


156
157
158
159
160
161
# File 'lib/rpm.rb', line 156

def each
  raise RuntimeError, 'closed DB' if @db.nil?
  @db.each do |pkg|
    yield pkg.name, pkg.version.v, pkg.version.r
  end
end

#file(filespec) ⇒ Object

def close

Raises:

  • (RuntimeError)


89
90
91
92
93
94
95
96
# File 'lib/rpm.rb', line 89

def file(filespec)
  raise RuntimeError, 'closed DB' if @db.nil?
  pkgs = []
  @db.each_match(RPM::TAG_BASENAMES, filespec) do |pkg|
    [pkg.name, pkg.version.v, pkg.version.r]
  end
  pkgs
end

#group(groupname) ⇒ Object

def file(filespec)

Raises:

  • (RuntimeError)


98
99
100
101
102
103
104
105
# File 'lib/rpm.rb', line 98

def group(groupname)
  raise RuntimeError, 'closed DB' if @db.nil?
  pkgs = []
  @db.each_match(RPM::TAG_GROUP, groupname) do |pkg|
    pkgs << [pkg.name, pkg.version.v, pkg.version.r]
  end
  pkgs
end

#package(packagename) ⇒ Object

def group(groupname)

Raises:

  • (RuntimeError)


107
108
109
110
111
112
113
114
# File 'lib/rpm.rb', line 107

def package(packagename)
  raise RuntimeError, 'closed DB' if @db.nil?
  pkgs = []
  @db.each_match(RPM::DBI_LABEL, packagename) do |pkg|
    pkgs << [pkg.name, pkg.version.v, pkg.version.r]
  end
  pkgs
end

#provides(name) ⇒ Object

def whatrequires(caps)

Raises:

  • (RuntimeError)


134
135
136
137
138
139
140
141
142
143
# File 'lib/rpm.rb', line 134

def provides(name)
  raise RuntimeError, 'closed DB' if @db.nil?
  pkg = nil
  @db.each_match(RPM::DBI_LABEL, name) {|p| pkg = p}
  if pkg then
    pkg.provides.collect {|prov| prov.name }
  else
    []
  end
end

#requires(name) ⇒ Object

def provides(name)

Raises:

  • (RuntimeError)


145
146
147
148
149
150
151
152
153
154
# File 'lib/rpm.rb', line 145

def requires(name)
  raise RuntimeError, 'closed DB' if @db.nil?
  pkg = nil
  @db.each_match(RPM::DBI_LABEL, name) {|p| pkg = p; break}
  if pkg then
    pkg.requires.collect {|req| [req.name, req.version.v, req.version.r] }
  else
    []
  end
end

#whatprovides(caps) ⇒ Object

def package(packagename)

Raises:

  • (RuntimeError)


116
117
118
119
120
121
122
123
# File 'lib/rpm.rb', line 116

def whatprovides(caps)
  raise RuntimeError, 'closed DB' if @db.nil?
  pkgs = []
  @db.each_match(RPM::TAG_PROVIDENAME, caps) do |pkg|
    pkgs << [pkg.name, pkg.version.v, pkg.version.r]
  end
  pkgs
end

#whatrequires(caps) ⇒ Object

def whatprovides(caps)

Raises:

  • (RuntimeError)


125
126
127
128
129
130
131
132
# File 'lib/rpm.rb', line 125

def whatrequires(caps)
  raise RuntimeError, 'closed DB' if @db.nil?
  pkgs = []
  @db.each_match(RPM::TAG_REQUIRENAME, caps) do |pkg|
    pkgs << [pkg.name, pkg.version.v, pkg.version.r]
  end
  pkgs
end