apt-pkg 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +3 -0
- data/History.md +55 -0
- data/LICENSE +22 -0
- data/README.md +63 -0
- data/ext/apt_pkg/apt-pkg.cpp +249 -0
- data/ext/apt_pkg/apt-pkg.h +26 -0
- data/ext/apt_pkg/configuration.cpp +190 -0
- data/ext/apt_pkg/configuration.h +5 -0
- data/ext/apt_pkg/extconf.rb +5 -0
- data/ext/apt_pkg/pkgcache.cpp +406 -0
- data/ext/apt_pkg/pkgcache.h +8 -0
- data/lib/debian/apt_pkg.rb +4 -0
- data/lib/debian/apt_pkg/gem_version.rb +9 -0
- data/lib/debian/apt_pkg/package.rb +47 -0
- data/test/apt_pkg_cache_not_init_integration.rb +24 -0
- data/test/apt_pkg_configuration_test.rb +78 -0
- data/test/apt_pkg_test.rb +134 -0
- data/test/debian/apt_pkg/package_test.rb +56 -0
- data/test/debian/apt_pkg/pkg_cache_test.rb +114 -0
- data/test/test_helper.rb +6 -0
- metadata +111 -0
@@ -0,0 +1,406 @@
|
|
1
|
+
#include "pkgcache.h"
|
2
|
+
|
3
|
+
static VALUE e_mDebianAptPkgInitError, rb_cPackage, rb_cVersion;
|
4
|
+
|
5
|
+
/*
|
6
|
+
* private
|
7
|
+
*/
|
8
|
+
bool
|
9
|
+
config_system_initialized()
|
10
|
+
{
|
11
|
+
string const arch = _config->Find("APT::Architecture");
|
12
|
+
if (arch.empty()) {
|
13
|
+
return false;
|
14
|
+
}
|
15
|
+
return true;
|
16
|
+
}
|
17
|
+
|
18
|
+
/*
|
19
|
+
* call-seq: gen_caches() -> bool
|
20
|
+
*
|
21
|
+
* Call the main cache generator.
|
22
|
+
* Raise `Debian::AptPkg::InitError` when config, system, cache is not
|
23
|
+
* configured.
|
24
|
+
*
|
25
|
+
* Debian::AptPkg::PkgCache.gen_caches # => false
|
26
|
+
*
|
27
|
+
**/
|
28
|
+
static VALUE
|
29
|
+
gen_caches(VALUE self)
|
30
|
+
{
|
31
|
+
if (!config_system_initialized()) {
|
32
|
+
rb_raise(e_mDebianAptPkgInitError, "System not initialized");
|
33
|
+
}
|
34
|
+
pkgCacheFile CacheFile;
|
35
|
+
int res = CacheFile.BuildCaches(NULL, true);
|
36
|
+
return INT2BOOL(res);
|
37
|
+
}
|
38
|
+
|
39
|
+
/*
|
40
|
+
* call-seq: update() -> bool
|
41
|
+
*
|
42
|
+
* Update the index files used by the cache.
|
43
|
+
* Raise `Debian::AptPkg::InitError` when config, system, cache is not
|
44
|
+
* configured.
|
45
|
+
*
|
46
|
+
* Debian::AptPkg::PkgCache.update # => false
|
47
|
+
*
|
48
|
+
**/
|
49
|
+
static VALUE
|
50
|
+
update(VALUE self)
|
51
|
+
{
|
52
|
+
if (!config_system_initialized()) {
|
53
|
+
rb_raise(e_mDebianAptPkgInitError, "System not initialized");
|
54
|
+
}
|
55
|
+
pkgCacheFile CacheFile;
|
56
|
+
// Get the source list
|
57
|
+
if (CacheFile.BuildSourceList() == false) {
|
58
|
+
return Qnil;
|
59
|
+
}
|
60
|
+
pkgAcquireStatus *Stat(NULL);
|
61
|
+
pkgSourceList *List = CacheFile.GetSourceList();
|
62
|
+
int res = ListUpdate(*Stat, *List);
|
63
|
+
return INT2BOOL(res);
|
64
|
+
}
|
65
|
+
|
66
|
+
/*
|
67
|
+
* call-seq: is_multi_arch() -> bool
|
68
|
+
*
|
69
|
+
* An attribute determining whether the cache supports multi-arch.
|
70
|
+
* Raise `Debian::AptPkg::InitError` when config, system, cache is not
|
71
|
+
* configured.
|
72
|
+
*
|
73
|
+
* Debian::AptPkg::PkgCache.is_multi_arch # => false
|
74
|
+
*
|
75
|
+
**/
|
76
|
+
static VALUE
|
77
|
+
is_multi_arch(VALUE self)
|
78
|
+
{
|
79
|
+
if (!config_system_initialized()) {
|
80
|
+
rb_raise(e_mDebianAptPkgInitError, "System not initialized");
|
81
|
+
}
|
82
|
+
pkgCacheFile CacheFile;
|
83
|
+
pkgCache *Cache = CacheFile.GetPkgCache();
|
84
|
+
if (Cache == NULL) {
|
85
|
+
return Qnil;
|
86
|
+
}
|
87
|
+
int res = Cache->MultiArchCache();
|
88
|
+
return INT2BOOL(res);
|
89
|
+
}
|
90
|
+
|
91
|
+
/*
|
92
|
+
* call-seq: packages() -> array, nil
|
93
|
+
*
|
94
|
+
* A list of Debian::AptPkg::Package objects stored in the cache
|
95
|
+
* Raise `Debian::AptPkg::InitError` when config, system, cache is not
|
96
|
+
* configured.
|
97
|
+
*
|
98
|
+
* Debian::AptPkg::PkgCache.packages
|
99
|
+
*
|
100
|
+
**/
|
101
|
+
static VALUE
|
102
|
+
packages(int argc, VALUE *argv, VALUE self)
|
103
|
+
{
|
104
|
+
if (!config_system_initialized()) {
|
105
|
+
rb_raise(e_mDebianAptPkgInitError, "System not initialized");
|
106
|
+
}
|
107
|
+
VALUE result = rb_ary_new();
|
108
|
+
pkgCacheFile CacheFile;
|
109
|
+
if (CacheFile.GetPkgCache() == 0) {
|
110
|
+
return Qnil;
|
111
|
+
}
|
112
|
+
for (pkgCache::PkgIterator Pkg = CacheFile.GetPkgCache()->PkgBegin(); not Pkg.end(); ++Pkg) {
|
113
|
+
VALUE current_version;
|
114
|
+
if (Pkg->CurrentVer == 0) {
|
115
|
+
current_version = Qnil;
|
116
|
+
} else {
|
117
|
+
current_version = rb_struct_new(rb_cVersion,
|
118
|
+
rb_str_new2(Pkg.CurrentVer().ParentPkg().Name()),
|
119
|
+
rb_str_new2(Pkg.CurrentVer().VerStr()),
|
120
|
+
rb_str_new2(Pkg.CurrentVer().Section()),
|
121
|
+
rb_str_new2(Pkg.CurrentVer().Arch()),
|
122
|
+
INT2FIX(Pkg.CurrentVer()->Size),
|
123
|
+
INT2FIX(Pkg.CurrentVer()->InstalledSize),
|
124
|
+
INT2FIX(Pkg.CurrentVer()->Hash),
|
125
|
+
INT2FIX(Pkg.CurrentVer()->ID),
|
126
|
+
INT2FIX(Pkg.CurrentVer()->Priority)
|
127
|
+
);
|
128
|
+
}
|
129
|
+
VALUE rb_cPackage_args[7];
|
130
|
+
rb_cPackage_args[0] = INT2FIX(Pkg->ID);
|
131
|
+
rb_cPackage_args[1] = rb_str_new2(Pkg.Name());
|
132
|
+
rb_cPackage_args[2] = rb_str_new2(Pkg.FullName().c_str());
|
133
|
+
rb_cPackage_args[3] = rb_str_new2(Pkg.Arch());
|
134
|
+
rb_cPackage_args[4] = INT2BOOL((Pkg->Flags & pkgCache::Flag::Essential) != 0);
|
135
|
+
rb_cPackage_args[5] = INT2BOOL((Pkg->Flags & pkgCache::Flag::Important) != 0);
|
136
|
+
rb_cPackage_args[6] = current_version;
|
137
|
+
rb_ary_push(result, rb_class_new_instance(7,
|
138
|
+
rb_cPackage_args,
|
139
|
+
rb_cPackage
|
140
|
+
));
|
141
|
+
}
|
142
|
+
return result;
|
143
|
+
}
|
144
|
+
|
145
|
+
/*
|
146
|
+
* call-seq: pkg_names() -> array, nil
|
147
|
+
*
|
148
|
+
* Deprecated and will removed in 0.6.0
|
149
|
+
* List the names of all packages in the system.
|
150
|
+
* Raise `Debian::AptPkg::InitError` when config, system, cache is not
|
151
|
+
* configured.
|
152
|
+
*
|
153
|
+
* Debian::AptPkg::PkgCache.pkg_names('gcolor2') # => ["gcolor2"]
|
154
|
+
*
|
155
|
+
**/
|
156
|
+
static VALUE
|
157
|
+
pkg_names(int argc, VALUE *argv, VALUE self)
|
158
|
+
{
|
159
|
+
rb_warn("Debian::AptPkg::PkgCache.pkg_names is deprecated; " \
|
160
|
+
"use Debian::AptPkg::PkgCache.packages instead");
|
161
|
+
if (!config_system_initialized()) {
|
162
|
+
rb_raise(e_mDebianAptPkgInitError, "System not initialized");
|
163
|
+
}
|
164
|
+
if (argc > 1 || argc == 0) {
|
165
|
+
rb_raise(rb_eArgError, "You must give at least one search argument");
|
166
|
+
}
|
167
|
+
VALUE name;
|
168
|
+
rb_scan_args(argc, argv, "01", &name);
|
169
|
+
if (NIL_P(name) || RSTRING_LEN(name) < 1) {
|
170
|
+
rb_raise(rb_eArgError, "You must give at least one search pattern");
|
171
|
+
}
|
172
|
+
VALUE result = rb_ary_new();
|
173
|
+
|
174
|
+
pkgCacheFile CacheFile;
|
175
|
+
if (CacheFile.GetPkgCache() == 0) {
|
176
|
+
return Qnil;
|
177
|
+
}
|
178
|
+
pkgCache::GrpIterator I = CacheFile.GetPkgCache()->GrpBegin();
|
179
|
+
|
180
|
+
const char *pkgname = StringValuePtr(name);
|
181
|
+
for (; I.end() != true; ++I) {
|
182
|
+
if (strncmp(I.Name(), pkgname, strlen(pkgname)) == 0) {
|
183
|
+
rb_ary_push(result, rb_str_new2(I.Name()));
|
184
|
+
}
|
185
|
+
}
|
186
|
+
return result;
|
187
|
+
}
|
188
|
+
|
189
|
+
/*
|
190
|
+
* call-seq: package_count() -> int, nil
|
191
|
+
*
|
192
|
+
* The total number of packages available in the cache.
|
193
|
+
* Raise `Debian::AptPkg::InitError` when config, system, cache is not
|
194
|
+
* configured.
|
195
|
+
*
|
196
|
+
* Debian::AptPkg::PkgCache.package_count # => 69511
|
197
|
+
*
|
198
|
+
**/
|
199
|
+
static VALUE
|
200
|
+
package_count(VALUE self)
|
201
|
+
{
|
202
|
+
if (!config_system_initialized()) {
|
203
|
+
rb_raise(e_mDebianAptPkgInitError, "System not initialized");
|
204
|
+
}
|
205
|
+
pkgCacheFile CacheFile;
|
206
|
+
pkgCache *Cache = CacheFile.GetPkgCache();
|
207
|
+
if (Cache == NULL) {
|
208
|
+
return Qnil;
|
209
|
+
}
|
210
|
+
return INT2FIX(Cache->HeaderP->PackageCount);
|
211
|
+
}
|
212
|
+
|
213
|
+
/*
|
214
|
+
* call-seq: version_count() -> int, nil
|
215
|
+
*
|
216
|
+
* The total number of package versions available in the cache.
|
217
|
+
* Raise `Debian::AptPkg::InitError` when config, system, cache is not
|
218
|
+
* configured.
|
219
|
+
*
|
220
|
+
* Debian::AptPkg::PkgCache.version_count # => 84630
|
221
|
+
*
|
222
|
+
**/
|
223
|
+
static VALUE
|
224
|
+
version_count(VALUE self)
|
225
|
+
{
|
226
|
+
if (!config_system_initialized()) {
|
227
|
+
rb_raise(e_mDebianAptPkgInitError, "System not initialized");
|
228
|
+
}
|
229
|
+
pkgCacheFile CacheFile;
|
230
|
+
pkgCache *Cache = CacheFile.GetPkgCache();
|
231
|
+
if (Cache == NULL) {
|
232
|
+
return Qnil;
|
233
|
+
}
|
234
|
+
return INT2FIX(Cache->HeaderP->VersionCount);
|
235
|
+
}
|
236
|
+
|
237
|
+
/*
|
238
|
+
* call-seq: depends_count() -> int, nil
|
239
|
+
*
|
240
|
+
* The total number of dependencies stored in the cache.
|
241
|
+
* Raise `Debian::AptPkg::InitError` when config, system, cache is not
|
242
|
+
* configured.
|
243
|
+
*
|
244
|
+
* Debian::AptPkg::PkgCache.depends_count # => 551983
|
245
|
+
*
|
246
|
+
**/
|
247
|
+
static VALUE
|
248
|
+
depends_count(VALUE self)
|
249
|
+
{
|
250
|
+
if (!config_system_initialized()) {
|
251
|
+
rb_raise(e_mDebianAptPkgInitError, "System not initialized");
|
252
|
+
}
|
253
|
+
pkgCacheFile CacheFile;
|
254
|
+
pkgCache *Cache = CacheFile.GetPkgCache();
|
255
|
+
if (Cache == NULL) {
|
256
|
+
return Qnil;
|
257
|
+
}
|
258
|
+
return INT2FIX(Cache->HeaderP->DependsCount);
|
259
|
+
}
|
260
|
+
|
261
|
+
/*
|
262
|
+
* call-seq: package_file_count() -> int, nil
|
263
|
+
*
|
264
|
+
* The total number of packages files available.
|
265
|
+
* Raise `Debian::AptPkg::InitError` when config, system, cache is not
|
266
|
+
* configured.
|
267
|
+
*
|
268
|
+
* Debian::AptPkg::PkgCache.package_file_count # => 17
|
269
|
+
*
|
270
|
+
**/
|
271
|
+
static VALUE
|
272
|
+
package_file_count(VALUE self)
|
273
|
+
{
|
274
|
+
if (!config_system_initialized()) {
|
275
|
+
rb_raise(e_mDebianAptPkgInitError, "System not initialized");
|
276
|
+
}
|
277
|
+
pkgCacheFile CacheFile;
|
278
|
+
pkgCache *Cache = CacheFile.GetPkgCache();
|
279
|
+
if (Cache == NULL) {
|
280
|
+
return Qnil;
|
281
|
+
}
|
282
|
+
return INT2FIX(Cache->HeaderP->PackageFileCount);
|
283
|
+
}
|
284
|
+
|
285
|
+
/*
|
286
|
+
* call-seq: ver_file_count() -> int, nil
|
287
|
+
*
|
288
|
+
* The total number of version and package file relations stored in the cache.
|
289
|
+
* Raise `Debian::AptPkg::InitError` when config, system, cache is not
|
290
|
+
* configured.
|
291
|
+
*
|
292
|
+
* Debian::AptPkg::PkgCache.ver_file_count # => 11274
|
293
|
+
*
|
294
|
+
**/
|
295
|
+
static VALUE
|
296
|
+
ver_file_count(VALUE self)
|
297
|
+
{
|
298
|
+
if (!config_system_initialized()) {
|
299
|
+
rb_raise(e_mDebianAptPkgInitError, "System not initialized");
|
300
|
+
}
|
301
|
+
pkgCacheFile CacheFile;
|
302
|
+
pkgCache *Cache = CacheFile.GetPkgCache();
|
303
|
+
if (Cache == NULL) {
|
304
|
+
return Qnil;
|
305
|
+
}
|
306
|
+
return INT2FIX(Cache->HeaderP->VerFileCount);
|
307
|
+
}
|
308
|
+
|
309
|
+
/*
|
310
|
+
* call-seq: provides_count() -> int, nil
|
311
|
+
*
|
312
|
+
* The number of provided packages.
|
313
|
+
* Raise `Debian::AptPkg::InitError` when config, system, cache is not
|
314
|
+
* configured.
|
315
|
+
*
|
316
|
+
* Debian::AptPkg::PkgCache.provides_count # => 69511
|
317
|
+
*
|
318
|
+
**/
|
319
|
+
static VALUE
|
320
|
+
provides_count(VALUE self)
|
321
|
+
{
|
322
|
+
if (!config_system_initialized()) {
|
323
|
+
rb_raise(e_mDebianAptPkgInitError, "System not initialized");
|
324
|
+
}
|
325
|
+
pkgCacheFile CacheFile;
|
326
|
+
pkgCache *Cache = CacheFile.GetPkgCache();
|
327
|
+
if (Cache == NULL) {
|
328
|
+
return Qnil;
|
329
|
+
}
|
330
|
+
return INT2FIX(Cache->HeaderP->ProvidesCount);
|
331
|
+
}
|
332
|
+
|
333
|
+
/*
|
334
|
+
* call-seq: group_count() -> int, nil
|
335
|
+
*
|
336
|
+
* The number of groups in the cache.
|
337
|
+
* Raise `Debian::AptPkg::InitError` when config, system, cache is not
|
338
|
+
* configured.
|
339
|
+
*
|
340
|
+
* Debian::AptPkg::PkgCache.group_count # => 16730
|
341
|
+
*
|
342
|
+
**/
|
343
|
+
static VALUE
|
344
|
+
group_count(VALUE self)
|
345
|
+
{
|
346
|
+
if (!config_system_initialized()) {
|
347
|
+
rb_raise(e_mDebianAptPkgInitError, "System not initialized");
|
348
|
+
}
|
349
|
+
pkgCacheFile CacheFile;
|
350
|
+
pkgCache *Cache = CacheFile.GetPkgCache();
|
351
|
+
if (Cache == NULL) {
|
352
|
+
return Qnil;
|
353
|
+
}
|
354
|
+
return INT2FIX(Cache->HeaderP->GroupCount);
|
355
|
+
}
|
356
|
+
|
357
|
+
void
|
358
|
+
init_apt_pkg_pkgcache()
|
359
|
+
{
|
360
|
+
VALUE rb_mDebian = rb_define_module("Debian");
|
361
|
+
VALUE rb_mDebianAptPkg = rb_define_module_under(rb_mDebian, "AptPkg");
|
362
|
+
VALUE rb_mDebianAptPkgCache = rb_define_module_under(rb_mDebianAptPkg,
|
363
|
+
"PkgCache");
|
364
|
+
e_mDebianAptPkgInitError = rb_define_class_under(rb_mDebianAptPkg,
|
365
|
+
"InitError",
|
366
|
+
rb_eRuntimeError);
|
367
|
+
rb_cPackage = rb_const_get_at(rb_mDebianAptPkg, rb_intern("Package"));
|
368
|
+
rb_cVersion = rb_struct_define_under(rb_mDebianAptPkg, "Version",
|
369
|
+
"parent_package_name",
|
370
|
+
"version_string",
|
371
|
+
"section",
|
372
|
+
"arch",
|
373
|
+
"size",
|
374
|
+
"installed_size",
|
375
|
+
"hash",
|
376
|
+
"id",
|
377
|
+
"priority",
|
378
|
+
NULL);
|
379
|
+
|
380
|
+
rb_define_singleton_method(rb_mDebianAptPkgCache, "gen_caches",
|
381
|
+
RUBY_METHOD_FUNC(gen_caches), 0);
|
382
|
+
rb_define_singleton_method(rb_mDebianAptPkgCache, "update",
|
383
|
+
RUBY_METHOD_FUNC(update), 0);
|
384
|
+
rb_define_singleton_method(rb_mDebianAptPkgCache, "is_multi_arch",
|
385
|
+
RUBY_METHOD_FUNC(is_multi_arch), 0);
|
386
|
+
rb_define_singleton_method(rb_mDebianAptPkgCache, "packages",
|
387
|
+
RUBY_METHOD_FUNC(packages), 0);
|
388
|
+
rb_define_singleton_method(rb_mDebianAptPkgCache, "pkg_names",
|
389
|
+
RUBY_METHOD_FUNC(pkg_names), -1);
|
390
|
+
|
391
|
+
rb_define_singleton_method(rb_mDebianAptPkgCache, "package_count",
|
392
|
+
RUBY_METHOD_FUNC(package_count), 0);
|
393
|
+
rb_define_singleton_method(rb_mDebianAptPkgCache, "version_count",
|
394
|
+
RUBY_METHOD_FUNC(version_count), 0);
|
395
|
+
rb_define_singleton_method(rb_mDebianAptPkgCache, "depends_count",
|
396
|
+
RUBY_METHOD_FUNC(depends_count), 0);
|
397
|
+
rb_define_singleton_method(rb_mDebianAptPkgCache,
|
398
|
+
"package_file_count",
|
399
|
+
RUBY_METHOD_FUNC(package_file_count), 0);
|
400
|
+
rb_define_singleton_method(rb_mDebianAptPkgCache, "ver_file_count",
|
401
|
+
RUBY_METHOD_FUNC(ver_file_count), 0);
|
402
|
+
rb_define_singleton_method(rb_mDebianAptPkgCache, "provides_count",
|
403
|
+
RUBY_METHOD_FUNC(provides_count), 0);
|
404
|
+
rb_define_singleton_method(rb_mDebianAptPkgCache, "group_count",
|
405
|
+
RUBY_METHOD_FUNC(group_count), 0);
|
406
|
+
}
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# Debian::AptPkg::Package file
|
3
|
+
module Debian
|
4
|
+
# AptPkg base module
|
5
|
+
module AptPkg
|
6
|
+
# Debian::AptPkg::Package class
|
7
|
+
# Representation of a package in a cache
|
8
|
+
class Package
|
9
|
+
attr_accessor :id, :name, :full_name, :arch, :essential, :important,
|
10
|
+
:current_version
|
11
|
+
|
12
|
+
# Initialize the Package class
|
13
|
+
# @example
|
14
|
+
# new(id, name, full_name, arch, essential, important, current_version)
|
15
|
+
# @param [Integer] The numeric ID of the package
|
16
|
+
# @param [String] The name of the package
|
17
|
+
# @param [String] Get the full name of the package, including the
|
18
|
+
# architecture
|
19
|
+
# @param [String] The architecture of the package
|
20
|
+
# @param [Boolean] Boolean value determining whether the package is
|
21
|
+
# essential
|
22
|
+
# @param [Boolean] Boolean value determining whether the package has the
|
23
|
+
# 'important' flag set
|
24
|
+
# ('Important: yes' in the Packages file)
|
25
|
+
# @param [Version,NilClass] The version of the package currently installed
|
26
|
+
# or `nil`
|
27
|
+
# @return [Package] Package instance
|
28
|
+
def initialize(id, name, full_name, arch, essential, important, current_version)
|
29
|
+
@id = id
|
30
|
+
@name = name
|
31
|
+
@full_name = full_name
|
32
|
+
@arch = arch
|
33
|
+
@essential = essential
|
34
|
+
@important = important
|
35
|
+
@current_version = current_version
|
36
|
+
end
|
37
|
+
|
38
|
+
# Return `true` if the package is installed
|
39
|
+
# @return [Boolean]
|
40
|
+
def is_installed
|
41
|
+
return false unless current_version
|
42
|
+
|
43
|
+
true
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|