sys-uname 0.7.4 → 0.8.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.
Files changed (9) hide show
  1. data/CHANGES +12 -0
  2. data/MANIFEST +12 -16
  3. data/README +8 -13
  4. data/Rakefile +72 -0
  5. data/doc/uname.txt +4 -4
  6. data/ext/extconf.rb +1 -20
  7. data/ext/uname.c +40 -34
  8. data/test/tc_uname.rb +9 -30
  9. metadata +6 -4
data/CHANGES CHANGED
@@ -1,3 +1,15 @@
1
+ == 0.8.0 - 10-Apr-2007
2
+ * The Uname.model method should now work on most BSD platforms, not just OS X,
3
+ since it uses the sysctl() function behind the scenes.
4
+ * The 'id' method was changed to 'id_number' on HP-UX to avoid confusion with
5
+ the Object.id method.
6
+ * The UnameError class is now Uname::Error.
7
+ * Added a Rakefile. There are now tasks for building, testing and installing
8
+ this package.
9
+ * Removed some pre-setup code from the test suite that was no longer necessary
10
+ as a result of the Rake test task.
11
+ * No code changes.
12
+
1
13
  == 0.7.4 - 19-Nov-2006
2
14
  * Internal layout changes, doc updates and gemspec improvements.
3
15
  * No code changes.
data/MANIFEST CHANGED
@@ -1,16 +1,12 @@
1
- install.rb
2
- MANIFEST
3
- CHANGES
4
- README
5
- sys-uname.gemspec
6
-
7
- doc/uname.txt
8
-
9
- examples/uname_test.rb
10
-
11
- ext/extconf.rb
12
- ext/uname.c
13
-
14
- lib/sys/uname.rb
15
-
16
- test/tc_uname.rb
1
+ * install.rb
2
+ * MANIFEST
3
+ * CHANGES
4
+ * Rakefile
5
+ * README
6
+ * sys-uname.gemspec
7
+ * doc/uname.txt
8
+ * examples/uname_test.rb
9
+ * ext/extconf.rb
10
+ * ext/uname.c
11
+ * lib/sys/uname.rb
12
+ * test/tc_uname.rb
data/README CHANGED
@@ -6,14 +6,8 @@
6
6
  Active WMI service (normally on by default).
7
7
 
8
8
  = Installation
9
- === Unix
10
- ruby extconf.rb
11
- make
12
- ruby test/tc_uname.rb (optional)
13
- make site-install
14
- === MS Windows
15
- ruby test\tc_uname.rb (optional)
16
- ruby install.rb
9
+ rake test (optional)
10
+ rake install (non-gem) or rake install_gem (gems)
17
11
 
18
12
  = Synopsis
19
13
  require 'sys/uname'
@@ -25,12 +19,13 @@
25
19
  Folks building this package on SunOS get two extra methods: architecture()
26
20
  and platform()
27
21
 
28
- = OS X Notes
29
- OS X users get the extra method "model()".
22
+ = BSD flavors, including OS X
23
+ Users on BSD platforms get the extra Uname.model method.
30
24
 
31
25
  = HP-UX Notes
32
- HP-UX users get the extra method "id()". This is actually a String, not
33
- a Fixnum, because that's how it's defined in the utsname struct.
26
+ HP-UX users get the extra Uname.id_number method. This is actually a
27
+ String, not a Fixnum, because that's how it's defined in the utsname
28
+ struct.
34
29
 
35
30
  = MS Windows Notes
36
31
  The C version for Windows has been completely scrapped in favor of an OLE
@@ -39,4 +34,4 @@
39
34
  UnameStruct members mean.
40
35
 
41
36
  = Documentation
