rpm 0.0.0 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/MIT-LICENSE +24 -0
- data/README.rdoc +298 -0
- data/Rakefile +32 -1
- data/lib/rpm/compat.rb +43 -0
- data/lib/rpm/db.rb +125 -0
- data/lib/rpm/dependency.rb +132 -0
- data/lib/rpm/ffi/header.rb +37 -0
- data/lib/rpm/ffi/rpmcallback.rb +26 -0
- data/lib/rpm/ffi/rpmdb.rb +22 -0
- data/lib/rpm/ffi/rpmds.rb +51 -0
- data/lib/rpm/ffi/rpmfi.rb +34 -0
- data/lib/rpm/ffi/rpmlib.rb +15 -0
- data/lib/rpm/ffi/rpmlog.rb +24 -0
- data/lib/rpm/ffi/rpmmacro.rb +38 -0
- data/lib/rpm/ffi/rpmprob.rb +42 -0
- data/lib/rpm/ffi/rpmps.rb +13 -0
- data/lib/rpm/ffi/rpmtag.rb +299 -0
- data/lib/rpm/ffi/rpmtd.rb +37 -0
- data/lib/rpm/ffi/rpmts.rb +70 -0
- data/lib/rpm/ffi/rpmtypes.rb +29 -0
- data/lib/rpm/ffi.rb +44 -0
- data/lib/rpm/file.rb +132 -0
- data/lib/rpm/gem_version.rb +7 -0
- data/lib/rpm/match_iterator.rb +73 -0
- data/lib/rpm/package.rb +344 -0
- data/lib/rpm/transaction.rb +130 -0
- data/lib/rpm/utils.rb +10 -0
- data/lib/rpm/version.rb +154 -1
- data/lib/rpm.rb +74 -3
- data/rpm.gemspec +10 -4
- data/test/data/a.spec +49 -0
- data/test/data/simple-1.0-0.i586.rpm +0 -0
- data/test/data/simple.spec +42 -0
- data/test/helper.rb +7 -0
- data/test/test_dependency.rb +29 -0
- data/test/test_file.rb +12 -0
- data/test/test_lib.rb +36 -0
- data/test/test_package.rb +60 -0
- data/test/test_rpm.rb +37 -0
- data/test/test_transaction.rb +61 -0
- data/test/test_version.rb +63 -0
- metadata +74 -13
- data/README +0 -3
@@ -0,0 +1,130 @@
|
|
1
|
+
require 'rpm'
|
2
|
+
|
3
|
+
module RPM
|
4
|
+
|
5
|
+
class Transaction
|
6
|
+
|
7
|
+
def self.release(ptr)
|
8
|
+
RPM::FFI.rpmtsFree(ptr)
|
9
|
+
end
|
10
|
+
|
11
|
+
def initialize(opts={})
|
12
|
+
|
13
|
+
opts[:root] ||= '/'
|
14
|
+
|
15
|
+
@ptr = ::FFI::AutoPointer.new(RPM::FFI.rpmtsCreate, Transaction.method(:release))
|
16
|
+
RPM::FFI.rpmtsSetRootDir(@ptr, opts[:root])
|
17
|
+
end
|
18
|
+
|
19
|
+
# @return [RPM::MatchIterator] Creates an iterator for +tag+ and +val+
|
20
|
+
def init_iterator(tag, val)
|
21
|
+
raise TypeError if (val && !val.is_a?(String))
|
22
|
+
|
23
|
+
it_ptr = RPM::FFI.rpmtsInitIterator(@ptr, tag.nil? ? 0 : tag, val, 0)
|
24
|
+
|
25
|
+
raise "Can't init iterator for [#{tag}] -> '#{val}'" if it_ptr.null?
|
26
|
+
return MatchIterator.from_ptr(it_ptr)
|
27
|
+
end
|
28
|
+
|
29
|
+
# @visibility private
|
30
|
+
def ptr
|
31
|
+
@ptr
|
32
|
+
end
|
33
|
+
|
34
|
+
#
|
35
|
+
# @yield [Package] Called for each match
|
36
|
+
# @param [Number] key RPM tag key
|
37
|
+
# @param [String] val Value to match
|
38
|
+
# @example
|
39
|
+
# RPM.transaction do |t|
|
40
|
+
# t.each_match(RPM::TAG_ARCH, "x86_64") do |pkg|
|
41
|
+
# puts pkg.name
|
42
|
+
# end
|
43
|
+
# end
|
44
|
+
#
|
45
|
+
def each_match(key, val, &block)
|
46
|
+
it = init_iterator(key, val)
|
47
|
+
|
48
|
+
return it unless block_given?
|
49
|
+
|
50
|
+
it.each(&block)
|
51
|
+
end
|
52
|
+
|
53
|
+
#
|
54
|
+
# @yield [Package] Called for each package in the database
|
55
|
+
# @example
|
56
|
+
# db.each do |pkg|
|
57
|
+
# puts pkg.name
|
58
|
+
# end
|
59
|
+
#
|
60
|
+
def each(&block)
|
61
|
+
each_match(0, nil, &block)
|
62
|
+
end
|
63
|
+
|
64
|
+
# Add a install operation to the transaction
|
65
|
+
# @param [Package] pkg Package to install
|
66
|
+
def install(pkg, key)
|
67
|
+
raise TypeError if not pkg.is_a?(RPM::Package)
|
68
|
+
|
69
|
+
@keys ||= Array.new
|
70
|
+
raise ArgError, "key must be unique" if @keys.include?(key)
|
71
|
+
@keys << key
|
72
|
+
|
73
|
+
RPM::FFI.rpmtsAddInstallElement(@ptr, pkg.ptr, key.to_s, 0, nil)
|
74
|
+
nil
|
75
|
+
end
|
76
|
+
|
77
|
+
# Sets the root directory for this transaction
|
78
|
+
# @param [String] root directory
|
79
|
+
def root_dir=(dir)
|
80
|
+
rc = RPM::FFI.rpmtsSetRootDir(@ptr, dir)
|
81
|
+
raise "Can't set #{dir} as root directory" if rc < 0
|
82
|
+
end
|
83
|
+
|
84
|
+
# @return [String ] the root directory for this transaction
|
85
|
+
def root_dir
|
86
|
+
RPM::FFI.rpmtsRootDir(@ptr)
|
87
|
+
end
|
88
|
+
|
89
|
+
def flags=(fl)
|
90
|
+
RPM::FFI.rpmtsSetFlags(@ptr, fl)
|
91
|
+
end
|
92
|
+
|
93
|
+
def flags
|
94
|
+
RPM::FFI.rpmtsFlags(@ptr)
|
95
|
+
end
|
96
|
+
|
97
|
+
# Performs the transaction.
|
98
|
+
# @param [Number] flag Transaction flags, default +RPM::TRANS_FLAG_NONE+
|
99
|
+
# @param [Number] filter Transaction filter, default +RPM::PROB_FILTER_NONE+
|
100
|
+
# @example
|
101
|
+
# transaction.commit do |sig|
|
102
|
+
# end
|
103
|
+
# @yield [CallbackData] sig Transaction progress
|
104
|
+
def commit
|
105
|
+
self.flags = RPM::FFI::TransFlags[:none]
|
106
|
+
|
107
|
+
callback = Proc.new do |h, what, amount, total, key, data|
|
108
|
+
puts "#{h} #{what} #{amount} #{total} #{key} #{data}"
|
109
|
+
end
|
110
|
+
|
111
|
+
RPM::FFI.rpmtsSetNotifyCallback(@ts, callback, nil)
|
112
|
+
|
113
|
+
rc = RPM::FFI.rpmtsRun(@ptr, nil, :none)
|
114
|
+
|
115
|
+
raise "Transaction Error" if rc < 0
|
116
|
+
|
117
|
+
if rc > 0
|
118
|
+
ps = RPM::FFI.rpmtsProblems(@ptr)
|
119
|
+
psi = RPM::FFI.rpmpsInitIterator(ps)
|
120
|
+
while (RPM::FFI.rpmpsNextIterator(psi) >= 0)
|
121
|
+
problem = RPM::FFI.rpmpsGetProblem(psi)
|
122
|
+
puts RPM::FFI.rpmProblemString.read_string
|
123
|
+
end
|
124
|
+
RPM::FFI.rpmpsFree(ps)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
end
|
129
|
+
|
130
|
+
end
|
data/lib/rpm/utils.rb
ADDED
data/lib/rpm/version.rb
CHANGED
@@ -1,3 +1,156 @@
|
|
1
|
+
require 'rpm'
|
2
|
+
|
1
3
|
module RPM
|
2
|
-
|
4
|
+
|
5
|
+
class Version
|
6
|
+
|
7
|
+
include Comparable
|
8
|
+
|
9
|
+
# Parses a "epoch:version-release" string
|
10
|
+
# @return [Array] tuple [epoch, version, release]
|
11
|
+
def self.parse_evr(evr)
|
12
|
+
raise ArgumentError, "version can't be nil" if evr.nil?
|
13
|
+
version = evr
|
14
|
+
epoch = nil
|
15
|
+
release = nil
|
16
|
+
|
17
|
+
idx = version.rindex(?-)
|
18
|
+
version, release = version[0..idx-1], version[idx+1..-1] if idx
|
19
|
+
|
20
|
+
idx = version.index(/\D/)
|
21
|
+
if (idx && version[idx] == ?:)
|
22
|
+
epoch = version[0..idx-1]
|
23
|
+
version = version[idx+1..-1]
|
24
|
+
end
|
25
|
+
return epoch ? epoch.to_i : nil, version, release
|
26
|
+
end
|
27
|
+
|
28
|
+
#
|
29
|
+
# @overload new(vr, e = nil)
|
30
|
+
# Creates a version object from a string representation
|
31
|
+
# @param [String] vr version and release in the form "v-r"
|
32
|
+
# @param [Number] e epoch
|
33
|
+
# @return [Version]
|
34
|
+
# @overload new(v, r, e = nil)
|
35
|
+
# Creates a version object from a string representation
|
36
|
+
# @param [String] v version
|
37
|
+
# @param [String] r release
|
38
|
+
# @param [Number] e epoch
|
39
|
+
# @return [Version]
|
40
|
+
# @example
|
41
|
+
# RPM:: Version.new "1.0.0-3"
|
42
|
+
# RPM:: Version.new "1.04"
|
43
|
+
# RPM:: Version.new "1.0.0-3k", 1
|
44
|
+
# RPM:: Version.new "2.0.3", "5k"
|
45
|
+
#
|
46
|
+
def initialize(*argv)
|
47
|
+
|
48
|
+
case argv.size
|
49
|
+
when 0
|
50
|
+
raise(ArgumentError "wrong number of arguments (0 for 1..3)")
|
51
|
+
when 1
|
52
|
+
RPM::Utils.check_type(argv[0], String)
|
53
|
+
@e, @v, @r = RPM::Version.parse_evr(argv[0])
|
54
|
+
when 2
|
55
|
+
# (vr, e)
|
56
|
+
RPM::Utils.check_type(argv[0], String)
|
57
|
+
@e, @v, @r = RPM::Version.parse_evr(argv[0])
|
58
|
+
raise(TypeError, "illegal argument value") if not e.nil?
|
59
|
+
@e = argv[1].to_i
|
60
|
+
when 3
|
61
|
+
RPM::Utils.check_type(argv[0], String)
|
62
|
+
RPM::Utils.check_type(argv[1], String)
|
63
|
+
@v = argv[0]
|
64
|
+
@r = argv[1]
|
65
|
+
@e = argv[2].to_i
|
66
|
+
else
|
67
|
+
raise(ArgumentError "too many arguments (#{args.size} for 1..3)")
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
# @return [String] the version component
|
72
|
+
def v
|
73
|
+
@v
|
74
|
+
end
|
75
|
+
|
76
|
+
# @return [String] the release component
|
77
|
+
# or +nil+
|
78
|
+
def r
|
79
|
+
@r
|
80
|
+
end
|
81
|
+
|
82
|
+
# @return [String] the epoch component
|
83
|
+
# or +nil+
|
84
|
+
def e
|
85
|
+
@e
|
86
|
+
end
|
87
|
+
|
88
|
+
# Comparison between versions
|
89
|
+
# @param [Version] other
|
90
|
+
# @return [Number] -1 if +other+ is greater than, 0 if +other+ is equal to,
|
91
|
+
# and +1 if other is less than version.
|
92
|
+
#
|
93
|
+
# @example
|
94
|
+
# v1 = RPM::Version.new("3.0-0",1)
|
95
|
+
# v2 = RPM::Version.new("3.1-0",1)
|
96
|
+
# v1 <=> v2
|
97
|
+
# => -1
|
98
|
+
#
|
99
|
+
def <=>(other)
|
100
|
+
RPM::Utils.check_type(other, RPM::Version)
|
101
|
+
ret = RPM::FFI.rpmvercmp(to_vre_epoch_zero, other.to_vre_epoch_zero)
|
102
|
+
end
|
103
|
+
|
104
|
+
# @param [Version] other Version to compare against
|
105
|
+
# @return [Boolean] true if the version is newer than +other+
|
106
|
+
def newer?(other)
|
107
|
+
(self <=> other) > 0
|
108
|
+
end
|
109
|
+
|
110
|
+
|
111
|
+
# @param [Version] other Version to compare against
|
112
|
+
# @return [Boolean] true if the version is older than +other+
|
113
|
+
def older?(other)
|
114
|
+
! newer?(other)
|
115
|
+
end
|
116
|
+
|
117
|
+
# String representation in the form "v-r"
|
118
|
+
# @return [String]
|
119
|
+
# @note The epoch is not included
|
120
|
+
def to_vr
|
121
|
+
vr = @r.nil? ? "#{@v}" : "#{@v}-#{@r}"
|
122
|
+
end
|
123
|
+
|
124
|
+
# String representation in the form "e:v-r"
|
125
|
+
# @return [String]
|
126
|
+
# @note The epoch is included if present
|
127
|
+
def to_vre(opts={})
|
128
|
+
vr = to_vr
|
129
|
+
vre = @e.nil? ? vr : "#{@e}:#{vr}"
|
130
|
+
end
|
131
|
+
|
132
|
+
# Alias for +to_vr+
|
133
|
+
# @see Version#to_vr
|
134
|
+
def to_s
|
135
|
+
to_vr
|
136
|
+
end
|
137
|
+
|
138
|
+
# Hash based on the version content
|
139
|
+
# @return [String]
|
140
|
+
def hash
|
141
|
+
h = @e.nil? ? 0 : @e;
|
142
|
+
h = (h << 1) ^ @r.hash
|
143
|
+
h = (h << 1) ^ @v.hash
|
144
|
+
end
|
145
|
+
|
146
|
+
# String representation in the form "e:v-r"
|
147
|
+
# @return [String]
|
148
|
+
# @note The epoch is included always. As 0 if not present
|
149
|
+
def to_vre_epoch_zero
|
150
|
+
vr = to_vr
|
151
|
+
vre = @e.nil? ? "0:#{vr}" : "#{@e}:#{vr}"
|
152
|
+
end
|
153
|
+
|
154
|
+
end
|
155
|
+
|
3
156
|
end
|
data/lib/rpm.rb
CHANGED
@@ -1,5 +1,76 @@
|
|
1
|
-
require "rpm/version"
|
2
1
|
|
3
|
-
|
4
|
-
|
2
|
+
require 'rpm/ffi'
|
3
|
+
require 'rpm/package'
|
4
|
+
require 'rpm/db'
|
5
|
+
require 'rpm/transaction'
|
6
|
+
require 'rpm/match_iterator'
|
7
|
+
require 'rpm/version'
|
8
|
+
require 'rpm/dependency'
|
9
|
+
require 'rpm/utils'
|
10
|
+
|
11
|
+
module RPM
|
12
|
+
|
13
|
+
module LibC
|
14
|
+
extend ::FFI::Library
|
15
|
+
ffi_lib ::FFI::Library::LIBC
|
16
|
+
|
17
|
+
# call #attach_function to attach to malloc, free, memcpy, bcopy, etc.
|
18
|
+
attach_function :malloc, [:size_t], :pointer
|
19
|
+
end
|
20
|
+
|
21
|
+
TAG = RPM::FFI::Tag
|
22
|
+
LOG = RPM::FFI::Log
|
23
|
+
SENSE = RPM::FFI::Sense
|
24
|
+
FILE = RPM::FFI::FileAttrs
|
25
|
+
FILE_STATE = RPM::FFI::FileState
|
26
|
+
TRANS_FLAG = RPM::FFI::TransFlags
|
27
|
+
PROB_FILTER = RPM::FFI::ProbFilter
|
28
|
+
MIRE = RPM::FFI::RegexpMode
|
29
|
+
|
30
|
+
# Creates a new transaction and pass it
|
31
|
+
# to the given block
|
32
|
+
#
|
33
|
+
# @param [String] root dir, default '/'
|
34
|
+
#
|
35
|
+
# @example
|
36
|
+
# RPM.transaction do |ts|
|
37
|
+
# ...
|
38
|
+
# end
|
39
|
+
#
|
40
|
+
def self.transaction(root = '/')
|
41
|
+
ts = Transaction.new
|
42
|
+
ts.root_dir = root
|
43
|
+
yield ts
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
# @param [String] name Name of the macro
|
48
|
+
# @return [String] value of macro +name+
|
49
|
+
def self.[](name)
|
50
|
+
val = String.new
|
51
|
+
buffer = ::FFI::MemoryPointer.new(:pointer, 1024)
|
52
|
+
buffer.write_string("%{#{name}}")
|
53
|
+
ret = RPM::FFI.expandMacros(nil, nil, buffer, 1024)
|
54
|
+
buffer.read_string
|
55
|
+
end
|
56
|
+
|
57
|
+
# Setup a macro
|
58
|
+
# @param [String] name Name of the macro
|
59
|
+
# @param [String] value Value of the macro or +nil+ to delete it
|
60
|
+
def self.[]=(name, value)
|
61
|
+
if value.nil?
|
62
|
+
RPM::FFI.delMacro(nil, name.to_s)
|
63
|
+
else
|
64
|
+
RPM::FFI.addMacro(nil, name.to_s, nil, value.to_s, RPM::FFI::RMIL_DEFAULT)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
5
68
|
end
|
69
|
+
|
70
|
+
RPM::FFI.rpmReadConfigFiles(nil, nil)
|
71
|
+
RPM::FFI.rpmInitMacros(nil, RPM::FFI.MACROFILES)
|
72
|
+
|
73
|
+
# TODO
|
74
|
+
# set verbosity
|
75
|
+
|
76
|
+
require 'rpm/compat'
|
data/rpm.gemspec
CHANGED
@@ -1,18 +1,24 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
$:.push File.expand_path("../lib", __FILE__)
|
3
|
-
require "rpm/
|
3
|
+
require "rpm/gem_version"
|
4
4
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = "rpm"
|
7
|
-
s.version = RPM::
|
7
|
+
s.version = RPM::GEM_VERSION
|
8
8
|
s.authors = ["Duncan Mac-Vicar P."]
|
9
9
|
s.email = ["dmacvicar@suse.de"]
|
10
10
|
s.homepage = ""
|
11
|
-
s.summary = %q{
|
12
|
-
s.description = %q{
|
11
|
+
s.summary = %q{Ruby bindings for rpm (package manager)}
|
12
|
+
s.description = %q{Ruby bindings for rpm. Almost a drop-in replacement for ruby-rpm. Uses FFI.}
|
13
|
+
|
14
|
+
s.rubyforge_project = "rpm"
|
13
15
|
|
14
16
|
s.files = `git ls-files`.split("\n")
|
15
17
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
18
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
19
|
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
# specify any dependencies here; for example:
|
22
|
+
# s.add_development_dependency "rspec"
|
23
|
+
s.add_runtime_dependency "ffi"
|
18
24
|
end
|
data/test/data/a.spec
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
Name: a
|
2
|
+
Version: 1.0
|
3
|
+
Release: 0
|
4
|
+
License: GPLv2
|
5
|
+
Summary: Minimal package example
|
6
|
+
Url: http://www.a.com
|
7
|
+
Group: Development
|
8
|
+
Source: a-1.0.tar.gz
|
9
|
+
BuildRequires: c d
|
10
|
+
Provides: something
|
11
|
+
BuildRoot: %{_tmppath}/%{name}-%{version}-build
|
12
|
+
|
13
|
+
%description
|
14
|
+
Description
|
15
|
+
|
16
|
+
%package devel
|
17
|
+
Summary: Development part
|
18
|
+
%description devel
|
19
|
+
Development headers
|
20
|
+
|
21
|
+
%prep
|
22
|
+
%setup -q
|
23
|
+
|
24
|
+
%build
|
25
|
+
%configure
|
26
|
+
make %{?_smp_mflags}
|
27
|
+
|
28
|
+
%install
|
29
|
+
%make_install
|
30
|
+
|
31
|
+
%clean
|
32
|
+
%{?buildroot:%__rm -rf "%{buildroot}"}
|
33
|
+
|
34
|
+
%post
|
35
|
+
|
36
|
+
%postun
|
37
|
+
|
38
|
+
%files
|
39
|
+
%defattr(-,root,root)
|
40
|
+
%doc ChangeLog README COPYING
|
41
|
+
%{_datadir}/a/README
|
42
|
+
|
43
|
+
%files devel
|
44
|
+
%{_includedir}/a.h
|
45
|
+
|
46
|
+
|
47
|
+
|
48
|
+
%changelog
|
49
|
+
|
Binary file
|
@@ -0,0 +1,42 @@
|
|
1
|
+
Name: simple
|
2
|
+
Version: 1.0
|
3
|
+
Release: 0
|
4
|
+
License: GPL
|
5
|
+
Summary: Simple dummy package
|
6
|
+
Summary(es): Paquete simple de muestra
|
7
|
+
Url: http://www.dummmy.com
|
8
|
+
Group: Development
|
9
|
+
BuildRoot: %{_tmppath}/%{name}-%{version}-build
|
10
|
+
|
11
|
+
%description
|
12
|
+
Dummy package
|
13
|
+
|
14
|
+
%description -l es
|
15
|
+
Paquete de muestra
|
16
|
+
|
17
|
+
%prep
|
18
|
+
|
19
|
+
%build
|
20
|
+
mkdir -p %{buildroot}%{_datadir}/%{name}
|
21
|
+
echo "Hello" > %{buildroot}%{_datadir}/%{name}/README
|
22
|
+
echo "Hola" > %{buildroot}%{_datadir}/%{name}/README.es
|
23
|
+
|
24
|
+
%install
|
25
|
+
|
26
|
+
%clean
|
27
|
+
%{?buildroot:%__rm -rf "%{buildroot}"}
|
28
|
+
|
29
|
+
%post
|
30
|
+
|
31
|
+
%postun
|
32
|
+
|
33
|
+
%files
|
34
|
+
%defattr(-,root,root)
|
35
|
+
%{_datadir}/%{name}/README
|
36
|
+
%{_datadir}/%{name}/README.es
|
37
|
+
|
38
|
+
%changelog
|
39
|
+
* Wed Nov 06 2011 Duncan Mac-Vicar P. <dmacvicar@suse.de>
|
40
|
+
- Fix something
|
41
|
+
* Tue Nov 05 2011 Duncan Mac-Vicar P. <dmacvicar@suse.de>
|
42
|
+
- Fix something else
|
data/test/helper.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'helper')
|
2
|
+
require 'rpm/compat'
|
3
|
+
|
4
|
+
class RPM_Dependency_Tests < Test::Unit::TestCase
|
5
|
+
|
6
|
+
EQ = RPM::SENSE_EQUAL
|
7
|
+
LT = RPM::SENSE_LESS
|
8
|
+
GT = RPM::SENSE_GREATER
|
9
|
+
|
10
|
+
def test_satisfy
|
11
|
+
prv = provides("foo", "2", "1", 0, EQ)
|
12
|
+
req = requires("foo", "1", "1", 0, EQ|GT)
|
13
|
+
assert(req.satisfy?(prv))
|
14
|
+
assert(prv.satisfy?(req))
|
15
|
+
|
16
|
+
# Different names don't overlap
|
17
|
+
prv = provides("foo", "2", "1", 0, EQ)
|
18
|
+
req = requires("bar", "1", "1", 0, EQ|GT)
|
19
|
+
assert(! req.satisfy?(prv))
|
20
|
+
end
|
21
|
+
|
22
|
+
def provides(name, v, r, e, sense)
|
23
|
+
RPM::Provide.new(name, RPM::Version.new(v, r, e), sense, nil)
|
24
|
+
end
|
25
|
+
|
26
|
+
def requires(name, v, r, e, sense)
|
27
|
+
RPM::Require.new(name, RPM::Version.new(v, r, e), sense, nil)
|
28
|
+
end
|
29
|
+
end
|
data/test/test_file.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'helper')
|
2
|
+
|
3
|
+
class RPM_File_Tests < Test::Unit::TestCase
|
4
|
+
def test_link_to
|
5
|
+
f = RPM::File.new("path", "md5sum", nil, 42, 1,
|
6
|
+
"owner", "group", 43, 0777, 44, 45)
|
7
|
+
assert_equal(nil, f.link_to)
|
8
|
+
f = RPM::File.new("path", "md5sum", "link_to", 42, 1,
|
9
|
+
"owner", "group", 43, 0777, 44, 45)
|
10
|
+
assert_equal("link_to", f.link_to)
|
11
|
+
end
|
12
|
+
end
|
data/test/test_lib.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'helper')
|
2
|
+
|
3
|
+
class RPM_Lib_Tests < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_lib_lib
|
6
|
+
assert_kind_of String, RPM::FFI.RPMVERSION
|
7
|
+
# "x.y.z"
|
8
|
+
assert(RPM::FFI.RPMVERSION.size >= 5)
|
9
|
+
assert_kind_of Fixnum, RPM::FFI.rpm_version_code
|
10
|
+
# >= 4.0.0
|
11
|
+
assert(RPM::FFI.rpm_version_code >= ((4 << 16) + (0 << 8) + (0 << 0)))
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_lib_header
|
15
|
+
ptr = RPM::FFI.headerNew
|
16
|
+
RPM::FFI.headerFree(ptr)
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_lib_ts
|
20
|
+
ts = RPM::FFI.rpmtsCreate
|
21
|
+
RPM::FFI.rpmtsSetRootDir(ts, "/")
|
22
|
+
it = RPM::FFI.rpmtsInitIterator(ts, 0, nil, 0)
|
23
|
+
hdrs = []
|
24
|
+
while (not (hdr = RPM::FFI.rpmdbNextIterator(it)).null?)
|
25
|
+
hdrs << hdr
|
26
|
+
assert_kind_of String, RPM::FFI.headerGetAsString(hdr, :name)
|
27
|
+
end
|
28
|
+
RPM::FFI.rpmdbFreeIterator(it)
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_lib_macros
|
33
|
+
assert_kind_of String, RPM::FFI.MACROFILES
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'helper')
|
2
|
+
|
3
|
+
class RPM_Header_Tests < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_create
|
6
|
+
|
7
|
+
pkg = RPM::Package.create('foo', RPM::Version.new('1.0'))
|
8
|
+
assert_equal 'foo', pkg.name
|
9
|
+
assert_equal '(none)', pkg.signature
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_open
|
13
|
+
|
14
|
+
pkg = RPM::Package.open(fixture('simple-1.0-0.i586.rpm'))
|
15
|
+
|
16
|
+
req = RPM::Require.new("simple", RPM::Version.new("1.0", "0"), RPM::SENSE_GREATER|RPM::SENSE_EQUAL, nil)
|
17
|
+
assert req.satisfy?(pkg)
|
18
|
+
|
19
|
+
assert_equal "simple-1.0-0-i586", pkg.to_s
|
20
|
+
|
21
|
+
assert_equal '6895248ed5a081f73d035174329169c7', pkg.signature
|
22
|
+
|
23
|
+
assert_kind_of RPM::Package, pkg
|
24
|
+
assert_equal 'simple', pkg[:name]
|
25
|
+
assert_equal 'i586', pkg[:arch]
|
26
|
+
assert_kind_of RPM::Version, pkg.version
|
27
|
+
assert_equal '1.0-0', pkg.version.to_s
|
28
|
+
|
29
|
+
backup_lang = ENV['LANG']
|
30
|
+
|
31
|
+
ENV['LANG'] = 'C'
|
32
|
+
assert_equal 'Simple dummy package', pkg[:summary]
|
33
|
+
assert_equal 'Dummy package', pkg[:description]
|
34
|
+
|
35
|
+
ENV['LANG'] = 'es'
|
36
|
+
assert_equal 'Paquete simple de muestra', pkg[:summary]
|
37
|
+
assert_equal 'Paquete de muestra', pkg[:description]
|
38
|
+
|
39
|
+
ENV['LANG'] = backup_lang
|
40
|
+
|
41
|
+
# Arrays
|
42
|
+
assert_equal ["root", "root"], pkg[:fileusername]
|
43
|
+
assert_equal [6, 5], pkg[:filesizes]
|
44
|
+
|
45
|
+
assert pkg.provides.map(&:name).include?("simple(x86-32)")
|
46
|
+
assert pkg.provides.map(&:name).include?("simple")
|
47
|
+
|
48
|
+
assert pkg.requires.map(&:name).include?("/bin/sh")
|
49
|
+
|
50
|
+
assert pkg.files.map(&:path).include?("/usr/share/simple/README")
|
51
|
+
assert pkg.files.map(&:path).include?("/usr/share/simple/README.es")
|
52
|
+
|
53
|
+
file = pkg.files.select {|x| x.path == "/usr/share/simple/README" }.first
|
54
|
+
assert_nil file.link_to
|
55
|
+
assert !file.symlink?
|
56
|
+
|
57
|
+
assert_equal ["- Fix something", "- Fix something else"], pkg.changelog.map(&:text)
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
data/test/test_rpm.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'helper')
|
2
|
+
|
3
|
+
class RPM_RPM_Tests < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_enum
|
6
|
+
assert RPM::TAG[:not_found]
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_compat
|
10
|
+
#puts RPM::LOG_ALERT
|
11
|
+
#assert_raise(NameError) { RPM::LOG_ALERT }
|
12
|
+
|
13
|
+
#require 'rpm/compat'
|
14
|
+
assert_nothing_raised { RPM::LOG_ALERT }
|
15
|
+
assert_equal RPM::LOG_ALERT, RPM::LOG[:alert]
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_iterator
|
19
|
+
RPM.transaction do |t|
|
20
|
+
assert_kind_of RPM::Transaction, t
|
21
|
+
#t.each do |pkg|
|
22
|
+
# puts pkg[:name]
|
23
|
+
#end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_macro_read
|
28
|
+
assert_equal '/usr', RPM['_usr']
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_macro_write
|
32
|
+
RPM['hoge'] = 'hoge'
|
33
|
+
assert_equal( RPM['hoge'], 'hoge' )
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
end # class RPM_RPM_Tests < Test::Unit::TestCase
|