apt-pkg 0.1.0 → 0.2.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 +4 -4
- data/History.md +7 -0
- data/LICENSE +1 -1
- data/README.md +14 -13
- data/ext/apt_pkg/apt-pkg.cpp +150 -89
- data/ext/apt_pkg/apt-pkg.h +2 -1
- data/ext/apt_pkg/configuration.cpp +94 -86
- data/ext/apt_pkg/extconf.rb +0 -3
- data/ext/apt_pkg/pkgcache.cpp +194 -116
- data/lib/debian/apt_pkg/version.rb +1 -1
- data/test/apt_pkg_cache_not_init_test.rb +13 -0
- data/test/apt_pkg_cache_test.rb +10 -0
- data/test/apt_pkg_configuration_test.rb +4 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dca5749e8aeefa1455545b78ee74c606a0980c3a
|
4
|
+
data.tar.gz: c55db57c265cc70b03951e4fe1d2512a1df11d8c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 309b619137c40692dda14b015640a608570d47f3bf80ff1b578718f757c8cde0c07f81efbb8f3e3d383457dd462972a1dfbe2a0b76a6f9b9a3771a19c18f6c02
|
7
|
+
data.tar.gz: c8a6b47d0fb7f87d74e830632c21a782070a600aa6daead1c00b8769b70529f6628f61a6c00e7f31e1714429b6ed75fc2170dbcd3ee8ebf680db08ce6a943961
|
data/History.md
CHANGED
data/LICENSE
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
The MIT License
|
2
2
|
|
3
|
-
Copyright (c) 2014-
|
3
|
+
Copyright (c) 2014-2016 Laurent Arnoud <laurent@spkdev.net>
|
4
4
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining
|
6
6
|
a copy of this software and associated documentation files (the
|
data/README.md
CHANGED
@@ -7,44 +7,45 @@ Currently install, remove packages commands are **not** implemented.
|
|
7
7
|
|
8
8
|
## INSTALL
|
9
9
|
|
10
|
-
|
11
|
-
|
10
|
+
``` console
|
11
|
+
apt install build-essential ruby-dev libapt-pkg-dev (>= 1.0)
|
12
12
|
gem install apt-pkg
|
13
|
-
|
13
|
+
```
|
14
14
|
|
15
15
|
## USING
|
16
16
|
|
17
17
|
Simple search is implemented with:
|
18
18
|
|
19
|
-
|
19
|
+
``` ruby
|
20
20
|
require 'debian/apt_pkg'
|
21
|
+
Debian::AptPkg.init
|
21
22
|
Debian::AptPkg::PkgCache.pkg_names("vim")
|
22
|
-
|
23
|
+
```
|
23
24
|
|
24
25
|
[Documentation](https://spk.github.io/ruby-apt-pkg/)
|
25
26
|
|
26
27
|
## BUILD
|
27
28
|
|
28
|
-
|
29
|
+
``` console
|
29
30
|
gem install bundler
|
30
31
|
bundle install
|
31
32
|
bundle exec rake compile
|
32
|
-
|
33
|
+
```
|
33
34
|
|
34
35
|
## TEST
|
35
36
|
|
36
|
-
|
37
|
+
``` console
|
37
38
|
bundle exec rake test
|
38
|
-
|
39
|
+
```
|
39
40
|
|
40
41
|
## LICENSE
|
41
42
|
|
42
43
|
The MIT License
|
43
44
|
|
44
|
-
Copyright (c) 2014-
|
45
|
+
Copyright (c) 2014-2016 Laurent Arnoud <laurent@spkdev.net>
|
45
46
|
|
46
47
|
---
|
47
|
-
[](https://travis-ci.org/spk/ruby-apt-pkg)
|
49
|
+
[](https://rubygems.org/gems/apt-pkg)
|
50
|
+
[](http://opensource.org/licenses/MIT "MIT")
|
50
51
|
[](https://webchat.oftc.net/ "#ruby-apt-pkg")
|
data/ext/apt_pkg/apt-pkg.cpp
CHANGED
@@ -2,6 +2,52 @@
|
|
2
2
|
#include "configuration.h"
|
3
3
|
#include "pkgcache.h"
|
4
4
|
|
5
|
+
/*
|
6
|
+
* call-seq: init() -> nil
|
7
|
+
*
|
8
|
+
* Shorthand for doing init_config() and init_system().
|
9
|
+
*
|
10
|
+
* Debian::AptPkg.init # => nil
|
11
|
+
*
|
12
|
+
**/
|
13
|
+
static VALUE
|
14
|
+
init(VALUE self)
|
15
|
+
{
|
16
|
+
pkgInitConfig(*_config);
|
17
|
+
pkgInitSystem(*_config, _system);
|
18
|
+
return Qnil;
|
19
|
+
}
|
20
|
+
|
21
|
+
/*
|
22
|
+
* call-seq: init_config() -> bool
|
23
|
+
*
|
24
|
+
* Load the default configuration and the config file.
|
25
|
+
*
|
26
|
+
* Debian::AptPkg.init_config # => false
|
27
|
+
*
|
28
|
+
**/
|
29
|
+
static VALUE
|
30
|
+
init_config(VALUE self)
|
31
|
+
{
|
32
|
+
int res = pkgInitConfig(*_config);
|
33
|
+
return INT2BOOL(res);
|
34
|
+
}
|
35
|
+
|
36
|
+
/*
|
37
|
+
* call-seq: init_system() -> bool
|
38
|
+
*
|
39
|
+
* Construct the apt_pkg system.
|
40
|
+
*
|
41
|
+
* Debian::AptPkg.init_system # => false
|
42
|
+
*
|
43
|
+
**/
|
44
|
+
static VALUE
|
45
|
+
init_system(VALUE self)
|
46
|
+
{
|
47
|
+
int res = pkgInitSystem(*_config, _system);
|
48
|
+
return INT2BOOL(res);
|
49
|
+
}
|
50
|
+
|
5
51
|
/*
|
6
52
|
* call-seq: cmp_version(pkg_version_a, pkg_version_b) -> int
|
7
53
|
*
|
@@ -15,11 +61,12 @@
|
|
15
61
|
* Debian::AptPkg.cmp_version('1.0', '1.1') # => -1
|
16
62
|
*
|
17
63
|
**/
|
18
|
-
static
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
64
|
+
static VALUE
|
65
|
+
cmp_version(VALUE self, VALUE pkg_version_a, VALUE pkg_version_b)
|
66
|
+
{
|
67
|
+
int res = debVS.CmpVersion(StringValuePtr(pkg_version_a),
|
68
|
+
StringValuePtr(pkg_version_b));
|
69
|
+
return INT2FIX(res);
|
23
70
|
}
|
24
71
|
|
25
72
|
/*
|
@@ -37,24 +84,26 @@ VALUE cmp_version(VALUE self, VALUE pkg_version_a, VALUE pkg_version_b) {
|
|
37
84
|
* Debian::AptPkg.check_dep('1', Debian::AptPkg::NOT_EQUALS, '2') # => true
|
38
85
|
*
|
39
86
|
**/
|
40
|
-
static
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
87
|
+
static VALUE
|
88
|
+
check_dep(VALUE self, VALUE pkg_version_a, VALUE cmp_type, VALUE pkg_version_b)
|
89
|
+
{
|
90
|
+
unsigned int op = 0;
|
91
|
+
if (TYPE(cmp_type) == T_FIXNUM) {
|
92
|
+
op = NUM2INT(cmp_type);
|
93
|
+
} else {
|
94
|
+
const char *op_str = StringValuePtr(cmp_type);
|
95
|
+
if (strcmp(op_str, ">") == 0)
|
96
|
+
op_str = ">>";
|
97
|
+
if (strcmp(op_str, "<") == 0)
|
98
|
+
op_str = "<<";
|
99
|
+
if (*debListParser::ConvertRelation(op_str, op) != 0) {
|
100
|
+
rb_raise(rb_eArgError, "Bad comparison operation");
|
101
|
+
return 0;
|
54
102
|
}
|
55
|
-
|
56
|
-
|
57
|
-
|
103
|
+
}
|
104
|
+
int res = debVS.CheckDep(StringValuePtr(pkg_version_a), op,
|
105
|
+
StringValuePtr(pkg_version_b));
|
106
|
+
return INT2BOOL(res);
|
58
107
|
}
|
59
108
|
|
60
109
|
/*
|
@@ -65,9 +114,10 @@ VALUE check_dep(VALUE self, VALUE pkg_version_a, VALUE cmp_type, VALUE pkg_versi
|
|
65
114
|
* Debian::AptPkg.uri_to_filename('http://debian.org/index.html') # => 'debian.org_index.html'
|
66
115
|
*
|
67
116
|
**/
|
68
|
-
static
|
69
|
-
|
70
|
-
|
117
|
+
static VALUE
|
118
|
+
uri_to_filename(VALUE self, VALUE uri)
|
119
|
+
{
|
120
|
+
return rb_str_new2(URItoFileName(StringValuePtr(uri)).c_str());
|
71
121
|
}
|
72
122
|
|
73
123
|
/*
|
@@ -78,9 +128,10 @@ VALUE uri_to_filename(VALUE self, VALUE uri) {
|
|
78
128
|
* Debian::AptPkg.upstream_version('3.4.15-1+b1') # => '3.4.15'
|
79
129
|
*
|
80
130
|
**/
|
81
|
-
static
|
82
|
-
|
83
|
-
|
131
|
+
static VALUE
|
132
|
+
upstream_version(VALUE self, VALUE ver)
|
133
|
+
{
|
134
|
+
return rb_str_new2(debVS.UpstreamVersion(StringValuePtr(ver)).c_str());
|
84
135
|
}
|
85
136
|
|
86
137
|
/*
|
@@ -91,9 +142,10 @@ VALUE upstream_version(VALUE self, VALUE ver) {
|
|
91
142
|
* Debian::AptPkg.time_to_str(3601) # => '1h 0min 1s'
|
92
143
|
*
|
93
144
|
**/
|
94
|
-
static
|
95
|
-
|
96
|
-
|
145
|
+
static VALUE
|
146
|
+
time_to_str(VALUE self, VALUE secondes)
|
147
|
+
{
|
148
|
+
return rb_str_new2(TimeToStr(NUM2INT(secondes)).c_str());
|
97
149
|
}
|
98
150
|
|
99
151
|
/*
|
@@ -104,9 +156,10 @@ VALUE time_to_str(VALUE self, VALUE secondes) {
|
|
104
156
|
* Debian::AptPkg.size_to_str(10000) # => '10.0 k'
|
105
157
|
*
|
106
158
|
**/
|
107
|
-
static
|
108
|
-
|
109
|
-
|
159
|
+
static VALUE
|
160
|
+
size_to_str(VALUE self, VALUE size)
|
161
|
+
{
|
162
|
+
return rb_str_new2(SizeToStr(NUM2INT(size)).c_str());
|
110
163
|
}
|
111
164
|
|
112
165
|
/*
|
@@ -119,9 +172,10 @@ VALUE size_to_str(VALUE self, VALUE size) {
|
|
119
172
|
* Debian::AptPkg.string_to_bool('no-recognized') # => false
|
120
173
|
*
|
121
174
|
**/
|
122
|
-
static
|
123
|
-
|
124
|
-
|
175
|
+
static VALUE
|
176
|
+
string_to_bool(VALUE self, VALUE text)
|
177
|
+
{
|
178
|
+
return INT2BOOL(StringToBool(StringValuePtr(text)) == 1);
|
125
179
|
}
|
126
180
|
|
127
181
|
/*
|
@@ -132,59 +186,66 @@ VALUE string_to_bool(VALUE self, VALUE text) {
|
|
132
186
|
* Debian::AptPkg.check_domain_list("alioth.debian.org", "debian.net,debian.org") # => true
|
133
187
|
*
|
134
188
|
**/
|
135
|
-
static
|
136
|
-
|
137
|
-
|
138
|
-
|
189
|
+
static VALUE
|
190
|
+
check_domain_list(VALUE self, VALUE host, VALUE list)
|
191
|
+
{
|
192
|
+
int res = CheckDomainList(StringValuePtr(host), StringValuePtr(list));
|
193
|
+
return INT2BOOL(res);
|
139
194
|
}
|
140
195
|
|
141
196
|
void
|
142
|
-
Init_apt_pkg()
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
197
|
+
Init_apt_pkg()
|
198
|
+
{
|
199
|
+
VALUE rb_mDebian = rb_define_module("Debian");
|
200
|
+
VALUE rb_mDebianAptPkg = rb_define_module_under(rb_mDebian, "AptPkg");
|
201
|
+
VALUE rb_mDebianAptPkgConfiguration =
|
202
|
+
rb_define_module_under(rb_mDebianAptPkg, "Configuration");
|
203
|
+
|
204
|
+
rb_define_singleton_method(rb_mDebianAptPkg, "init",
|
205
|
+
RUBY_METHOD_FUNC(init), 0);
|
206
|
+
rb_define_singleton_method(rb_mDebianAptPkg, "init_config",
|
207
|
+
RUBY_METHOD_FUNC(init_config), 0);
|
208
|
+
rb_define_singleton_method(rb_mDebianAptPkg, "init_system",
|
209
|
+
RUBY_METHOD_FUNC(init_system), 0);
|
210
|
+
|
211
|
+
rb_define_singleton_method(rb_mDebianAptPkg, "uri_to_filename",
|
212
|
+
RUBY_METHOD_FUNC(uri_to_filename), 1);
|
213
|
+
rb_define_singleton_method(rb_mDebianAptPkg, "time_to_str",
|
214
|
+
RUBY_METHOD_FUNC(time_to_str), 1);
|
215
|
+
rb_define_singleton_method(rb_mDebianAptPkg, "size_to_str",
|
216
|
+
RUBY_METHOD_FUNC(size_to_str), 1);
|
217
|
+
rb_define_singleton_method(rb_mDebianAptPkg, "string_to_bool",
|
218
|
+
RUBY_METHOD_FUNC(string_to_bool), 1);
|
219
|
+
rb_define_singleton_method(rb_mDebianAptPkg, "check_domain_list",
|
220
|
+
RUBY_METHOD_FUNC(check_domain_list), 2);
|
221
|
+
rb_define_singleton_method(rb_mDebianAptPkg, "cmp_version",
|
222
|
+
RUBY_METHOD_FUNC(cmp_version), 2);
|
223
|
+
rb_define_singleton_method(rb_mDebianAptPkg, "check_dep",
|
224
|
+
RUBY_METHOD_FUNC(check_dep), 3);
|
225
|
+
rb_define_singleton_method(rb_mDebianAptPkg, "upstream_version",
|
226
|
+
RUBY_METHOD_FUNC(upstream_version), 1);
|
227
|
+
|
228
|
+
/* Represents less equal operator. */
|
229
|
+
rb_define_const(rb_mDebianAptPkg, "LESS_EQ", INT2FIX(pkgCache::Dep::LessEq));
|
230
|
+
/* Represents greater equal operator. */
|
231
|
+
rb_define_const(rb_mDebianAptPkg, "GREATER_EQ",
|
232
|
+
INT2FIX(pkgCache::Dep::GreaterEq));
|
233
|
+
/* Represents less operator. */
|
234
|
+
rb_define_const(rb_mDebianAptPkg, "LESS", INT2FIX(pkgCache::Dep::Less));
|
235
|
+
/* Represents greater operator. */
|
236
|
+
rb_define_const(rb_mDebianAptPkg, "GREATER", INT2FIX(pkgCache::Dep::Greater));
|
237
|
+
/* Represents equals operator. */
|
238
|
+
rb_define_const(rb_mDebianAptPkg, "EQUALS", INT2FIX(pkgCache::Dep::Equals));
|
239
|
+
/* Represents not equals operator. */
|
240
|
+
rb_define_const(rb_mDebianAptPkg, "NOT_EQUALS",
|
241
|
+
INT2FIX(pkgCache::Dep::NotEquals));
|
242
|
+
|
243
|
+
/* Represents the version of apt. */
|
244
|
+
rb_define_const(rb_mDebianAptPkg, "APT_VERSION", rb_str_new2(pkgVersion));
|
245
|
+
/* Represents the version of apt_pkg library. */
|
246
|
+
rb_define_const(rb_mDebianAptPkg, "LIBAPT_PKG_VERSION",
|
247
|
+
rb_str_new2(pkgLibVersion));
|
248
|
+
|
249
|
+
init_apt_pkg_configuration();
|
250
|
+
init_apt_pkg_pkgcache();
|
190
251
|
}
|
data/ext/apt_pkg/apt-pkg.h
CHANGED
@@ -20,5 +20,6 @@ static VALUE string_to_bool(VALUE self, VALUE text);
|
|
20
20
|
static VALUE check_domain_list(VALUE self, VALUE host, VALUE list);
|
21
21
|
/* Versioning */
|
22
22
|
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,
|
23
|
+
static VALUE check_dep(VALUE self, VALUE pkg_version_a, VALUE cmp_type,
|
24
|
+
VALUE pkg_version_b);
|
24
25
|
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,213 +1,291 @@
|
|
1
1
|
#include "pkgcache.h"
|
2
2
|
|
3
|
+
/*
|
4
|
+
* private
|
5
|
+
*/
|
6
|
+
bool
|
7
|
+
config_system_initialized()
|
8
|
+
{
|
9
|
+
string const arch = _config->Find("APT::Architecture");
|
10
|
+
if (arch.empty()) {
|
11
|
+
return false;
|
12
|
+
}
|
13
|
+
return true;
|
14
|
+
}
|
15
|
+
|
3
16
|
/*
|
4
17
|
* call-seq: gen_caches() -> bool
|
5
18
|
*
|
6
19
|
* Call the main cache generator.
|
20
|
+
* Return `nil` when config, system, cache is not configured.
|
7
21
|
*
|
8
22
|
* Debian::AptPkg::PkgCache.gen_caches # => false
|
9
23
|
*
|
10
24
|
**/
|
11
|
-
static
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
return
|
25
|
+
static VALUE
|
26
|
+
gen_caches(VALUE self)
|
27
|
+
{
|
28
|
+
if (!config_system_initialized()) {
|
29
|
+
return Qnil;
|
30
|
+
}
|
31
|
+
pkgCacheFile CacheFile;
|
32
|
+
int res = CacheFile.BuildCaches(NULL, true);
|
33
|
+
return INT2BOOL(res);
|
34
|
+
}
|
35
|
+
|
36
|
+
/*
|
37
|
+
* call-seq: is_multi_arch() -> bool
|
38
|
+
*
|
39
|
+
* An attribute determining whether the cache supports multi-arch.
|
40
|
+
* Return `nil` when config, system, cache is not configured.
|
41
|
+
*
|
42
|
+
* Debian::AptPkg::PkgCache.is_multi_arch # => false
|
43
|
+
*
|
44
|
+
**/
|
45
|
+
static VALUE
|
46
|
+
is_multi_arch(VALUE self)
|
47
|
+
{
|
48
|
+
if (!config_system_initialized()) {
|
49
|
+
return Qnil;
|
50
|
+
}
|
51
|
+
pkgCacheFile CacheFile;
|
52
|
+
pkgCache *Cache = CacheFile.GetPkgCache();
|
53
|
+
if (Cache == NULL) {
|
54
|
+
return Qnil;
|
55
|
+
}
|
56
|
+
int res = Cache->MultiArchCache();
|
57
|
+
return INT2BOOL(res);
|
16
58
|
}
|
17
59
|
|
18
60
|
/*
|
19
61
|
* call-seq: pkg_names() -> array, nil
|
20
62
|
*
|
21
63
|
* List the names of all packages in the system.
|
22
|
-
* Return `nil` when cache is not
|
64
|
+
* Return `nil` when config, system, cache is not configured.
|
23
65
|
*
|
24
66
|
* Debian::AptPkg::PkgCache.pkg_names('gcolor2') # => ["gcolor2"]
|
25
67
|
*
|
26
68
|
**/
|
27
|
-
static
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
69
|
+
static VALUE
|
70
|
+
pkg_names(int argc, VALUE *argv, VALUE self)
|
71
|
+
{
|
72
|
+
if (!config_system_initialized()) {
|
73
|
+
return Qnil;
|
74
|
+
}
|
75
|
+
if (argc > 1 || argc == 0) {
|
76
|
+
rb_raise(rb_eArgError, "You must give at least one search argument");
|
77
|
+
}
|
78
|
+
VALUE name;
|
79
|
+
rb_scan_args(argc, argv, "01", &name);
|
80
|
+
if (NIL_P(name) || RSTRING_LEN(name) < 1) {
|
81
|
+
rb_raise(rb_eArgError, "You must give at least one search pattern");
|
82
|
+
}
|
83
|
+
VALUE result = rb_ary_new();
|
38
84
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
85
|
+
pkgCacheFile CacheFile;
|
86
|
+
if (CacheFile.GetPkgCache() == 0) {
|
87
|
+
return Qnil;
|
88
|
+
}
|
89
|
+
pkgCache::GrpIterator I = CacheFile.GetPkgCache()->GrpBegin();
|
44
90
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
}
|
91
|
+
const char *pkgname = StringValuePtr(name);
|
92
|
+
for (; I.end() != true; ++I) {
|
93
|
+
if (strncmp(I.Name(), pkgname, strlen(pkgname)) == 0) {
|
94
|
+
rb_ary_push(result, rb_str_new2(I.Name()));
|
50
95
|
}
|
51
|
-
|
96
|
+
}
|
97
|
+
return result;
|
52
98
|
}
|
53
99
|
|
54
100
|
/*
|
55
101
|
* call-seq: package_count() -> int, nil
|
56
102
|
*
|
57
103
|
* The total number of packages available in the cache.
|
58
|
-
* Return `nil` when cache is not
|
104
|
+
* Return `nil` when config, system, cache is not configured.
|
59
105
|
*
|
60
106
|
* Debian::AptPkg::PkgCache.package_count # => 69511
|
61
107
|
*
|
62
108
|
**/
|
63
|
-
static
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
109
|
+
static VALUE
|
110
|
+
package_count(VALUE self)
|
111
|
+
{
|
112
|
+
if (!config_system_initialized()) {
|
113
|
+
return Qnil;
|
114
|
+
}
|
115
|
+
pkgCacheFile CacheFile;
|
116
|
+
pkgCache *Cache = CacheFile.GetPkgCache();
|
117
|
+
if (Cache == NULL) {
|
118
|
+
return Qnil;
|
119
|
+
}
|
120
|
+
return INT2FIX(Cache->HeaderP->PackageCount);
|
71
121
|
}
|
72
122
|
|
73
123
|
/*
|
74
124
|
* call-seq: version_count() -> int, nil
|
75
125
|
*
|
76
126
|
* The total number of package versions available in the cache.
|
77
|
-
* Return `nil` when cache is not
|
127
|
+
* Return `nil` when config, system, cache is not configured.
|
78
128
|
*
|
79
129
|
* Debian::AptPkg::PkgCache.version_count # => 84630
|
80
130
|
*
|
81
131
|
**/
|
82
|
-
static
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
132
|
+
static VALUE
|
133
|
+
version_count(VALUE self)
|
134
|
+
{
|
135
|
+
if (!config_system_initialized()) {
|
136
|
+
return Qnil;
|
137
|
+
}
|
138
|
+
pkgCacheFile CacheFile;
|
139
|
+
pkgCache *Cache = CacheFile.GetPkgCache();
|
140
|
+
if (Cache == NULL) {
|
141
|
+
return Qnil;
|
142
|
+
}
|
143
|
+
return INT2FIX(Cache->HeaderP->VersionCount);
|
90
144
|
}
|
91
145
|
|
92
146
|
/*
|
93
147
|
* call-seq: depends_count() -> int, nil
|
94
148
|
*
|
95
149
|
* The total number of dependencies stored in the cache.
|
96
|
-
* Return `nil` when cache is not
|
150
|
+
* Return `nil` when config, system, cache is not configured.
|
97
151
|
*
|
98
152
|
* Debian::AptPkg::PkgCache.depends_count # => 551983
|
99
153
|
*
|
100
154
|
**/
|
101
|
-
static
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
155
|
+
static VALUE
|
156
|
+
depends_count(VALUE self)
|
157
|
+
{
|
158
|
+
if (!config_system_initialized()) {
|
159
|
+
return Qnil;
|
160
|
+
}
|
161
|
+
pkgCacheFile CacheFile;
|
162
|
+
pkgCache *Cache = CacheFile.GetPkgCache();
|
163
|
+
if (Cache == NULL) {
|
164
|
+
return Qnil;
|
165
|
+
}
|
166
|
+
return INT2FIX(Cache->HeaderP->DependsCount);
|
109
167
|
}
|
110
168
|
|
111
169
|
/*
|
112
170
|
* call-seq: package_file_count() -> int, nil
|
113
171
|
*
|
114
172
|
* The total number of packages files available.
|
115
|
-
* Return `nil` when cache is not
|
173
|
+
* Return `nil` when config, system, cache is not configured.
|
116
174
|
*
|
117
175
|
* Debian::AptPkg::PkgCache.package_file_count # => 17
|
118
176
|
*
|
119
177
|
**/
|
120
|
-
static
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
178
|
+
static VALUE
|
179
|
+
package_file_count(VALUE self)
|
180
|
+
{
|
181
|
+
if (!config_system_initialized()) {
|
182
|
+
return Qnil;
|
183
|
+
}
|
184
|
+
pkgCacheFile CacheFile;
|
185
|
+
pkgCache *Cache = CacheFile.GetPkgCache();
|
186
|
+
if (Cache == NULL) {
|
187
|
+
return Qnil;
|
188
|
+
}
|
189
|
+
return INT2FIX(Cache->HeaderP->PackageFileCount);
|
128
190
|
}
|
129
191
|
|
130
192
|
/*
|
131
193
|
* call-seq: ver_file_count() -> int, nil
|
132
194
|
*
|
133
195
|
* The total number of version and package file relations stored in the cache.
|
134
|
-
* Return `nil` when cache is not
|
196
|
+
* Return `nil` when config, system, cache is not configured.
|
135
197
|
*
|
136
198
|
* Debian::AptPkg::PkgCache.ver_file_count # => 11274
|
137
199
|
*
|
138
200
|
**/
|
139
|
-
static
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
201
|
+
static VALUE
|
202
|
+
ver_file_count(VALUE self)
|
203
|
+
{
|
204
|
+
if (!config_system_initialized()) {
|
205
|
+
return Qnil;
|
206
|
+
}
|
207
|
+
pkgCacheFile CacheFile;
|
208
|
+
pkgCache *Cache = CacheFile.GetPkgCache();
|
209
|
+
if (Cache == NULL) {
|
210
|
+
return Qnil;
|
211
|
+
}
|
212
|
+
return INT2FIX(Cache->HeaderP->VerFileCount);
|
147
213
|
}
|
148
214
|
|
149
215
|
/*
|
150
216
|
* call-seq: provides_count() -> int, nil
|
151
217
|
*
|
152
218
|
* The number of provided packages.
|
153
|
-
* Return `nil` when cache is not
|
219
|
+
* Return `nil` when config, system, cache is not configured.
|
154
220
|
*
|
155
221
|
* Debian::AptPkg::PkgCache.provides_count # => 69511
|
156
222
|
*
|
157
223
|
**/
|
158
|
-
static
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
224
|
+
static VALUE
|
225
|
+
provides_count(VALUE self)
|
226
|
+
{
|
227
|
+
if (!config_system_initialized()) {
|
228
|
+
return Qnil;
|
229
|
+
}
|
230
|
+
pkgCacheFile CacheFile;
|
231
|
+
pkgCache *Cache = CacheFile.GetPkgCache();
|
232
|
+
if (Cache == NULL) {
|
233
|
+
return Qnil;
|
234
|
+
}
|
235
|
+
return INT2FIX(Cache->HeaderP->ProvidesCount);
|
166
236
|
}
|
167
237
|
|
168
238
|
/*
|
169
239
|
* call-seq: group_count() -> int, nil
|
170
240
|
*
|
171
241
|
* The number of groups in the cache.
|
172
|
-
* Return `nil` when cache is not
|
242
|
+
* Return `nil` when config, system, cache is not configured.
|
173
243
|
*
|
174
244
|
* Debian::AptPkg::PkgCache.group_count # => 16730
|
175
245
|
*
|
176
246
|
**/
|
177
|
-
static
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
247
|
+
static VALUE
|
248
|
+
group_count(VALUE self)
|
249
|
+
{
|
250
|
+
if (!config_system_initialized()) {
|
251
|
+
return Qnil;
|
252
|
+
}
|
253
|
+
pkgCacheFile CacheFile;
|
254
|
+
pkgCache *Cache = CacheFile.GetPkgCache();
|
255
|
+
if (Cache == NULL) {
|
256
|
+
return Qnil;
|
257
|
+
}
|
258
|
+
return INT2FIX(Cache->HeaderP->GroupCount);
|
185
259
|
}
|
186
260
|
|
187
261
|
void
|
188
|
-
init_apt_pkg_pkgcache()
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
262
|
+
init_apt_pkg_pkgcache()
|
263
|
+
{
|
264
|
+
VALUE rb_mDebian = rb_define_module("Debian");
|
265
|
+
VALUE rb_mDebianAptPkg = rb_define_module_under(rb_mDebian, "AptPkg");
|
266
|
+
VALUE rb_mDebianAptPkgConfiguration = rb_define_module_under(rb_mDebianAptPkg,
|
267
|
+
"PkgCache");
|
268
|
+
|
269
|
+
rb_define_singleton_method(rb_mDebianAptPkgConfiguration, "gen_caches",
|
270
|
+
RUBY_METHOD_FUNC(gen_caches), 0);
|
271
|
+
rb_define_singleton_method(rb_mDebianAptPkgConfiguration, "is_multi_arch",
|
272
|
+
RUBY_METHOD_FUNC(is_multi_arch), 0);
|
273
|
+
rb_define_singleton_method(rb_mDebianAptPkgConfiguration, "pkg_names",
|
274
|
+
RUBY_METHOD_FUNC(pkg_names), -1);
|
275
|
+
|
276
|
+
rb_define_singleton_method(rb_mDebianAptPkgConfiguration, "package_count",
|
277
|
+
RUBY_METHOD_FUNC(package_count), 0);
|
278
|
+
rb_define_singleton_method(rb_mDebianAptPkgConfiguration, "version_count",
|
279
|
+
RUBY_METHOD_FUNC(version_count), 0);
|
280
|
+
rb_define_singleton_method(rb_mDebianAptPkgConfiguration, "depends_count",
|
281
|
+
RUBY_METHOD_FUNC(depends_count), 0);
|
282
|
+
rb_define_singleton_method(rb_mDebianAptPkgConfiguration,
|
283
|
+
"package_file_count",
|
284
|
+
RUBY_METHOD_FUNC(package_file_count), 0);
|
285
|
+
rb_define_singleton_method(rb_mDebianAptPkgConfiguration, "ver_file_count",
|
286
|
+
RUBY_METHOD_FUNC(ver_file_count), 0);
|
287
|
+
rb_define_singleton_method(rb_mDebianAptPkgConfiguration, "provides_count",
|
288
|
+
RUBY_METHOD_FUNC(provides_count), 0);
|
289
|
+
rb_define_singleton_method(rb_mDebianAptPkgConfiguration, "group_count",
|
290
|
+
RUBY_METHOD_FUNC(group_count), 0);
|
213
291
|
}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require_relative 'test_helper'
|
2
|
+
|
3
|
+
describe Debian::AptPkg::PkgCache do
|
4
|
+
describe 'not init' do
|
5
|
+
%i(package version depends package_file ver_file provides group).each do |m|
|
6
|
+
describe ".#{m}_count" do
|
7
|
+
it 'can be called' do
|
8
|
+
Debian::AptPkg::PkgCache.public_send("#{m}_count")
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/test/apt_pkg_cache_test.rb
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
require_relative 'test_helper'
|
2
2
|
|
3
3
|
describe Debian::AptPkg::PkgCache do
|
4
|
+
before :all do
|
5
|
+
Debian::AptPkg.init
|
6
|
+
end
|
7
|
+
|
4
8
|
describe '.gen_caches' do
|
5
9
|
it 'return boolean' do
|
6
10
|
if Process.uid == 0
|
@@ -11,6 +15,12 @@ describe Debian::AptPkg::PkgCache do
|
|
11
15
|
end
|
12
16
|
end
|
13
17
|
|
18
|
+
describe '.is_multi_arch' do
|
19
|
+
it 'can be called' do
|
20
|
+
Debian::AptPkg::PkgCache.is_multi_arch
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
14
24
|
describe '.pkg_names' do
|
15
25
|
it 'no argument' do
|
16
26
|
lambda do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: apt-pkg
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Laurent Arnoud
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-01-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -77,6 +77,7 @@ files:
|
|
77
77
|
- ext/apt_pkg/pkgcache.h
|
78
78
|
- lib/debian/apt_pkg.rb
|
79
79
|
- lib/debian/apt_pkg/version.rb
|
80
|
+
- test/apt_pkg_cache_not_init_test.rb
|
80
81
|
- test/apt_pkg_cache_test.rb
|
81
82
|
- test/apt_pkg_configuration_test.rb
|
82
83
|
- test/apt_pkg_test.rb
|
@@ -107,3 +108,4 @@ signing_key:
|
|
107
108
|
specification_version: 4
|
108
109
|
summary: Ruby interface to libapt-pkg
|
109
110
|
test_files: []
|
111
|
+
has_rdoc:
|