apt-pkg 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: bf4ed45aa8d76fac8568ae2cf5de1fab078edeff
4
+ data.tar.gz: 0c9db355335cbba15f7bb38b075c7df54005c418
5
+ SHA512:
6
+ metadata.gz: 9da1d1ddf75a69b86f588b632e4a180ffd82715de67d2559f9c4d6dfc76f7b702cbf2bff9e897cfd7ebf71544e21a4b996ab21b7b150c5c8cc145cdaefc0e747
7
+ data.tar.gz: ffeaf3e067fee5d83632c9b47766b090608b99026e4ea4fb63dc826ba29142e8dfd54db6000fe0270866e91cc9cf8f1ddedb297fe39553b6f4d2a14f589254ab
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ tmp/
2
+ html/
3
+ *.gem
4
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2014 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,31 @@
1
+ # Ruby interface to apt-pkg
2
+
3
+ ## INSTALL
4
+
5
+ ~~~ console
6
+ aptitude install libapt-pkg-dev ruby2.0-dev
7
+ gem install bundler
8
+ bundle install
9
+ ~~~
10
+
11
+ ## BUILD
12
+
13
+ ~~~ console
14
+ bundle exec rake compile
15
+ ~~~
16
+
17
+ ## TEST
18
+
19
+ ~~~ console
20
+ bundle exec rake test
21
+ ~~~
22
+
23
+ ## REFERENCES
24
+
25
+ * http://apt.alioth.debian.org/python-apt-doc/library/apt_pkg.html
26
+
27
+ ## LICENSE
28
+
29
+ The MIT License
30
+
31
+ Copyright (c) 2014 Laurent Arnoud <laurent@spkdev.net>
data/Rakefile ADDED
@@ -0,0 +1,18 @@
1
+ require 'rake/extensiontask'
2
+ require 'rake/testtask'
3
+ require 'rdoc/task'
4
+
5
+ Rake::ExtensionTask.new('apt_pkg')
6
+
7
+ Rake::Task[:test].prerequisites << :clean
8
+ Rake::Task[:test].prerequisites << :compile
9
+
10
+ Rake::TestTask.new do |t|
11
+ t.pattern = 'test/**/*_test.rb'
12
+ end
13
+
14
+ RDoc::Task.new do |rd|
15
+ rd.rdoc_files.include("ext/**/*.cpp")
16
+ end
17
+
18
+ task default: [:test]
data/apt-pkg.gemspec ADDED
@@ -0,0 +1,22 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "apt-pkg"
3
+ s.version = '0.0.1'
4
+
5
+ s.authors = ["Laurent Arnoud"]
6
+ s.description = %q{Ruby interface to apt-pkg}
7
+ s.summary = s.description
8
+ s.email = %q{laurent@spkdev.net}
9
+ s.license = "MIT"
10
+ s.extensions = ["ext/apt_pkg/extconf.rb"]
11
+ s.extra_rdoc_files = [
12
+ "README.md"
13
+ ]
14
+ s.files = `git ls-files`.split($\)
15
+ s.homepage = %q{http://github.com/spk/ruby-apt-pkg}
16
+ s.rdoc_options = ["--charset=UTF-8"]
17
+ s.require_paths = ["lib"]
18
+ s.add_development_dependency('rake')
19
+ s.add_development_dependency('rake-compiler')
20
+ s.add_development_dependency('minitest')
21
+ s.add_development_dependency('rdoc')
22
+ end
@@ -0,0 +1,176 @@
1
+ #include <ruby.h>
2
+ #include <apt-pkg/debversion.h>
3
+ #include <apt-pkg/pkgcache.h>
4
+ #include <apt-pkg/strutl.h>
5
+ #include <apt-pkg/init.h>
6
+
7
+ using namespace std;
8
+
9
+ /* from '<ruby/dl.h>' */
10
+ #define INT2BOOL(x) ((x) ? Qtrue : Qfalse)
11
+
12
+ /* function prototypes */
13
+ extern "C" void Init_apt_pkg();
14
+ /* String functions */
15
+ static VALUE cmp_version(VALUE self, VALUE pkg_version_a, VALUE pkg_version_b);
16
+ static VALUE check_dep(VALUE self, VALUE pkg_version_a, VALUE op, VALUE pkg_version_b);
17
+ static VALUE uri_to_filename(VALUE self, VALUE uri);
18
+ static VALUE upstream_version(VALUE self, VALUE ver);
19
+ static VALUE time_to_str(VALUE self, VALUE secondes);
20
+ static VALUE size_to_str(VALUE self, VALUE size);
21
+ static VALUE string_to_bool(VALUE self, VALUE text);
22
+ static VALUE check_domain_list(VALUE self, VALUE host, VALUE list);
23
+
24
+ /*
25
+ * call-seq: cmp_version(pkg_version_a, pkg_version_b) -> int
26
+ *
27
+ * Compare the given versions.
28
+ *
29
+ * Return a strictly negative value if 'a' is smaller than 'b', 0 if they
30
+ * are equal, and a strictly positive value if 'a' is larger than 'b'.
31
+ *
32
+ * Debian::AptPkg.cmp_version('1.1', '1.0') # => 1
33
+ * Debian::AptPkg.cmp_version('1.0', '1.0') # => 0
34
+ * Debian::AptPkg.cmp_version('1.0', '1.1') # => -1
35
+ *
36
+ **/
37
+ static
38
+ VALUE cmp_version(VALUE self, VALUE pkg_version_a, VALUE pkg_version_b) {
39
+ int res = debVS.CmpVersion(StringValuePtr(pkg_version_a), StringValuePtr(pkg_version_b));
40
+ return INT2FIX(res);
41
+ }
42
+
43
+ /*
44
+ * call-seq: check_dep(pkg_version_a, op, pkg_version_b) -> bool
45
+ *
46
+ * Compare the given versions with an operator.
47
+ *
48
+ * Params:
49
+ *
50
+ * +pkg_version_a+:: Version to compare from.
51
+ * +op+:: See operators const.
52
+ * +pkg_version_b+:: Version to compare to.
53
+ *
54
+ * Debian::AptPkg.check_dep('1', Debian::AptPkg::LESS_EQ, '2') # => true
55
+ *
56
+ **/
57
+ static
58
+ VALUE check_dep(VALUE self, VALUE pkg_version_a, VALUE op, VALUE pkg_version_b) {
59
+ int res = debVS.CheckDep(StringValuePtr(pkg_version_a), NUM2INT(op), StringValuePtr(pkg_version_b));
60
+ return INT2BOOL(res);
61
+ }
62
+
63
+ /*
64
+ * call-seq: uri_to_filename(uri) -> string
65
+ *
66
+ * Return a filename which can be used to store the file.
67
+ *
68
+ * Debian::AptPkg.uri_to_filename('http://debian.org/index.html') # => 'debian.org_index.html'
69
+ *
70
+ **/
71
+ static
72
+ VALUE uri_to_filename(VALUE self, VALUE uri) {
73
+ return rb_str_new2(URItoFileName(StringValuePtr(uri)).c_str());
74
+ }
75
+
76
+ /*
77
+ * call-seq: upstream_version(ver) -> string
78
+ *
79
+ * Return the upstream version for the Debian package version given by version.
80
+ *
81
+ * Debian::AptPkg.upstream_version('3.4.15-1+b1') # => '3.4.15'
82
+ *
83
+ **/
84
+ static
85
+ VALUE upstream_version(VALUE self, VALUE ver) {
86
+ return rb_str_new2(debVS.UpstreamVersion(StringValuePtr(ver)).c_str());
87
+ }
88
+
89
+ /*
90
+ * call-seq: time_to_str(secondes) -> string
91
+ *
92
+ * Format a given duration in human-readable manner.
93
+ *
94
+ * Debian::AptPkg.time_to_str(3601) # => '1h 0min 1s'
95
+ *
96
+ **/
97
+ static
98
+ VALUE time_to_str(VALUE self, VALUE secondes) {
99
+ return rb_str_new2(TimeToStr(NUM2INT(secondes)).c_str());
100
+ }
101
+
102
+ /*
103
+ * call-seq: size_to_str(size) -> string
104
+ *
105
+ * Return a string describing the size in a human-readable manner.
106
+ *
107
+ * Debian::AptPkg.size_to_str(10000) # => '10.0 k'
108
+ *
109
+ **/
110
+ static
111
+ VALUE size_to_str(VALUE self, VALUE size) {
112
+ return rb_str_new2(SizeToStr(NUM2INT(size)).c_str());
113
+ }
114
+
115
+ /*
116
+ * call-seq: string_to_bool(text) -> int
117
+ *
118
+ * Parse the string input and return a boolean.
119
+ *
120
+ * Debian::AptPkg.string_to_bool('yes') # => 1
121
+ * Debian::AptPkg.string_to_bool('no') # => 0
122
+ * Debian::AptPkg.string_to_bool('no-recognized') # => -1
123
+ *
124
+ **/
125
+ static
126
+ VALUE string_to_bool(VALUE self, VALUE text) {
127
+ return INT2FIX(StringToBool(StringValuePtr(text)));
128
+ }
129
+
130
+ /*
131
+ * call-seq: check_domain_list(host, list) -> bool
132
+ *
133
+ * See if the host name given by host is one of the domains given.
134
+ *
135
+ * Debian::AptPkg.check_domain_list("alioth.debian.org", "debian.net,debian.org") # => true
136
+ *
137
+ **/
138
+ static
139
+ VALUE check_domain_list(VALUE self, VALUE host, VALUE list) {
140
+ int res = CheckDomainList(StringValuePtr(host), StringValuePtr(list));
141
+ return INT2BOOL(res);
142
+ }
143
+
144
+ void
145
+ Init_apt_pkg() {
146
+ /* Base module */
147
+ VALUE rb_mDebian = rb_define_module("Debian");
148
+ VALUE rb_mDebianAptPkg = rb_define_module_under(rb_mDebian, "AptPkg");
149
+
150
+ rb_define_singleton_method(rb_mDebianAptPkg, "cmp_version", RUBY_METHOD_FUNC(cmp_version), 2);
151
+ rb_define_singleton_method(rb_mDebianAptPkg, "check_dep", RUBY_METHOD_FUNC(check_dep), 3);
152
+ rb_define_singleton_method(rb_mDebianAptPkg, "uri_to_filename", RUBY_METHOD_FUNC(uri_to_filename), 1);
153
+ rb_define_singleton_method(rb_mDebianAptPkg, "upstream_version", RUBY_METHOD_FUNC(upstream_version), 1);
154
+ rb_define_singleton_method(rb_mDebianAptPkg, "time_to_str", RUBY_METHOD_FUNC(time_to_str), 1);
155
+ rb_define_singleton_method(rb_mDebianAptPkg, "size_to_str", RUBY_METHOD_FUNC(size_to_str), 1);
156
+ rb_define_singleton_method(rb_mDebianAptPkg, "string_to_bool", RUBY_METHOD_FUNC(string_to_bool), 1);
157
+ rb_define_singleton_method(rb_mDebianAptPkg, "check_domain_list", RUBY_METHOD_FUNC(check_domain_list), 2);
158
+
159
+ /* Represents less equal operator. */
160
+ rb_define_const(rb_mDebianAptPkg, "LESS_EQ", INT2FIX(pkgCache::Dep::LessEq));
161
+ /* Represents greater equal operator. */
162
+ rb_define_const(rb_mDebianAptPkg, "GREATER_EQ", INT2FIX(pkgCache::Dep::GreaterEq));
163
+ /* Represents less operator. */
164
+ rb_define_const(rb_mDebianAptPkg, "LESS", INT2FIX(pkgCache::Dep::Less));
165
+ /* Represents greater operator. */
166
+ rb_define_const(rb_mDebianAptPkg, "GREATER", INT2FIX(pkgCache::Dep::Greater));
167
+ /* Represents equals operator. */
168
+ rb_define_const(rb_mDebianAptPkg, "EQUALS", INT2FIX(pkgCache::Dep::Equals));
169
+ /* Represents not equals operator. */
170
+ rb_define_const(rb_mDebianAptPkg, "NOT_EQUALS", INT2FIX(pkgCache::Dep::NotEquals));
171
+
172
+ /* Represents the version of apt. */
173
+ rb_define_const(rb_mDebianAptPkg, "VERSION", rb_str_new2(pkgVersion));
174
+ /* Represents the version of apt_pkg library. */
175
+ rb_define_const(rb_mDebianAptPkg, "LIB_VERSION", rb_str_new2(pkgLibVersion));
176
+ }
@@ -0,0 +1,8 @@
1
+ require 'mkmf'
2
+
3
+ have_library("stdc++")
4
+ have_library("apt-pkg")
5
+
6
+ dir_config('apt_pkg')
7
+
8
+ create_makefile('apt_pkg')
@@ -0,0 +1,97 @@
1
+ # encoding: UTF-8
2
+ require_relative 'test_helper'
3
+
4
+ describe Debian::AptPkg do
5
+
6
+ describe 'Debian::AptPkg.cmp_version' do
7
+ it 'should compare version' do
8
+ Debian::AptPkg.cmp_version('1.1', '1.0').must_be :>, 0
9
+ Debian::AptPkg.cmp_version('1.0', '1.0').must_be :==, 0
10
+ Debian::AptPkg.cmp_version('1.0', '1.1').must_be :<, 0
11
+ end
12
+ end
13
+
14
+ describe 'Debian::AptPkg.check_dep' do
15
+ describe 'LessEq' do
16
+ it 'should compare Debian version' do
17
+ Debian::AptPkg.check_dep('1', Debian::AptPkg::LESS_EQ, '2').must_equal true
18
+ Debian::AptPkg.check_dep('2', Debian::AptPkg::LESS_EQ, '1').must_equal false
19
+ Debian::AptPkg.check_dep('1', Debian::AptPkg::LESS_EQ, '1').must_equal true
20
+ end
21
+ end
22
+ describe 'GreaterEq' do
23
+ it 'should compare Debian version' do
24
+ Debian::AptPkg.check_dep('1', Debian::AptPkg::GREATER_EQ, '2').must_equal false
25
+ Debian::AptPkg.check_dep('2', Debian::AptPkg::GREATER_EQ, '1').must_equal true
26
+ Debian::AptPkg.check_dep('1', Debian::AptPkg::GREATER_EQ, '1').must_equal true
27
+ end
28
+ end
29
+ describe 'Less' do
30
+ it 'should compare Debian version' do
31
+ Debian::AptPkg.check_dep('1', Debian::AptPkg::LESS, '2').must_equal true
32
+ Debian::AptPkg.check_dep('2', Debian::AptPkg::LESS, '1').must_equal false
33
+ Debian::AptPkg.check_dep('1', Debian::AptPkg::LESS, '1').must_equal false
34
+ end
35
+ end
36
+ describe 'Greater' do
37
+ it 'should compare Debian version' do
38
+ Debian::AptPkg.check_dep('1', Debian::AptPkg::GREATER, '2').must_equal false
39
+ Debian::AptPkg.check_dep('2', Debian::AptPkg::GREATER, '1').must_equal true
40
+ Debian::AptPkg.check_dep('1', Debian::AptPkg::GREATER, '1').must_equal false
41
+ end
42
+ end
43
+ describe 'Equals' do
44
+ it 'should compare Debian version' do
45
+ Debian::AptPkg.check_dep('1', Debian::AptPkg::EQUALS, '2').must_equal false
46
+ Debian::AptPkg.check_dep('2', Debian::AptPkg::EQUALS, '1').must_equal false
47
+ Debian::AptPkg.check_dep('1', Debian::AptPkg::EQUALS, '1').must_equal true
48
+ end
49
+ end
50
+ describe 'NotEquals' do
51
+ it 'should compare Debian version' do
52
+ Debian::AptPkg.check_dep('1', Debian::AptPkg::NOT_EQUALS, '2').must_equal true
53
+ Debian::AptPkg.check_dep('2', Debian::AptPkg::NOT_EQUALS, '1').must_equal true
54
+ Debian::AptPkg.check_dep('1', Debian::AptPkg::NOT_EQUALS, '1').must_equal false
55
+ end
56
+ end
57
+ end
58
+
59
+ describe 'Debian::AptPkg.uri_to_filename' do
60
+ it 'should return a filename which can be used to store the file' do
61
+ Debian::AptPkg.uri_to_filename('http://debian.org/index.html').must_equal 'debian.org_index.html'
62
+ end
63
+ end
64
+
65
+ describe 'Debian::AptPkg.upstream_version' do
66
+ it 'Return the upstream version for the Debian package version given by version' do
67
+ Debian::AptPkg.upstream_version('3.4.15-1+b1').must_equal '3.4.15'
68
+ end
69
+ end
70
+
71
+ describe 'Debian::AptPkg.time_to_str' do
72
+ it 'Format a given duration in human-readable manner' do
73
+ Debian::AptPkg.time_to_str(3601).must_equal '1h 0min 1s'
74
+ end
75
+ end
76
+
77
+ describe 'Debian::AptPkg.size_to_str' do
78
+ it 'Return a string describing the size in a human-readable manner' do
79
+ Debian::AptPkg.size_to_str(10000).must_equal '10.0 k'
80
+ end
81
+ end
82
+
83
+ describe 'Debian::AptPkg.string_to_bool' do
84
+ it 'Parse the string input and return a boolean' do
85
+ Debian::AptPkg.string_to_bool('yes').must_equal 1
86
+ Debian::AptPkg.string_to_bool('no').must_equal 0
87
+ Debian::AptPkg.string_to_bool('no-recognized').must_equal -1
88
+ end
89
+ end
90
+
91
+ describe 'Debian::AptPkg.check_domain_list' do
92
+ it 'See if the host name given by host is one of the domains given' do
93
+ Debian::AptPkg.check_domain_list("alioth.debian.org", "debian.net,debian.org").must_equal true
94
+ Debian::AptPkg.check_domain_list("git.debian.org", "spkdev.net").must_equal false
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,7 @@
1
+ # encoding: UTF-8
2
+ $VERBOSE = true
3
+ require 'minitest/autorun'
4
+ require 'minitest/pride'
5
+ require 'pp'
6
+
7
+ require_relative '../lib/apt_pkg'
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: apt-pkg
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Laurent Arnoud
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake-compiler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rdoc
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Ruby interface to apt-pkg
70
+ email: laurent@spkdev.net
71
+ executables: []
72
+ extensions:
73
+ - ext/apt_pkg/extconf.rb
74
+ extra_rdoc_files:
75
+ - README.md
76
+ files:
77
+ - .gitignore
78
+ - Gemfile
79
+ - LICENSE
80
+ - README.md
81
+ - Rakefile
82
+ - apt-pkg.gemspec
83
+ - ext/apt_pkg/apt-pkg.cpp
84
+ - ext/apt_pkg/extconf.rb
85
+ - test/apt_pkg_test.rb
86
+ - test/test_helper.rb
87
+ homepage: http://github.com/spk/ruby-apt-pkg
88
+ licenses:
89
+ - MIT
90
+ metadata: {}
91
+ post_install_message:
92
+ rdoc_options:
93
+ - --charset=UTF-8
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - '>='
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - '>='
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 2.0.14
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: Ruby interface to apt-pkg
112
+ test_files: []