apt-pkg 0.0.4 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 746f8355732d3706f08ed9a0448074b5cc809650
4
- data.tar.gz: 4e790f19af21ca58fb505e253b0063a9f37a403c
3
+ metadata.gz: f84dc3e1846ba85b0b390fab4f2bc79df60be2f8
4
+ data.tar.gz: 8a01ee86fb7e14569a3ddca653f65c6a57fa38de
5
5
  SHA512:
6
- metadata.gz: 0847ba542a425cf905fc8b1f9878e61d95567ad5edc8701d787b7aeb6890a8907f31a535b7159b43443b79a22c29f0d69ce7df77baec6801318ce42550acfa0e
7
- data.tar.gz: c78871b2f29b15180af494de3d6b822c257da1dca3fb3a43af0e6890219ce10e6e44a8ab33658bd4932688241897d6f36e8992da3b672e8365d70470601ca35c
6
+ metadata.gz: 0351a2ebd626836792954809677e899c6b2bb4689088583421ba63efb6d723e7395967f614a37f0fa25c441bf22b28f2210540842e3c6d0585aee7aea2284c56
7
+ data.tar.gz: 6791a8180fa9a6abe2da1f071a0c7ce76aa320bf641893e2a3d86dc07a14bd681b05db6d1364fb94ddab6af5ddade6a8ace3388e4c102283f598baaed2cf502f
data/History.md CHANGED
@@ -1,6 +1,14 @@
1
1
 
2
+ 0.1.0 / 2015-12-20
3
+ ==================
4
+
5
+ * Change VERSION, APT_VERSION and LIBAPT_PKG_VERSION
6
+ * Add cache count methods
7
+ * Fix rake lint task exit status
8
+ * Fix syntax offences
9
+
2
10
  0.0.4 / 2015-12-19
3
11
  ==================
4
12
 
5
- * Simple search with `Debian::AptPkg::PkgCache.pkg_names("vim")`
6
- * Documentation update
13
+ * Simple search with `Debian::AptPkg::PkgCache.pkg_names("vim")`
14
+ * Documentation update
data/README.md CHANGED
@@ -17,7 +17,7 @@ gem install apt-pkg
17
17
  Simple search is implemented with:
18
18
 
19
19
  ~~~ ruby
20
- require 'apt_pkg'
20
+ require 'debian/apt_pkg'
21
21
  Debian::AptPkg::PkgCache.pkg_names("vim")
22
22
  ~~~
23
23
 
@@ -180,9 +180,10 @@ Init_apt_pkg() {
180
180
  rb_define_const(rb_mDebianAptPkg, "NOT_EQUALS", INT2FIX(pkgCache::Dep::NotEquals));
181
181
 
182
182
  /* Represents the version of apt. */
183
- rb_define_const(rb_mDebianAptPkg, "VERSION", rb_str_new2(pkgVersion));
183
+ rb_define_const(rb_mDebianAptPkg, "APT_VERSION", rb_str_new2(pkgVersion));
184
184
  /* Represents the version of apt_pkg library. */
185
- rb_define_const(rb_mDebianAptPkg, "LIB_VERSION", rb_str_new2(pkgLibVersion));
185
+ rb_define_const(rb_mDebianAptPkg, "LIBAPT_PKG_VERSION",
186
+ rb_str_new2(pkgLibVersion));
186
187
 
187
188
  init_apt_pkg_configuration();
188
189
  init_apt_pkg_pkgcache();
@@ -1,7 +1,7 @@
1
1
  require 'mkmf'
2
2
 
3
- have_library("stdc++")
4
- have_library("apt-pkg")
3
+ have_library('stdc++')
4
+ have_library('apt-pkg')
5
5
 
6
6
  dir_config('apt_pkg')
7
7
 
@@ -19,7 +19,7 @@ VALUE gen_caches(VALUE self) {
19
19
  * call-seq: pkg_names() -> array, nil
20
20
  *
21
21
  * List the names of all packages in the system.
22
- * Return nil when cache is not generated.
22
+ * Return `nil` when cache is not generated.
23
23
  *
24
24
  * Debian::AptPkg::PkgCache.pkg_names('gcolor2') # => ["gcolor2"]
25
25
  *
@@ -51,6 +51,139 @@ VALUE pkg_names(int argc, VALUE* argv, VALUE self) {
51
51
  return result;
52
52
  }
53
53
 
54
+ /*
55
+ * call-seq: package_count() -> int, nil
56
+ *
57
+ * The total number of packages available in the cache.
58
+ * Return `nil` when cache is not generated.
59
+ *
60
+ * Debian::AptPkg::PkgCache.package_count # => 69511
61
+ *
62
+ **/
63
+ static
64
+ VALUE package_count(VALUE self) {
65
+ pkgCacheFile CacheFile;
66
+ pkgCache *Cache = CacheFile.GetPkgCache();
67
+ if (Cache == NULL) {
68
+ return Qnil;
69
+ }
70
+ return INT2FIX(Cache->HeaderP->PackageCount);
71
+ }
72
+
73
+ /*
74
+ * call-seq: version_count() -> int, nil
75
+ *
76
+ * The total number of package versions available in the cache.
77
+ * Return `nil` when cache is not generated.
78
+ *
79
+ * Debian::AptPkg::PkgCache.version_count # => 84630
80
+ *
81
+ **/
82
+ static
83
+ VALUE version_count(VALUE self) {
84
+ pkgCacheFile CacheFile;
85
+ pkgCache *Cache = CacheFile.GetPkgCache();
86
+ if (Cache == NULL) {
87
+ return Qnil;
88
+ }
89
+ return INT2FIX(Cache->HeaderP->VersionCount);
90
+ }
91
+
92
+ /*
93
+ * call-seq: depends_count() -> int, nil
94
+ *
95
+ * The total number of dependencies stored in the cache.
96
+ * Return `nil` when cache is not generated.
97
+ *
98
+ * Debian::AptPkg::PkgCache.depends_count # => 551983
99
+ *
100
+ **/
101
+ static
102
+ VALUE depends_count(VALUE self) {
103
+ pkgCacheFile CacheFile;
104
+ pkgCache *Cache = CacheFile.GetPkgCache();
105
+ if (Cache == NULL) {
106
+ return Qnil;
107
+ }
108
+ return INT2FIX(Cache->HeaderP->DependsCount);
109
+ }
110
+
111
+ /*
112
+ * call-seq: package_file_count() -> int, nil
113
+ *
114
+ * The total number of packages files available.
115
+ * Return `nil` when cache is not generated.
116
+ *
117
+ * Debian::AptPkg::PkgCache.package_file_count # => 17
118
+ *
119
+ **/
120
+ static
121
+ VALUE package_file_count(VALUE self) {
122
+ pkgCacheFile CacheFile;
123
+ pkgCache *Cache = CacheFile.GetPkgCache();
124
+ if (Cache == NULL) {
125
+ return Qnil;
126
+ }
127
+ return INT2FIX(Cache->HeaderP->PackageFileCount);
128
+ }
129
+
130
+ /*
131
+ * call-seq: ver_file_count() -> int, nil
132
+ *
133
+ * The total number of version and package file relations stored in the cache.
134
+ * Return `nil` when cache is not generated.
135
+ *
136
+ * Debian::AptPkg::PkgCache.ver_file_count # => 11274
137
+ *
138
+ **/
139
+ static
140
+ VALUE ver_file_count(VALUE self) {
141
+ pkgCacheFile CacheFile;
142
+ pkgCache *Cache = CacheFile.GetPkgCache();
143
+ if (Cache == NULL) {
144
+ return Qnil;
145
+ }
146
+ return INT2FIX(Cache->HeaderP->VerFileCount);
147
+ }
148
+
149
+ /*
150
+ * call-seq: provides_count() -> int, nil
151
+ *
152
+ * The number of provided packages.
153
+ * Return `nil` when cache is not generated.
154
+ *
155
+ * Debian::AptPkg::PkgCache.provides_count # => 69511
156
+ *
157
+ **/
158
+ static
159
+ VALUE provides_count(VALUE self) {
160
+ pkgCacheFile CacheFile;
161
+ pkgCache *Cache = CacheFile.GetPkgCache();
162
+ if (Cache == NULL) {
163
+ return Qnil;
164
+ }
165
+ return INT2FIX(Cache->HeaderP->ProvidesCount);
166
+ }
167
+
168
+ /*
169
+ * call-seq: group_count() -> int, nil
170
+ *
171
+ * The number of groups in the cache.
172
+ * Return `nil` when cache is not generated.
173
+ *
174
+ * Debian::AptPkg::PkgCache.group_count # => 16730
175
+ *
176
+ **/
177
+ static
178
+ VALUE group_count(VALUE self) {
179
+ pkgCacheFile CacheFile;
180
+ pkgCache *Cache = CacheFile.GetPkgCache();
181
+ if (Cache == NULL) {
182
+ return Qnil;
183
+ }
184
+ return INT2FIX(Cache->HeaderP->GroupCount);
185
+ }
186
+
54
187
  void
55
188
  init_apt_pkg_pkgcache() {
56
189
  VALUE rb_mDebian = rb_define_module("Debian");
@@ -62,4 +195,19 @@ init_apt_pkg_pkgcache() {
62
195
  RUBY_METHOD_FUNC(gen_caches), 0);
63
196
  rb_define_singleton_method(rb_mDebianAptPkgConfiguration, "pkg_names",
64
197
  RUBY_METHOD_FUNC(pkg_names), -1);
198
+
199
+ rb_define_singleton_method(rb_mDebianAptPkgConfiguration, "package_count",
200
+ RUBY_METHOD_FUNC(package_count), 0);
201
+ rb_define_singleton_method(rb_mDebianAptPkgConfiguration, "version_count",
202
+ RUBY_METHOD_FUNC(version_count), 0);
203
+ rb_define_singleton_method(rb_mDebianAptPkgConfiguration, "depends_count",
204
+ RUBY_METHOD_FUNC(depends_count), 0);
205
+ rb_define_singleton_method(rb_mDebianAptPkgConfiguration, "package_file_count",
206
+ RUBY_METHOD_FUNC(package_file_count), 0);
207
+ rb_define_singleton_method(rb_mDebianAptPkgConfiguration, "ver_file_count",
208
+ RUBY_METHOD_FUNC(ver_file_count), 0);
209
+ rb_define_singleton_method(rb_mDebianAptPkgConfiguration, "provides_count",
210
+ RUBY_METHOD_FUNC(provides_count), 0);
211
+ rb_define_singleton_method(rb_mDebianAptPkgConfiguration, "group_count",
212
+ RUBY_METHOD_FUNC(group_count), 0);
65
213
  }
@@ -0,0 +1,2 @@
1
+ require 'apt_pkg'
2
+ require 'debian/apt_pkg/version'
@@ -0,0 +1,8 @@
1
+ # Debian::AptPkg version file
2
+ module Debian
3
+ # AptPkg base module
4
+ module AptPkg
5
+ # Gem version
6
+ VERSION = '0.1.0'.freeze
7
+ end
8
+ end
@@ -12,28 +12,41 @@ describe Debian::AptPkg::PkgCache do
12
12
  end
13
13
 
14
14
  describe '.pkg_names' do
15
- it 'argument' do
16
- lambda {
15
+ it 'no argument' do
16
+ lambda do
17
17
  Debian::AptPkg::PkgCache.pkg_names
18
- }.must_raise ArgumentError
19
-
20
- lambda {
18
+ end.must_raise ArgumentError
19
+ end
20
+ it 'nil argument' do
21
+ lambda do
21
22
  Debian::AptPkg::PkgCache.pkg_names(nil)
22
- }.must_raise ArgumentError
23
+ end.must_raise ArgumentError
24
+ end
23
25
 
24
- lambda {
25
- Debian::AptPkg::PkgCache.pkg_names("")
26
- }.must_raise ArgumentError
26
+ it 'blank argument' do
27
+ lambda do
28
+ Debian::AptPkg::PkgCache.pkg_names('')
29
+ end.must_raise ArgumentError
27
30
  end
28
31
 
29
32
  it 'be filtered' do
30
- search = Debian::AptPkg::PkgCache.pkg_names("vim")
33
+ search = Debian::AptPkg::PkgCache.pkg_names('vim')
31
34
  # CI specific cache can not be present
32
35
  unless search.nil? || search.empty?
33
- search.must_include "vim"
34
- search.must_include "vim-nox"
35
- search.must_include "vim-gtk"
36
- search.wont_include "emacs"
36
+ search.must_include 'vim'
37
+ search.must_include 'vim-nox'
38
+ search.must_include 'vim-gtk'
39
+ search.wont_include 'emacs'
40
+ end
41
+ end
42
+ end
43
+
44
+ %i(package version depends package_file ver_file provides group).each do |m|
45
+ describe ".#{m}_count" do
46
+ it 'return an int' do
47
+ if Process.uid == 0
48
+ Debian::AptPkg::PkgCache.public_send("#{m}_count").must_be :>=, 0
49
+ end
37
50
  end
38
51
  end
39
52
  end
@@ -28,9 +28,9 @@ describe Debian::AptPkg::Configuration do
28
28
  end
29
29
 
30
30
  it 'check_language' do
31
- lambda {
31
+ lambda do
32
32
  Debian::AptPkg::Configuration.check_language
33
- }.must_raise ArgumentError
33
+ end.must_raise ArgumentError
34
34
 
35
35
  langs = Debian::AptPkg::Configuration.languages
36
36
  Debian::AptPkg::Configuration.check_language(langs.first).must_equal true
@@ -47,28 +47,28 @@ describe Debian::AptPkg::Configuration do
47
47
  end
48
48
 
49
49
  it 'find configuration value' do
50
- lambda {
50
+ lambda do
51
51
  Debian::AptPkg::Configuration.config_find
52
- }.must_raise ArgumentError
52
+ end.must_raise ArgumentError
53
53
 
54
- Debian::AptPkg::Configuration.config_find('Dir::Etc::main').
55
- must_equal "apt.conf"
56
- Debian::AptPkg::Configuration.config_find('Dir::Etc::netrc').
57
- must_equal "auth.conf"
58
- Debian::AptPkg::Configuration.config_find('Dir::Etc::parts').
59
- must_equal "apt.conf.d"
60
- Debian::AptPkg::Configuration.config_find('Spk', 'DebianUser').
61
- must_equal "DebianUser"
54
+ Debian::AptPkg::Configuration.config_find('Dir::Etc::main')
55
+ .must_equal 'apt.conf'
56
+ Debian::AptPkg::Configuration.config_find('Dir::Etc::netrc')
57
+ .must_equal 'auth.conf'
58
+ Debian::AptPkg::Configuration.config_find('Dir::Etc::parts')
59
+ .must_equal 'apt.conf.d'
60
+ Debian::AptPkg::Configuration.config_find('Spk', 'DebianUser')
61
+ .must_equal 'DebianUser'
62
62
  end
63
63
 
64
64
  it 'find file' do
65
- lambda {
65
+ lambda do
66
66
  Debian::AptPkg::Configuration.config_find_file
67
- }.must_raise ArgumentError
67
+ end.must_raise ArgumentError
68
68
 
69
- Debian::AptPkg::Configuration.config_find_file('Dir::Etc::main').
70
- must_equal "/etc/apt/apt.conf"
71
- Debian::AptPkg::Configuration.config_find_file('Dir::Etc::netrc').
72
- must_equal "/etc/apt/auth.conf"
69
+ Debian::AptPkg::Configuration.config_find_file('Dir::Etc::main')
70
+ .must_equal '/etc/apt/apt.conf'
71
+ Debian::AptPkg::Configuration.config_find_file('Dir::Etc::netrc')
72
+ .must_equal '/etc/apt/auth.conf'
73
73
  end
74
74
  end
@@ -1,6 +1,18 @@
1
1
  require_relative 'test_helper'
2
2
 
3
3
  describe Debian::AptPkg do
4
+ it 'gem has a version number' do
5
+ refute_nil Debian::AptPkg::VERSION
6
+ end
7
+
8
+ it 'apt has a version number' do
9
+ refute_nil Debian::AptPkg::APT_VERSION
10
+ end
11
+
12
+ it 'libapt-pkg has a version number' do
13
+ refute_nil Debian::AptPkg::LIBAPT_PKG_VERSION
14
+ end
15
+
4
16
  describe '.cmp_version' do
5
17
  it 'should compare version' do
6
18
  Debian::AptPkg.cmp_version('1.1', '1.0').must_be :>, 0
@@ -52,28 +64,28 @@ describe Debian::AptPkg do
52
64
 
53
65
  describe 'NotEquals' do
54
66
  it 'should compare Debian version' do
55
- Debian::AptPkg.check_dep('1', Debian::AptPkg::NOT_EQUALS, '2').
56
- must_equal true
57
- Debian::AptPkg.check_dep('2', Debian::AptPkg::NOT_EQUALS, '1').
58
- must_equal true
59
- Debian::AptPkg.check_dep('1', Debian::AptPkg::NOT_EQUALS, '1').
60
- must_equal false
67
+ Debian::AptPkg.check_dep('1', Debian::AptPkg::NOT_EQUALS, '2')
68
+ .must_equal true
69
+ Debian::AptPkg.check_dep('2', Debian::AptPkg::NOT_EQUALS, '1')
70
+ .must_equal true
71
+ Debian::AptPkg.check_dep('1', Debian::AptPkg::NOT_EQUALS, '1')
72
+ .must_equal false
61
73
  end
62
74
  end
63
75
 
64
76
  describe 'Errors' do
65
77
  it 'should raise argument error with bad comparison' do
66
- lambda {
78
+ lambda do
67
79
  Debian::AptPkg.check_dep('1', 'bad', '2')
68
- }.must_raise ArgumentError
80
+ end.must_raise ArgumentError
69
81
  end
70
82
  end
71
83
  end
72
84
 
73
85
  describe '.uri_to_filename' do
74
86
  it 'should return a filename which can be used to store the file' do
75
- Debian::AptPkg.uri_to_filename('http://debian.org/index.html').
76
- must_equal 'debian.org_index.html'
87
+ Debian::AptPkg.uri_to_filename('http://debian.org/index.html')
88
+ .must_equal 'debian.org_index.html'
77
89
  end
78
90
  end
79
91
 
@@ -91,7 +103,7 @@ describe Debian::AptPkg do
91
103
 
92
104
  describe '.size_to_str' do
93
105
  it 'Return a string describing the size in a human-readable manner' do
94
- Debian::AptPkg.size_to_str(10000).must_equal '10.0 k'
106
+ Debian::AptPkg.size_to_str(10_000).must_equal '10.0 k'
95
107
  end
96
108
  end
97
109
 
@@ -105,10 +117,10 @@ describe Debian::AptPkg do
105
117
 
106
118
  describe '.check_domain_list' do
107
119
  it 'See if the host name given by host is one of the domains given' do
108
- Debian::AptPkg.check_domain_list("alioth.debian.org",
109
- "debian.net,debian.org").must_equal true
110
- Debian::AptPkg.check_domain_list("git.debian.org",
111
- "spkdev.net").must_equal false
120
+ Debian::AptPkg.check_domain_list('alioth.debian.org',
121
+ 'debian.net,debian.org').must_equal true
122
+ Debian::AptPkg.check_domain_list('git.debian.org',
123
+ 'spkdev.net').must_equal false
112
124
  end
113
125
  end
114
126
  end
@@ -3,4 +3,4 @@ require 'minitest/autorun'
3
3
  require 'minitest/pride'
4
4
  require 'pp'
5
5
 
6
- require_relative '../lib/apt_pkg'
6
+ require_relative '../lib/debian/apt_pkg'
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.0.4
4
+ version: 0.1.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: 2015-12-19 00:00:00.000000000 Z
11
+ date: 2015-12-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -75,6 +75,8 @@ files:
75
75
  - ext/apt_pkg/extconf.rb
76
76
  - ext/apt_pkg/pkgcache.cpp
77
77
  - ext/apt_pkg/pkgcache.h
78
+ - lib/debian/apt_pkg.rb
79
+ - lib/debian/apt_pkg/version.rb
78
80
  - test/apt_pkg_cache_test.rb
79
81
  - test/apt_pkg_configuration_test.rb
80
82
  - test/apt_pkg_test.rb
@@ -105,4 +107,3 @@ signing_key:
105
107
  specification_version: 4
106
108
  summary: Ruby interface to libapt-pkg
107
109
  test_files: []
108
- has_rdoc: