apt-pkg 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 +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
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 16cd206a5d9b3137497d05f937ef5b78fcac7aa6bd62e4177b73ef98ff0d917e
|
4
|
+
data.tar.gz: b0bcc23a93c8112321c890487ee385c7cede6da1b3179da4e5f0ebf11b723161
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3e650327a185fca89e757e30659c8c61371e7d2950e47b72e463a6ed598da4656e7fcc2f831830acea7de9e045242636077746d9f692ab5ca55dc9f62182db56
|
7
|
+
data.tar.gz: 8ab515778e66c88f8b53f10d03d65e95db89db8061f166bd4235b2dd47f18433187162b645d663a8f38bcf937d06d4a7fbdd14391b887eafadc4652b35cad80c
|
data/Gemfile
ADDED
data/History.md
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
|
2
|
+
0.5.0 / 2020-07-22
|
3
|
+
==================
|
4
|
+
|
5
|
+
* Debian::AptPkg::PkgCache.pkg_names deprecated
|
6
|
+
* Add all maintained Rubies on gitlab-ci
|
7
|
+
* Init listing packages on cache
|
8
|
+
* Quick fix gitlab ci
|
9
|
+
* Add .gitlab-ci.yml
|
10
|
+
* Rename lib/debian/apt_pkg/{version,gem_version}.rb
|
11
|
+
* Update README
|
12
|
+
* Tidy tests remove should
|
13
|
+
* Debian::AptPkg.init returns a boolean
|
14
|
+
* Fix mimitest warnings
|
15
|
+
* Remove cppcheck on CI version conflict
|
16
|
+
* Fix code lint
|
17
|
+
* Fix CI and update Rubies
|
18
|
+
* Fix libapt-pkg 2.1 compat
|
19
|
+
* Update apt-pkg deps
|
20
|
+
* Update doc Debian::AptPkg::InitError
|
21
|
+
* README: Bundler is not needed
|
22
|
+
* Use Debian::AptPkg::InitError instead of RuntimeError
|
23
|
+
* Fix rb_mDebianAptPkgCache name
|
24
|
+
|
25
|
+
0.4.0 / 2016-10-06
|
26
|
+
==================
|
27
|
+
|
28
|
+
* Raise RuntimeError instead of returning `nil`
|
29
|
+
|
30
|
+
0.3.0 / 2016-01-23
|
31
|
+
==================
|
32
|
+
|
33
|
+
* Prefer prefix ++/-- operators for non-primitive types
|
34
|
+
* Add Debian::AptPkg::PkgCache.update
|
35
|
+
|
36
|
+
0.2.0 / 2016-01-04
|
37
|
+
==================
|
38
|
+
|
39
|
+
* Fix cache count methods when not init
|
40
|
+
* Add init, init_{config,system}
|
41
|
+
* Add PkgCache.is_multi_arch method
|
42
|
+
|
43
|
+
0.1.0 / 2015-12-20
|
44
|
+
==================
|
45
|
+
|
46
|
+
* Change VERSION, APT_VERSION and LIBAPT_PKG_VERSION
|
47
|
+
* Add cache count methods
|
48
|
+
* Fix rake lint task exit status
|
49
|
+
* Fix syntax offences
|
50
|
+
|
51
|
+
0.0.4 / 2015-12-19
|
52
|
+
==================
|
53
|
+
|
54
|
+
* Simple search with `Debian::AptPkg::PkgCache.pkg_names("vim")`
|
55
|
+
* Documentation update
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2014-2020 Laurent Arnoud <laurent@spkdev.net>
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
'Software'), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
19
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
20
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
21
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
22
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
# Ruby interface to apt-pkg
|
2
|
+
|
3
|
+
Goal of this project is to have a proper Ruby binding to APT like in
|
4
|
+
[Python](https://tracker.debian.org/pkg/python-apt).
|
5
|
+
|
6
|
+
Currently install, remove packages commands are **not** implemented.
|
7
|
+
|
8
|
+
## INSTALL
|
9
|
+
|
10
|
+
```
|
11
|
+
apt install build-essential ruby-dev libapt-pkg-dev (>= 1.0)
|
12
|
+
gem install apt-pkg
|
13
|
+
```
|
14
|
+
|
15
|
+
## USING
|
16
|
+
|
17
|
+
Basic usage:
|
18
|
+
|
19
|
+
``` ruby
|
20
|
+
require 'debian/apt_pkg'
|
21
|
+
|
22
|
+
# Initialize the configuration and system of apt
|
23
|
+
Debian::AptPkg.init
|
24
|
+
|
25
|
+
# Update the index files used by the cache
|
26
|
+
Debian::AptPkg::PkgCache.update
|
27
|
+
|
28
|
+
# Search package by names
|
29
|
+
Debian::AptPkg::PkgCache.pkg_names("vim")
|
30
|
+
|
31
|
+
# List packages stored in the cache
|
32
|
+
Debian::AptPkg::PkgCache.packages
|
33
|
+
|
34
|
+
# List installed packages
|
35
|
+
Debian::AptPkg::PkgCache.packages.select {|pkg| pkg.is_installed }
|
36
|
+
```
|
37
|
+
|
38
|
+
[Documentation](http://www.rubydoc.info/gems/apt-pkg)
|
39
|
+
|
40
|
+
## BUILD
|
41
|
+
|
42
|
+
``` console
|
43
|
+
rake compile
|
44
|
+
```
|
45
|
+
|
46
|
+
## TEST
|
47
|
+
|
48
|
+
``` console
|
49
|
+
rake test
|
50
|
+
```
|
51
|
+
|
52
|
+
## LICENSE
|
53
|
+
|
54
|
+
The MIT License
|
55
|
+
|
56
|
+
Copyright (c) 2014-2020 Laurent Arnoud <laurent@spkdev.net>
|
57
|
+
|
58
|
+
---
|
59
|
+
[](https://travis-ci.org/spk/ruby-apt-pkg)
|
60
|
+
[](https://rubygems.org/gems/apt-pkg)
|
61
|
+
[](http://www.rubydoc.info/gems/apt-pkg)
|
62
|
+
[](http://opensource.org/licenses/MIT "MIT")
|
63
|
+
[](https://github.com/spk/ruby-apt-pkg)
|
@@ -0,0 +1,249 @@
|
|
1
|
+
#include "apt-pkg.h"
|
2
|
+
#include "configuration.h"
|
3
|
+
#include "pkgcache.h"
|
4
|
+
|
5
|
+
/*
|
6
|
+
* call-seq: init() -> bool
|
7
|
+
*
|
8
|
+
* Shorthand for doing init_config() and init_system().
|
9
|
+
*
|
10
|
+
* Debian::AptPkg.init # => true
|
11
|
+
*
|
12
|
+
**/
|
13
|
+
static VALUE
|
14
|
+
init(VALUE self)
|
15
|
+
{
|
16
|
+
int res = pkgInitConfig(*_config) && pkgInitSystem(*_config, _system);
|
17
|
+
return INT2BOOL(res);
|
18
|
+
}
|
19
|
+
|
20
|
+
/*
|
21
|
+
* call-seq: init_config() -> bool
|
22
|
+
*
|
23
|
+
* Load the default configuration and the config file.
|
24
|
+
*
|
25
|
+
* Debian::AptPkg.init_config # => false
|
26
|
+
*
|
27
|
+
**/
|
28
|
+
static VALUE
|
29
|
+
init_config(VALUE self)
|
30
|
+
{
|
31
|
+
int res = pkgInitConfig(*_config);
|
32
|
+
return INT2BOOL(res);
|
33
|
+
}
|
34
|
+
|
35
|
+
/*
|
36
|
+
* call-seq: init_system() -> bool
|
37
|
+
*
|
38
|
+
* Construct the apt_pkg system.
|
39
|
+
*
|
40
|
+
* Debian::AptPkg.init_system # => false
|
41
|
+
*
|
42
|
+
**/
|
43
|
+
static VALUE
|
44
|
+
init_system(VALUE self)
|
45
|
+
{
|
46
|
+
int res = pkgInitSystem(*_config, _system);
|
47
|
+
return INT2BOOL(res);
|
48
|
+
}
|
49
|
+
|
50
|
+
/*
|
51
|
+
* call-seq: cmp_version(pkg_version_a, pkg_version_b) -> int
|
52
|
+
*
|
53
|
+
* Compare the given versions.
|
54
|
+
*
|
55
|
+
* Return a strictly negative value if 'a' is smaller than 'b', 0 if they
|
56
|
+
* are equal, and a strictly positive value if 'a' is larger than 'b'.
|
57
|
+
*
|
58
|
+
* Debian::AptPkg.cmp_version('1.1', '1.0') # => 1
|
59
|
+
* Debian::AptPkg.cmp_version('1.0', '1.0') # => 0
|
60
|
+
* Debian::AptPkg.cmp_version('1.0', '1.1') # => -1
|
61
|
+
*
|
62
|
+
**/
|
63
|
+
static VALUE
|
64
|
+
cmp_version(VALUE self, VALUE pkg_version_a, VALUE pkg_version_b)
|
65
|
+
{
|
66
|
+
int res = debVS.CmpVersion(StringValuePtr(pkg_version_a),
|
67
|
+
StringValuePtr(pkg_version_b));
|
68
|
+
return INT2FIX(res);
|
69
|
+
}
|
70
|
+
|
71
|
+
/*
|
72
|
+
* call-seq: check_dep(pkg_version_a, op, pkg_version_b) -> bool
|
73
|
+
*
|
74
|
+
* Compare the given versions with an operator.
|
75
|
+
*
|
76
|
+
* Params:
|
77
|
+
*
|
78
|
+
* +pkg_version_a+:: Version to compare from.
|
79
|
+
* +op+:: See operators const or string (<, >, <=, >=, =)
|
80
|
+
* +pkg_version_b+:: Version to compare to.
|
81
|
+
*
|
82
|
+
* Debian::AptPkg.check_dep('1', '<', '2') # => true
|
83
|
+
* Debian::AptPkg.check_dep('1', Debian::AptPkg::NOT_EQUALS, '2') # => true
|
84
|
+
*
|
85
|
+
**/
|
86
|
+
static VALUE
|
87
|
+
check_dep(VALUE self, VALUE pkg_version_a, VALUE cmp_type, VALUE pkg_version_b)
|
88
|
+
{
|
89
|
+
unsigned int op = 0;
|
90
|
+
if (TYPE(cmp_type) == T_FIXNUM) {
|
91
|
+
op = NUM2INT(cmp_type);
|
92
|
+
} else {
|
93
|
+
const char *op_str = StringValuePtr(cmp_type);
|
94
|
+
if (strcmp(op_str, ">") == 0)
|
95
|
+
op_str = ">>";
|
96
|
+
if (strcmp(op_str, "<") == 0)
|
97
|
+
op_str = "<<";
|
98
|
+
if (*debListParser::ConvertRelation(op_str, op) != 0) {
|
99
|
+
rb_raise(rb_eArgError, "Bad comparison operation");
|
100
|
+
return 0;
|
101
|
+
}
|
102
|
+
}
|
103
|
+
int res = debVS.CheckDep(StringValuePtr(pkg_version_a), op,
|
104
|
+
StringValuePtr(pkg_version_b));
|
105
|
+
return INT2BOOL(res);
|
106
|
+
}
|
107
|
+
|
108
|
+
/*
|
109
|
+
* call-seq: uri_to_filename(uri) -> string
|
110
|
+
*
|
111
|
+
* Return a filename which can be used to store the file.
|
112
|
+
*
|
113
|
+
* Debian::AptPkg.uri_to_filename('http://debian.org/index.html') # => 'debian.org_index.html'
|
114
|
+
*
|
115
|
+
**/
|
116
|
+
static VALUE
|
117
|
+
uri_to_filename(VALUE self, VALUE uri)
|
118
|
+
{
|
119
|
+
return rb_str_new2(URItoFileName(StringValuePtr(uri)).c_str());
|
120
|
+
}
|
121
|
+
|
122
|
+
/*
|
123
|
+
* call-seq: upstream_version(ver) -> string
|
124
|
+
*
|
125
|
+
* Return the upstream version for the Debian package version given by version.
|
126
|
+
*
|
127
|
+
* Debian::AptPkg.upstream_version('3.4.15-1+b1') # => '3.4.15'
|
128
|
+
*
|
129
|
+
**/
|
130
|
+
static VALUE
|
131
|
+
upstream_version(VALUE self, VALUE ver)
|
132
|
+
{
|
133
|
+
return rb_str_new2(debVS.UpstreamVersion(StringValuePtr(ver)).c_str());
|
134
|
+
}
|
135
|
+
|
136
|
+
/*
|
137
|
+
* call-seq: time_to_str(secondes) -> string
|
138
|
+
*
|
139
|
+
* Format a given duration in human-readable manner.
|
140
|
+
*
|
141
|
+
* Debian::AptPkg.time_to_str(3601) # => '1h 0min 1s'
|
142
|
+
*
|
143
|
+
**/
|
144
|
+
static VALUE
|
145
|
+
time_to_str(VALUE self, VALUE secondes)
|
146
|
+
{
|
147
|
+
return rb_str_new2(TimeToStr(NUM2INT(secondes)).c_str());
|
148
|
+
}
|
149
|
+
|
150
|
+
/*
|
151
|
+
* call-seq: size_to_str(size) -> string
|
152
|
+
*
|
153
|
+
* Return a string describing the size in a human-readable manner.
|
154
|
+
*
|
155
|
+
* Debian::AptPkg.size_to_str(10000) # => '10.0 k'
|
156
|
+
*
|
157
|
+
**/
|
158
|
+
static VALUE
|
159
|
+
size_to_str(VALUE self, VALUE size)
|
160
|
+
{
|
161
|
+
return rb_str_new2(SizeToStr(NUM2INT(size)).c_str());
|
162
|
+
}
|
163
|
+
|
164
|
+
/*
|
165
|
+
* call-seq: string_to_bool(text) -> int
|
166
|
+
*
|
167
|
+
* Parse the string input and return a boolean.
|
168
|
+
*
|
169
|
+
* Debian::AptPkg.string_to_bool('yes') # => true
|
170
|
+
* Debian::AptPkg.string_to_bool('no') # => false
|
171
|
+
* Debian::AptPkg.string_to_bool('no-recognized') # => false
|
172
|
+
*
|
173
|
+
**/
|
174
|
+
static VALUE
|
175
|
+
string_to_bool(VALUE self, VALUE text)
|
176
|
+
{
|
177
|
+
return INT2BOOL(StringToBool(StringValuePtr(text)) == 1);
|
178
|
+
}
|
179
|
+
|
180
|
+
/*
|
181
|
+
* call-seq: check_domain_list(host, list) -> bool
|
182
|
+
*
|
183
|
+
* See if the host name given by host is one of the domains given.
|
184
|
+
*
|
185
|
+
* Debian::AptPkg.check_domain_list("alioth.debian.org", "debian.net,debian.org") # => true
|
186
|
+
*
|
187
|
+
**/
|
188
|
+
static VALUE
|
189
|
+
check_domain_list(VALUE self, VALUE host, VALUE list)
|
190
|
+
{
|
191
|
+
int res = CheckDomainList(StringValuePtr(host), StringValuePtr(list));
|
192
|
+
return INT2BOOL(res);
|
193
|
+
}
|
194
|
+
|
195
|
+
void
|
196
|
+
// cppcheck-suppress unusedFunction
|
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
|
+
|
202
|
+
rb_define_singleton_method(rb_mDebianAptPkg, "init",
|
203
|
+
RUBY_METHOD_FUNC(init), 0);
|
204
|
+
rb_define_singleton_method(rb_mDebianAptPkg, "init_config",
|
205
|
+
RUBY_METHOD_FUNC(init_config), 0);
|
206
|
+
rb_define_singleton_method(rb_mDebianAptPkg, "init_system",
|
207
|
+
RUBY_METHOD_FUNC(init_system), 0);
|
208
|
+
|
209
|
+
rb_define_singleton_method(rb_mDebianAptPkg, "uri_to_filename",
|
210
|
+
RUBY_METHOD_FUNC(uri_to_filename), 1);
|
211
|
+
rb_define_singleton_method(rb_mDebianAptPkg, "time_to_str",
|
212
|
+
RUBY_METHOD_FUNC(time_to_str), 1);
|
213
|
+
rb_define_singleton_method(rb_mDebianAptPkg, "size_to_str",
|
214
|
+
RUBY_METHOD_FUNC(size_to_str), 1);
|
215
|
+
rb_define_singleton_method(rb_mDebianAptPkg, "string_to_bool",
|
216
|
+
RUBY_METHOD_FUNC(string_to_bool), 1);
|
217
|
+
rb_define_singleton_method(rb_mDebianAptPkg, "check_domain_list",
|
218
|
+
RUBY_METHOD_FUNC(check_domain_list), 2);
|
219
|
+
rb_define_singleton_method(rb_mDebianAptPkg, "cmp_version",
|
220
|
+
RUBY_METHOD_FUNC(cmp_version), 2);
|
221
|
+
rb_define_singleton_method(rb_mDebianAptPkg, "check_dep",
|
222
|
+
RUBY_METHOD_FUNC(check_dep), 3);
|
223
|
+
rb_define_singleton_method(rb_mDebianAptPkg, "upstream_version",
|
224
|
+
RUBY_METHOD_FUNC(upstream_version), 1);
|
225
|
+
|
226
|
+
/* Represents less equal operator. */
|
227
|
+
rb_define_const(rb_mDebianAptPkg, "LESS_EQ", INT2FIX(pkgCache::Dep::LessEq));
|
228
|
+
/* Represents greater equal operator. */
|
229
|
+
rb_define_const(rb_mDebianAptPkg, "GREATER_EQ",
|
230
|
+
INT2FIX(pkgCache::Dep::GreaterEq));
|
231
|
+
/* Represents less operator. */
|
232
|
+
rb_define_const(rb_mDebianAptPkg, "LESS", INT2FIX(pkgCache::Dep::Less));
|
233
|
+
/* Represents greater operator. */
|
234
|
+
rb_define_const(rb_mDebianAptPkg, "GREATER", INT2FIX(pkgCache::Dep::Greater));
|
235
|
+
/* Represents equals operator. */
|
236
|
+
rb_define_const(rb_mDebianAptPkg, "EQUALS", INT2FIX(pkgCache::Dep::Equals));
|
237
|
+
/* Represents not equals operator. */
|
238
|
+
rb_define_const(rb_mDebianAptPkg, "NOT_EQUALS",
|
239
|
+
INT2FIX(pkgCache::Dep::NotEquals));
|
240
|
+
|
241
|
+
/* Represents the version of apt. */
|
242
|
+
rb_define_const(rb_mDebianAptPkg, "APT_VERSION", rb_str_new2(pkgVersion));
|
243
|
+
/* Represents the version of apt_pkg library. */
|
244
|
+
rb_define_const(rb_mDebianAptPkg, "LIBAPT_PKG_VERSION",
|
245
|
+
rb_str_new2(pkgLibVersion));
|
246
|
+
|
247
|
+
init_apt_pkg_configuration();
|
248
|
+
init_apt_pkg_pkgcache();
|
249
|
+
}
|
@@ -0,0 +1,26 @@
|
|
1
|
+
#include <ruby.h>
|
2
|
+
#include <apt-pkg/deblistparser.h>
|
3
|
+
#include <apt-pkg/debversion.h>
|
4
|
+
#include <apt-pkg/pkgcache.h>
|
5
|
+
#include <apt-pkg/strutl.h>
|
6
|
+
#include <apt-pkg/pkgsystem.h>
|
7
|
+
#include <apt-pkg/init.h>
|
8
|
+
|
9
|
+
/* from '<ruby/dl.h>' */
|
10
|
+
#define INT2BOOL(x) ((x) ? Qtrue : Qfalse)
|
11
|
+
|
12
|
+
using namespace std;
|
13
|
+
|
14
|
+
/* function prototypes */
|
15
|
+
extern "C" void Init_apt_pkg();
|
16
|
+
/* String functions */
|
17
|
+
static VALUE uri_to_filename(VALUE self, VALUE uri);
|
18
|
+
static VALUE time_to_str(VALUE self, VALUE secondes);
|
19
|
+
static VALUE size_to_str(VALUE self, VALUE size);
|
20
|
+
static VALUE string_to_bool(VALUE self, VALUE text);
|
21
|
+
static VALUE check_domain_list(VALUE self, VALUE host, VALUE list);
|
22
|
+
/* Versioning */
|
23
|
+
static VALUE cmp_version(VALUE self, VALUE pkg_version_a, VALUE pkg_version_b);
|
24
|
+
static VALUE check_dep(VALUE self, VALUE pkg_version_a, VALUE cmp_type,
|
25
|
+
VALUE pkg_version_b);
|
26
|
+
static VALUE upstream_version(VALUE self, VALUE ver);
|
@@ -0,0 +1,190 @@
|
|
1
|
+
#include "configuration.h"
|
2
|
+
|
3
|
+
/*
|
4
|
+
* call-seq: architectures() -> array
|
5
|
+
*
|
6
|
+
* Return the list of architectures supported on this system.
|
7
|
+
*
|
8
|
+
* Debian::AptPkg::Configuration.architectures # => ["amd64"]
|
9
|
+
*
|
10
|
+
**/
|
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
|
+
}
|
22
|
+
|
23
|
+
/*
|
24
|
+
* call-seq: check_architecture(arch) -> bool
|
25
|
+
*
|
26
|
+
* Are we interested in the given Architecture.
|
27
|
+
*
|
28
|
+
* Debian::AptPkg::Configuration.check_architecture("all") # => true
|
29
|
+
*
|
30
|
+
**/
|
31
|
+
static VALUE
|
32
|
+
check_architecture(VALUE self, VALUE arch)
|
33
|
+
{
|
34
|
+
int res = APT::Configuration::checkArchitecture(StringValuePtr(arch));
|
35
|
+
return INT2BOOL(res);
|
36
|
+
}
|
37
|
+
|
38
|
+
/*
|
39
|
+
* call-seq: languages() -> array
|
40
|
+
*
|
41
|
+
* Return the list of languages code.
|
42
|
+
*
|
43
|
+
* Params:
|
44
|
+
*
|
45
|
+
* +all+:: All languages code or short for false.
|
46
|
+
*
|
47
|
+
* Debian::AptPkg::Configuration.languages # => ["en", "none", "fr"]
|
48
|
+
* Debian::AptPkg::Configuration.languages(false) # => ["en"]
|
49
|
+
*
|
50
|
+
**/
|
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;
|
64
|
+
}
|
65
|
+
|
66
|
+
/*
|
67
|
+
* call-seq: check_language(lang, all) -> bool
|
68
|
+
*
|
69
|
+
* Are we interested in the given language.
|
70
|
+
*
|
71
|
+
* Debian::AptPkg::Configuration.check_language("fr") # => true
|
72
|
+
*
|
73
|
+
**/
|
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);
|
84
|
+
}
|
85
|
+
|
86
|
+
/*
|
87
|
+
* call-seq: compressors() -> array
|
88
|
+
*
|
89
|
+
* Return the list of compressors supported on this system.
|
90
|
+
*
|
91
|
+
* Debian::AptPkg::Configuration.compressors # => ["gz"]
|
92
|
+
*
|
93
|
+
**/
|
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;
|
104
|
+
}
|
105
|
+
|
106
|
+
/*
|
107
|
+
* call-seq: config_find(name, default_key = '') -> string
|
108
|
+
*
|
109
|
+
* Return the value stored at the option named key, or the value given by the
|
110
|
+
* string default if the option in question is not set.
|
111
|
+
*
|
112
|
+
* Params:
|
113
|
+
*
|
114
|
+
* +name+:: Key name.
|
115
|
+
* +default_key+:: Default key when config option not set.
|
116
|
+
*
|
117
|
+
* Debian::AptPkg::Configuration.config_find('Dir::Etc::main') # => "apt.conf"
|
118
|
+
*
|
119
|
+
**/
|
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());
|
132
|
+
}
|
133
|
+
|
134
|
+
/*
|
135
|
+
* call-seq: config_find_file(name, default_key = '') -> string
|
136
|
+
*
|
137
|
+
* Locate the given key using find() and return the path to the file/directory.
|
138
|
+
* This uses a special algorithms which moves upwards in the configuration space
|
139
|
+
* and prepends the values of the options to the result. These methods are
|
140
|
+
* generally used for the options stored in the ‘Dir’ section of the
|
141
|
+
* configuration.
|
142
|
+
*
|
143
|
+
* Params:
|
144
|
+
*
|
145
|
+
* +name+:: Key name.
|
146
|
+
* +default_key+:: Default key when config option not set.
|
147
|
+
*
|
148
|
+
* Debian::AptPkg::Configuration.config_find_file('Dir::Etc::main') # => "/etc/apt/apt.conf"
|
149
|
+
*
|
150
|
+
**/
|
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());
|
163
|
+
}
|
164
|
+
|
165
|
+
void
|
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");
|
172
|
+
|
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);
|
184
|
+
|
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);
|
190
|
+
}
|