apt-pkg 0.0.4 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/History.md +51 -2
- data/LICENSE +1 -1
- data/README.md +35 -22
- data/ext/apt_pkg/apt-pkg.cpp +148 -88
- data/ext/apt_pkg/apt-pkg.h +3 -1
- data/ext/apt_pkg/configuration.cpp +94 -86
- data/ext/apt_pkg/extconf.rb +2 -5
- data/ext/apt_pkg/pkgcache.cpp +379 -38
- data/ext/apt_pkg/pkgcache.h +1 -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 +35 -31
- data/test/apt_pkg_test.rb +67 -47
- 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 +1 -1
- metadata +15 -12
- data/test/apt_pkg_cache_test.rb +0 -40
data/ext/apt_pkg/apt-pkg.h
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
#include <apt-pkg/debversion.h>
|
4
4
|
#include <apt-pkg/pkgcache.h>
|
5
5
|
#include <apt-pkg/strutl.h>
|
6
|
+
#include <apt-pkg/pkgsystem.h>
|
6
7
|
#include <apt-pkg/init.h>
|
7
8
|
|
8
9
|
/* from '<ruby/dl.h>' */
|
@@ -20,5 +21,6 @@ static VALUE string_to_bool(VALUE self, VALUE text);
|
|
20
21
|
static VALUE check_domain_list(VALUE self, VALUE host, VALUE list);
|
21
22
|
/* Versioning */
|
22
23
|
static VALUE cmp_version(VALUE self, VALUE pkg_version_a, VALUE pkg_version_b);
|
23
|
-
static VALUE check_dep(VALUE self, VALUE pkg_version_a, VALUE cmp_type,
|
24
|
+
static VALUE check_dep(VALUE self, VALUE pkg_version_a, VALUE cmp_type,
|
25
|
+
VALUE pkg_version_b);
|
24
26
|
static VALUE upstream_version(VALUE self, VALUE ver);
|
@@ -8,16 +8,16 @@
|
|
8
8
|
* Debian::AptPkg::Configuration.architectures # => ["amd64"]
|
9
9
|
*
|
10
10
|
**/
|
11
|
-
static
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
11
|
+
static VALUE
|
12
|
+
architectures(VALUE self)
|
13
|
+
{
|
14
|
+
VALUE result = rb_ary_new();
|
15
|
+
std::vector < std::string > arches = APT::Configuration::getArchitectures();
|
16
|
+
std::vector < std::string >::const_iterator I;
|
17
|
+
for (I = arches.begin(); I != arches.end(); ++I) {
|
18
|
+
rb_ary_push(result, rb_str_new2((*I).c_str()));
|
19
|
+
}
|
20
|
+
return result;
|
21
21
|
}
|
22
22
|
|
23
23
|
/*
|
@@ -28,10 +28,11 @@ VALUE architectures(VALUE self) {
|
|
28
28
|
* Debian::AptPkg::Configuration.check_architecture("all") # => true
|
29
29
|
*
|
30
30
|
**/
|
31
|
-
static
|
32
|
-
|
33
|
-
|
34
|
-
|
31
|
+
static VALUE
|
32
|
+
check_architecture(VALUE self, VALUE arch)
|
33
|
+
{
|
34
|
+
int res = APT::Configuration::checkArchitecture(StringValuePtr(arch));
|
35
|
+
return INT2BOOL(res);
|
35
36
|
}
|
36
37
|
|
37
38
|
/*
|
@@ -47,18 +48,19 @@ VALUE check_architecture(VALUE self, VALUE arch) {
|
|
47
48
|
* Debian::AptPkg::Configuration.languages(false) # => ["en"]
|
48
49
|
*
|
49
50
|
**/
|
50
|
-
static
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
51
|
+
static VALUE
|
52
|
+
languages(int argc, VALUE *argv, VALUE self)
|
53
|
+
{
|
54
|
+
VALUE all;
|
55
|
+
rb_scan_args(argc, argv, "01", &all);
|
56
|
+
VALUE result = rb_ary_new();
|
57
|
+
std::vector < std::string > const langs =
|
58
|
+
APT::Configuration::getLanguages(all);
|
59
|
+
std::vector < std::string >::const_iterator I;
|
60
|
+
for (I = langs.begin(); I != langs.end(); ++I) {
|
61
|
+
rb_ary_push(result, rb_str_new2((*I).c_str()));
|
62
|
+
}
|
63
|
+
return result;
|
62
64
|
}
|
63
65
|
|
64
66
|
/*
|
@@ -69,15 +71,16 @@ VALUE languages(int argc, VALUE* argv, VALUE self) {
|
|
69
71
|
* Debian::AptPkg::Configuration.check_language("fr") # => true
|
70
72
|
*
|
71
73
|
**/
|
72
|
-
static
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
74
|
+
static VALUE
|
75
|
+
check_language(int argc, VALUE *argv, VALUE self)
|
76
|
+
{
|
77
|
+
if (argc > 2 || argc == 0) {
|
78
|
+
rb_raise(rb_eArgError, "wrong number of arguments");
|
79
|
+
}
|
80
|
+
VALUE lang, all;
|
81
|
+
rb_scan_args(argc, argv, "11", &lang, &all);
|
82
|
+
int res = APT::Configuration::checkLanguage(StringValuePtr(lang), all);
|
83
|
+
return INT2BOOL(res);
|
81
84
|
}
|
82
85
|
|
83
86
|
/*
|
@@ -88,16 +91,16 @@ VALUE check_language(int argc, VALUE* argv, VALUE self) {
|
|
88
91
|
* Debian::AptPkg::Configuration.compressors # => ["gz"]
|
89
92
|
*
|
90
93
|
**/
|
91
|
-
static
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
94
|
+
static VALUE
|
95
|
+
compressors(VALUE self)
|
96
|
+
{
|
97
|
+
VALUE result = rb_ary_new();
|
98
|
+
std::vector < std::string > cmps = APT::Configuration::getCompressionTypes();
|
99
|
+
std::vector < std::string >::const_iterator I;
|
100
|
+
for (I = cmps.begin(); I != cmps.end(); ++I) {
|
101
|
+
rb_ary_push(result, rb_str_new2((*I).c_str()));
|
102
|
+
}
|
103
|
+
return result;
|
101
104
|
}
|
102
105
|
|
103
106
|
/*
|
@@ -114,17 +117,18 @@ VALUE compressors(VALUE self) {
|
|
114
117
|
* Debian::AptPkg::Configuration.config_find('Dir::Etc::main') # => "apt.conf"
|
115
118
|
*
|
116
119
|
**/
|
117
|
-
static
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
120
|
+
static VALUE
|
121
|
+
config_find(int argc, VALUE *argv, VALUE self)
|
122
|
+
{
|
123
|
+
if (argc > 2 || argc == 0) {
|
124
|
+
rb_raise(rb_eArgError, "wrong number of arguments");
|
125
|
+
}
|
126
|
+
VALUE name, default_key;
|
127
|
+
rb_scan_args(argc, argv, "11", &name, &default_key);
|
128
|
+
if (NIL_P(default_key))
|
129
|
+
default_key = rb_str_new2("");
|
130
|
+
return rb_str_new2(_config->Find(StringValuePtr(name),
|
131
|
+
StringValuePtr(default_key)).c_str());
|
128
132
|
}
|
129
133
|
|
130
134
|
/*
|
@@ -144,39 +148,43 @@ VALUE config_find(int argc, VALUE* argv, VALUE self) {
|
|
144
148
|
* Debian::AptPkg::Configuration.config_find_file('Dir::Etc::main') # => "/etc/apt/apt.conf"
|
145
149
|
*
|
146
150
|
**/
|
147
|
-
static
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
151
|
+
static VALUE
|
152
|
+
config_find_file(int argc, VALUE *argv, VALUE self)
|
153
|
+
{
|
154
|
+
if (argc > 2 || argc == 0) {
|
155
|
+
rb_raise(rb_eArgError, "wrong number of arguments");
|
156
|
+
}
|
157
|
+
VALUE name, default_key;
|
158
|
+
rb_scan_args(argc, argv, "11", &name, &default_key);
|
159
|
+
if (NIL_P(default_key))
|
160
|
+
default_key = rb_str_new2("");
|
161
|
+
return rb_str_new2(_config->FindFile(StringValuePtr(name),
|
162
|
+
StringValuePtr(default_key)).c_str());
|
158
163
|
}
|
159
164
|
|
160
165
|
void
|
161
|
-
init_apt_pkg_configuration()
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
+
init_apt_pkg_configuration()
|
167
|
+
{
|
168
|
+
VALUE rb_mDebian = rb_define_module("Debian");
|
169
|
+
VALUE rb_mDebianAptPkg = rb_define_module_under(rb_mDebian, "AptPkg");
|
170
|
+
VALUE rb_mDebianAptPkgConfiguration =
|
171
|
+
rb_define_module_under(rb_mDebianAptPkg, "Configuration");
|
166
172
|
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
173
|
+
rb_define_singleton_method(rb_mDebianAptPkgConfiguration, "architectures",
|
174
|
+
RUBY_METHOD_FUNC(architectures), 0);
|
175
|
+
rb_define_singleton_method(rb_mDebianAptPkgConfiguration,
|
176
|
+
"check_architecture",
|
177
|
+
RUBY_METHOD_FUNC(check_architecture), 1);
|
178
|
+
rb_define_singleton_method(rb_mDebianAptPkgConfiguration, "languages",
|
179
|
+
RUBY_METHOD_FUNC(languages), -1);
|
180
|
+
rb_define_singleton_method(rb_mDebianAptPkgConfiguration, "check_language",
|
181
|
+
RUBY_METHOD_FUNC(check_language), -1);
|
182
|
+
rb_define_singleton_method(rb_mDebianAptPkgConfiguration, "compressors",
|
183
|
+
RUBY_METHOD_FUNC(compressors), 0);
|
177
184
|
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
185
|
+
rb_define_singleton_method(rb_mDebianAptPkgConfiguration, "config_find",
|
186
|
+
RUBY_METHOD_FUNC(config_find), -1);
|
187
|
+
rb_define_singleton_method(rb_mDebianAptPkgConfiguration,
|
188
|
+
"config_find_file",
|
189
|
+
RUBY_METHOD_FUNC(config_find_file), -1);
|
182
190
|
}
|
data/ext/apt_pkg/extconf.rb
CHANGED
data/ext/apt_pkg/pkgcache.cpp
CHANGED
@@ -1,65 +1,406 @@
|
|
1
1
|
#include "pkgcache.h"
|
2
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
|
+
|
3
18
|
/*
|
4
19
|
* call-seq: gen_caches() -> bool
|
5
20
|
*
|
6
21
|
* Call the main cache generator.
|
22
|
+
* Raise `Debian::AptPkg::InitError` when config, system, cache is not
|
23
|
+
* configured.
|
7
24
|
*
|
8
25
|
* Debian::AptPkg::PkgCache.gen_caches # => false
|
9
26
|
*
|
10
27
|
**/
|
11
|
-
static
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
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;
|
16
143
|
}
|
17
144
|
|
18
145
|
/*
|
19
146
|
* call-seq: pkg_names() -> array, nil
|
20
147
|
*
|
148
|
+
* Deprecated and will removed in 0.6.0
|
21
149
|
* List the names of all packages in the system.
|
22
|
-
*
|
150
|
+
* Raise `Debian::AptPkg::InitError` when config, system, cache is not
|
151
|
+
* configured.
|
23
152
|
*
|
24
153
|
* Debian::AptPkg::PkgCache.pkg_names('gcolor2') # => ["gcolor2"]
|
25
154
|
*
|
26
155
|
**/
|
27
|
-
static
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
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();
|
38
173
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
174
|
+
pkgCacheFile CacheFile;
|
175
|
+
if (CacheFile.GetPkgCache() == 0) {
|
176
|
+
return Qnil;
|
177
|
+
}
|
178
|
+
pkgCache::GrpIterator I = CacheFile.GetPkgCache()->GrpBegin();
|
44
179
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
}
|
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()));
|
50
184
|
}
|
51
|
-
|
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);
|
52
355
|
}
|
53
356
|
|
54
357
|
void
|
55
|
-
init_apt_pkg_pkgcache()
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
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);
|
65
406
|
}
|