42
- For more details, see the 'uname.txt' file under the 'doc' directory.
37
+ For more details, see the 'uname.txt' file under the 'doc' directory.
data/Rakefile ADDED
@@ -0,0 +1,72 @@
1
+ require 'rake'
2
+ require 'rake/clean'
3
+ require 'rake/testtask'
4
+
5
+ desc "Clean the build files for the sys-uname source for UNIX systems"
6
+ task :clean do
7
+ FileUtils.rm_rf('sys') if File.exists?('sys')
8
+
9
+ Dir.chdir('ext') do
10
+ unless RUBY_PLATFORM.match('mswin')
11
+ FileUtils.rm_rf('sys') if File.exists?('sys')
12
+ build_file = 'uname.' + Config::CONFIG['DLEXT']
13
+ sh 'make distclean' if File.exists?(build_file)
14
+ end
15
+ end
16
+ end
17
+
18
+ desc "Build the sys-uname package on UNIX systems (but don't install it)"
19
+ task :build => [:clean] do
20
+ Dir.chdir('ext') do
21
+ unless RUBY_PLATFORM.match('mswin')
22
+ ruby 'extconf.rb'
23
+ sh 'make'
24
+ build_file = 'uname.' + Config::CONFIG['DLEXT']
25
+ Dir.mkdir('sys') unless File.exists?('sys')
26
+ FileUtils.cp(build_file, 'sys')
27
+ end
28
+ end
29
+ end
30
+
31
+ desc "Run the example program"
32
+ task :example => [:build] do
33
+ Dir.mkdir('sys') unless File.exists?('sys')
34
+ if RUBY_PLATFORM.match('mswin')
35
+ sh 'ruby -Ilib examples/uname_test.rb'
36
+ else
37
+ sh 'ruby -Iext examples/uname_test.rb'
38
+ end
39
+ end
40
+
41
+ if RUBY_PLATFORM.match('mswin')
42
+ desc "Install the sys-uname package (non-gem)"
43
+ task :install do
44
+ sh 'ruby install.rb'
45
+ end
46
+ else
47
+ desc "Install the sys-uname package"
48
+ task :install => [:build] do
49
+ Dir.chdir('ext') do
50
+ sh 'make install'
51
+ end
52
+ end
53
+ end
54
+
55
+ desc "Install the sys-uname package as a gem"
56
+ task :install_gem do
57
+ ruby 'sys-uname.gemspec'
58
+ file = Dir['sys-uname*.gem'].first
59
+ sh "gem install #{file}"
60
+ end
61
+
62
+ desc "Run the test suite"
63
+ Rake::TestTask.new("test") do |t|
64
+ if RUBY_PLATFORM.match('mswin')
65
+ t.libs << 'lib'
66
+ else
67
+ task :test => :build
68
+ t.libs << 'ext'
69
+ t.libs.delete('lib')
70
+ end
71
+ t.test_files = FileList['test/tc_uname.rb']
72
+ end
data/doc/uname.txt CHANGED
@@ -76,7 +76,7 @@ Uname.dhcp_cache
76
76
  interface configured by boot(1M) followed by the DHCPACK reply from
77
77
  the server.
78
78
 
79
- == OS X Only
79
+ == BSD Platforms Only (including OS X)
80
80
  Uname.model
81
81
  Returns the model type, e.g. "PowerBook5,1"
82
82
 
@@ -105,7 +105,7 @@ Uname.id
105
105
  Ruby's
106
106
 
107
107
  == Copyright
108
- (C) 2002-2006 Daniel J. Berger
108
+ (C) 2002-2007 Daniel J. Berger
109
109
  All Rights Reserved
110
110
 
111
111
  == Warranty
@@ -115,8 +115,8 @@ Uname.id
115
115
 
116
116
  == Author
117
117
  Daniel Berger
118
- djberg96 at gmail dot com
118
+ djberg96 at nospam at gmail dot com
119
119
  imperator on IRC (Freenode)
120
120
 
121
121
  == See Also
122
- uname(1) for unix, or WMI for MS Windows.
122
+ uname(1) for unix, or WMI for MS Windows.
data/ext/extconf.rb CHANGED
@@ -1,28 +1,9 @@
1
- ##########################
2
- # extconf.rb - sys-uname
3
- ##########################
4
1
  require 'mkmf'
5
2
 
6
- if PLATFORM.match('mswin')
7
- STDERR.puts "Run 'ruby install.rb' instead for Windows"
8
- STDERR.puts "Exiting..."
9
- exit
10
- end
3
+ have_func('sysctl')
11
4
 
12
5
  if RUBY_PLATFORM =~ /sunos|solaris/i
13
6
  have_header('sys/systeminfo.h')
14
7
  end
15
8
 
16
- ########################################################################
17
- # Move any ".rb" files under 'lib/sys/' to ".orig" to prevent mkmf from
18
- # installing them during the 'make install' phase.
19
- ########################################################################
20
- if File.basename(Dir.pwd) == 'ext'
21
- Dir.chdir('..'){
22
- Dir["lib/sys/*.rb"].each{ |f|
23
- File.rename(f, 'lib/sys/' + File.basename(f, '.rb')+ '.orig')
24
- }
25
- }
26
- end
27
-
28
9
  create_makefile('sys/uname')
data/ext/uname.c CHANGED
@@ -1,14 +1,12 @@
1
1
  /******************************************************************************
2
- * unix.c (uname.c) - Ruby Extension for *nix (POSIX?) operating systems.
2
+ * uname.c - Ruby extension for returning uname information on Unix platforms.
3
3
  *
4
- * Author(s):
5
- * Daniel Berger (primary)
6
- * Mike Hall (OS X patch)
4
+ * Author: Daniel Berger
7
5
  *****************************************************************************/
8
- #include "ruby.h"
6
+ #include <ruby.h>
9
7
  #include <sys/utsname.h>
10
8
 
11
- #define SYS_UNAME_VERSION "0.7.4"
9
+ #define SYS_UNAME_VERSION "0.8.0"
12
10
 
13
11
  /* Solaris */
14
12
  #ifdef HAVE_SYS_SYSTEMINFO_H
@@ -16,10 +14,10 @@
16
14
  #include <sys/systeminfo.h>
17
15
  #endif
18
16
 
19
- /* OS X - use Darwin's 'sysctl()' to get the model name */
20
- #if defined(__MACH__) && defined(__APPLE__)
17
+ /* BSD platforms, including OS X */
18
+ #ifdef HAVE_SYSCTL
21
19
  #include <sys/sysctl.h>
22
- static int getmodel(char *buf, int n)
20
+ static int get_model(char *buf, int n)
23
21
  {
24
22
  size_t sz = n;
25
23
  int mib[2];
@@ -40,7 +38,7 @@ VALUE sUname;
40
38
  /*
41
39
  * Returns a struct of type UnameStruct that contains sysname, nodename,
42
40
  * machine, version, and release. On Solaris, it will also include
43
- * architecture and platform. On HP-UX, it will also include id.
41
+ * architecture and platform. On HP-UX, it will also include id_number.
44
42
  */
45
43
  static VALUE uname_uname_all()
46
44
  {
@@ -52,13 +50,13 @@ static VALUE uname_uname_all()
52
50
  #ifdef HAVE_SYS_SYSTEMINFO_H
53
51
  char platform[BUFSIZE];
54
52
  char arch[BUFSIZE];
55
- sysinfo(SI_ARCHITECTURE,arch,BUFSIZE);
56
- sysinfo(SI_PLATFORM,platform,BUFSIZE);
53
+ sysinfo(SI_ARCHITECTURE, arch, BUFSIZE);
54
+ sysinfo(SI_PLATFORM, platform, BUFSIZE);
57
55
  #endif
58
56
 
59
- #if defined(__MACH__) && defined(__APPLE__)
57
+ #ifdef HAVE_SYSCTL
60
58
  char model[BUFSIZ];
61
- getmodel(model, sizeof(model));
59
+ get_model(model, sizeof(model));
62
60
  #endif
63
61
 
64
62
  return rb_struct_new(sUname,
@@ -72,7 +70,7 @@ static VALUE uname_uname_all()
72
70
  rb_str_new2(platform)
73
71
  #endif
74
72
 
75
- #if defined(__MACH__) && defined(__APPLE__)
73
+ #ifdef HAVE_SYSCTL
76
74
  ,rb_str_new2(model)
77
75
  #endif
78
76
 
@@ -125,7 +123,7 @@ static VALUE uname_release()
125
123
  }
126
124
 
127
125
  /*
128
- * Returns the operating system name. e.g. "SunOS".
126
+ * Returns the operating system name. e.g. "SunOS".
129
127
  */
130
128
  static VALUE uname_sysname()
131
129
  {
@@ -141,17 +139,17 @@ static VALUE uname_sysname()
141
139
  static VALUE uname_architecture()
142
140
  {
143
141
  char buf[BUFSIZE];
144
- sysinfo(SI_ARCHITECTURE,buf,BUFSIZE);
142
+ sysinfo(SI_ARCHITECTURE, buf, BUFSIZE);
145
143
  return rb_str_new2(buf);
146
144
  }
147
145
 
148
146
  /*
149
- * Returns the platform identifier. e.g. "SUNW,Sun-Blade-100".
147
+ * Returns the platform identifier. e.g. "SUNW,Sun-Blade-100".
150
148
  */
151
149
  static VALUE uname_platform()
152
150
  {
153
151
  char buf[BUFSIZE];
154
- sysinfo(SI_PLATFORM,buf,BUFSIZE);
152
+ sysinfo(SI_PLATFORM, buf, BUFSIZE);
155
153
  return rb_str_new2(buf);
156
154
  }
157
155
 
@@ -165,7 +163,7 @@ static VALUE uname_platform()
165
163
  static VALUE uname_isalist()
166
164
  {
167
165
  char buf[BUFSIZE];
168
- sysinfo(SI_ISALIST,buf,BUFSIZE);
166
+ sysinfo(SI_ISALIST, buf, BUFSIZE);
169
167
  return rb_str_new2(buf);
170
168
  }
171
169
  #endif
@@ -176,7 +174,7 @@ static VALUE uname_isalist()
176
174
  static VALUE uname_hw_provider()
177
175
  {
178
176
  char buf[BUFSIZE];
179
- sysinfo(SI_HW_PROVIDER,buf,BUFSIZE);
177
+ sysinfo(SI_HW_PROVIDER, buf, BUFSIZE);
180
178
  return rb_str_new2(buf);
181
179
  }
182
180
 
@@ -187,7 +185,7 @@ static VALUE uname_hw_provider()
187
185
  static VALUE uname_hw_serial()
188
186
  {
189
187
  char buf[BUFSIZE];
190
- sysinfo(SI_HW_SERIAL,buf,BUFSIZE);
188
+ sysinfo(SI_HW_SERIAL, buf, BUFSIZE);
191
189
  return rb_Integer(rb_str_new2(buf));
192
190
  }
193
191
 
@@ -197,7 +195,7 @@ static VALUE uname_hw_serial()
197
195
  static VALUE uname_srpc_domain()
198
196
  {
199
197
  char buf[BUFSIZE];
200
- sysinfo(SI_SRPC_DOMAIN,buf,BUFSIZE);
198
+ sysinfo(SI_SRPC_DOMAIN, buf, BUFSIZE);
201
199
  return rb_str_new2(buf);
202
200
  }
203
201
 
@@ -210,27 +208,27 @@ static VALUE uname_srpc_domain()
210
208
  static VALUE uname_dhcp_cache()
211
209
  {
212
210
  char buf[BUFSIZE];
213
- sysinfo(SI_DHCP_CACHE,buf,BUFSIZE);
211
+ sysinfo(SI_DHCP_CACHE, buf, BUFSIZE);
214
212
  return rb_str_new2(buf);
215
213
  }
216
214
  #endif
217
215
  #endif
218
216
 
219
- #if defined(__MACH__) && defined(__APPLE__)
217
+ #ifdef HAVE_SYSCTL
220
218
  /*
221
219
  * Returns the model type, e.g. "PowerBook5,1"
222
220
  */
223
221
  static VALUE uname_model()
224
222
  {
225
223
  char model[BUFSIZ];
226
- getmodel(model, sizeof(model));
224
+ get_model(model, sizeof(model));
227
225
  return rb_str_new2(model);
228
226
  }
229
227
  #endif
230
228
 
231
229
  #if defined(__hpux)
232
230
  /*
233
- * Returns the id number, e.g. 234233587. This is a String, not a Fixnum.
231
+ * Returns the id number, e.g. 234233587. This is a string, not a number.
234
232
  */
235
233
  static VALUE uname_id()
236
234
  {
@@ -243,10 +241,15 @@ static VALUE uname_id()
243
241
  /* An interface for returning uname (platform) information. */
244
242
  void Init_uname()
245
243
  {
246
- VALUE sys_mSys, cUname;
244
+ VALUE mSys, cUname;
247
245
 
248
- sys_mSys = rb_define_module("Sys");
249
- cUname = rb_define_class_under(sys_mSys, "Uname", rb_cObject);
246
+ /* The Sys module serves only as a toplevel namespace */
247
+ mSys = rb_define_module("Sys");
248
+
249
+ /* The Uname serves as the base class from which system information can
250
+ * be obtained via various class methods.
251
+ */
252
+ cUname = rb_define_class_under(mSys, "Uname", rb_cObject);
250
253
 
251
254
  rb_define_singleton_method(cUname, "sysname", uname_sysname, 0);
252
255
  rb_define_singleton_method(cUname, "nodename",uname_nodename,0);
@@ -269,26 +272,29 @@ void Init_uname()
269
272
  #endif
270
273
  #endif
271
274
 
272
- #if defined(__MACH__) && defined(__APPLE__)
275
+ #ifdef HAVE_SYSCTL
273
276
  rb_define_singleton_method(cUname, "model", uname_model, 0);
274
277
  #endif
275
278
 
276
279
  #if defined(__hpux)
277
- rb_define_singleton_method(cUname, "id", uname_id, 0);
280
+ rb_define_singleton_method(cUname, "id_number", uname_id, 0);
278
281
  #endif
279
282
 
283
+ /* The UnameStruct encapsulates information associated with system
284
+ * information, such as operating system version, release, etc.
285
+ */
280
286
  sUname = rb_struct_define("UnameStruct","sysname","nodename",
281
287
  "machine","version","release",
282
288
  #ifdef HAVE_SYS_SYSTEMINFO_H
283
289
  "architecture","platform",
284
290
  #endif
285
291
 
286
- #if defined(__MACH__) && defined(__APPLE__)
292
+ #ifdef HAVE_SYSCTL
287
293
  "model",
288
294
  #endif
289
295
 
290
296
  #if defined(__hpux)
291
- "id",
297
+ "id_number",
292
298
  #endif
293
299
  NULL);
294
300
 
data/test/tc_uname.rb CHANGED
@@ -1,30 +1,9 @@
1
1
  ##############################################################################
2
2
  # tc_uname.rb
3
3
  #
4
- # Test suite for the sys-uname package.
4
+ # Test suite for the sys-uname package. This test suite should be run via
5
+ # the 'rake test' task.
5
6
  ##############################################################################
6
- base = File.basename(Dir.pwd)
7
-
8
- if base == 'test' || base =~ /sys-uname/
9
- Dir.chdir('..') if base == 'test'
10
-
11
- if RUBY_PLATFORM.match('mswin')
12
- $LOAD_PATH.unshift(Dir.pwd + '/lib')
13
- else
14
- require 'ftools'
15
- require 'rbconfig'
16
- Dir.mkdir('sys') unless File.exists?('sys')
17
- file = 'uname.' + Config::CONFIG['DLEXT']
18
- if File.exists?(file)
19
- File.copy(file, 'sys')
20
- else
21
- File.copy('ext/' + file, 'sys')
22
- end
23
- end
24
-
25
- $LOAD_PATH.unshift(Dir.pwd)
26
- end
27
-
28
7
  require 'sys/uname'
29
8
  require 'test/unit'
30
9
  include Sys
@@ -39,7 +18,7 @@ class TC_Uname < Test::Unit::TestCase
39
18
  assert_not_nil(Uname::VERSION)
40
19
  assert_nothing_raised{ Uname::VERSION }
41
20
  assert_kind_of(String, Uname::VERSION)
42
- assert_equal('0.7.4', Uname::VERSION)
21
+ assert_equal('0.8.0', Uname::VERSION)
43
22
  end
44
23
 
45
24
  def test_machine
@@ -143,7 +122,7 @@ class TC_Uname < Test::Unit::TestCase
143
122
  end
144
123
 
145
124
  def test_model
146
- if RUBY_PLATFORM =~ /darwin|powerpc/i
125
+ if RUBY_PLATFORM =~ /darwin|powerpc|bsd|mach/i
147
126
  assert_respond_to(Uname, :model)
148
127
  assert_nothing_raised{ Uname.model }
149
128
  assert_kind_of(String, Uname.model)
@@ -152,13 +131,13 @@ class TC_Uname < Test::Unit::TestCase
152
131
  end
153
132
  end
154
133
 
155
- def test_id
134
+ def test_id_number
156
135
  if RUBY_PLATFORM =~ /hpux/i
157
- assert_respond_to(Uname, :id)
158
- assert_nothing_raised{ Uname.id }
159
- assert_kind_of(String, Uname.id)
136
+ assert_respond_to(Uname, :id_number)
137
+ assert_nothing_raised{ Uname.id_number }
138
+ assert_kind_of(String, Uname.id_number)
160
139
  else
161
- puts '"id" test skipped on this platform'
140
+ puts '"test_id_number" test skipped on this platform'
162
141
  end
163
142
  end
164
143
 
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.0
2
+ rubygems_version: 0.9.2
3
3
  specification_version: 1
4
4
  name: sys-uname
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.7.4
7
- date: 2006-11-19 00:00:00 -07:00
6
+ version: 0.8.0
7
+ date: 2007-04-11 00:00:00 -06:00
8
8
  summary: An interface for returning uname (platform) information
9
9
  require_paths:
10
10
  - lib
@@ -31,9 +31,10 @@ authors:
31
31
  files:
32
32
  - doc/uname.txt
33
33
  - test/tc_uname.rb
34
- - README
35
34
  - CHANGES
36
35
  - MANIFEST
36
+ - README
37
+ - Rakefile
37
38
  - ext/extconf.rb
38
39
  - ext/uname.c
39
40
  test_files:
@@ -45,6 +46,7 @@ extra_rdoc_files:
45
46
  - README
46
47
  - MANIFEST
47
48
  - doc/uname.txt
49
+ - ext/uname.c
48
50
  executables: []
49
51
 
50
52
  extensions: