sys-uname 1.2.2 → 1.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e5cbd8721570c3681f05f66562a956b366d7839da185a309acc136fceab2f9b8
4
- data.tar.gz: 315ba4bc84cbfb0e1201a78062858218f6652148a37d9e62f90a7200c70d3d50
3
+ metadata.gz: 19e018e416bcea0fd03d4d34554d8ac3f904d7a9c71461966925e5b3d5919cd4
4
+ data.tar.gz: fc9c7883ee6f7a4f17b129c132fa20b1c3ada2b68cb78dbecc2e16687007c93b
5
5
  SHA512:
6
- metadata.gz: 5c22800edea9dfd5b9057fb3fae10a76e88ecbead21e02b8d66ce7b1105294f01efe661d9ae9e9fe9653293acd8966aabd667296c40d1891225fd54289422845
7
- data.tar.gz: 10cad4749fee0e1e6fcd5f531e046ba8f9ce9af354401d065b8d786365aa7e87d6691745e84f164cf3ef87f1a5849b52f815d7c9a517ec839005963c5ca75d7b
6
+ metadata.gz: 516fc8b3658b538eed4a81b28756af79b8d6aadf718d03a4e995b5a2d44c7dcada9b123a19206a4c91da126faed8e3f93d5c8dbdec16fc6afa72aa94240819b4
7
+ data.tar.gz: 9978cc8d5929f4167314ea05c873a05e357008812df1480b8f59a24a8ebddf5c6568a7618a7db83437e02914f3008fc2890c2b9fdfe1b2a1ef04cd4c34c5f6e0
checksums.yaml.gz.sig CHANGED
Binary file
data/CHANGES.md CHANGED
@@ -1,3 +1,14 @@
1
+ ## 1.3.0 - 10-Jun-2024
2
+ * Added DragonflyBSD support.
3
+ * Removed Solaris support, it's dead.
4
+
5
+ ## 1.2.3 - 9-Apr-2023
6
+ * Added rubygems_mfa_required and github_repo to metadata.
7
+ * Miscellaneous rubocop related updates.
8
+ * Fixed one test for Windows.
9
+ * The rubocop and rubocop-rspec gems are now development dependencies.
10
+ * Now assumes Ruby 2.0 or later.
11
+
1
12
  ## 1.2.2 - 30-Oct-2020
2
13
  * Added a Gemfile.
3
14
  * The ffi dependency is now slightly more restrictive.
data/Gemfile CHANGED
@@ -1,7 +1,2 @@
1
- source 'https://rubygems.org' do
2
- gem 'ffi', '~> 1.1'
3
- group 'test' do
4
- gem 'rake'
5
- gem 'rspec', '~> 3.9'
6
- end
7
- end
1
+ source 'https://rubygems.org'
2
+ gemspec
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ [![Ruby](https://github.com/djberg96/sys-uname/actions/workflows/ruby.yml/badge.svg)](https://github.com/djberg96/sys-uname/actions/workflows/ruby.yml)
2
+
1
3
  ## Description
2
4
  A cross-platform Ruby interface for getting operating system information. The name
3
5
  comes from the Unix 'uname' command, but this library works on MS Windows as well.
@@ -8,8 +10,11 @@ ffi 1.0 or later
8
10
  ## Installation
9
11
  `gem install sys-uname`
10
12
 
13
+ ## Adding the trusted cert
14
+ `gem cert --add <(curl -Ls https://raw.githubusercontent.com/djberg96/sys-uname/main/certs/djberg96_pub.pem)`
15
+
11
16
  ## Synopsis
12
- ```
17
+ ```ruby
13
18
  require 'sys/uname' # require 'sys-uname' works, too
14
19
 
15
20
  # You now have Sys::Uname and Sys::Platform classes available.
@@ -22,22 +27,18 @@ p Sys::Platform.linux? # => true
22
27
  p Sys::Platform::ARCH # => :x86_64
23
28
  ```
24
29
 
25
- ## Solaris Notes
26
- Users on SunOS get several extra methods: architecture, platform,
27
- hw_serial, hw_provider, srpc_domain, isa_list, and dhcp_cache.
28
-
29
30
  ## BSD flavors, including OS X
30
- Users on BSD platforms get the extra Uname.model method.
31
+ Users on BSD platforms get the extra `Uname.model` method.
31
32
 
32
33
  ## HP-UX Notes
33
- HP-UX users get the extra Uname.id_number method. This is actually a
34
+ HP-UX users get the extra `Uname.id_number` method. This is actually a
34
35
  String, not a Fixnum, because that's how it's defined in the utsname
35
36
  struct.
36
37
 
37
38
  ## MS Windows Notes
38
39
  The C version for Windows has been completely scrapped in favor of an OLE
39
40
  plus WMI approach. It is pure Ruby. Please see the MSDN documentation for
40
- the Win32_OperatingSystem class for a complete list of what each of the
41
+ the `Win32_OperatingSystem` class for a complete list of what each of the
41
42
  UnameStruct members mean.
42
43
 
43
44
  ## The Platform Class
data/Rakefile CHANGED
@@ -1,8 +1,8 @@
1
1
  require 'rake'
2
- require 'rake/testtask'
3
2
  require 'rake/clean'
4
3
  require 'rbconfig'
5
4
  require 'rspec/core/rake_task'
5
+ require 'rubocop/rake_task'
6
6
 
7
7
  CLEAN.include("**/*.rbc", "**/*.rbx", "**/*.gem", "**/*.lock")
8
8
 
@@ -19,7 +19,7 @@ namespace :gem do
19
19
  desc "Create the sys-uname gem"
20
20
  task :create => [:clean] do
21
21
  require 'rubygems/package'
22
- spec = eval(IO.read('sys-uname.gemspec'))
22
+ spec = Gem::Specification.load('sys-uname.gemspec')
23
23
  spec.signing_key = File.join(Dir.home, '.ssh', 'gem-private_key.pem')
24
24
  Gem::Package.build(spec)
25
25
  end
@@ -31,6 +31,8 @@ namespace :gem do
31
31
  end
32
32
  end
33
33
 
34
+ RuboCop::RakeTask.new
35
+
34
36
  desc "Run the test suite"
35
37
  RSpec::Core::RakeTask.new(:spec)
36
38
 
data/doc/uname.rdoc CHANGED
@@ -26,7 +26,7 @@ VERSION
26
26
 
27
27
  == Class Methods
28
28
  Uname.sysname
29
- Returns the operating system name, e.g. "SunOS"
29
+ Returns the operating system name, e.g. "Darwin".
30
30
 
31
31
  Uname.nodename
32
32
  Returns the nodename. This is usually, but not necessarily, the
@@ -48,41 +48,12 @@ Uname.release
48
48
 
49
49
  Uname.uname
50
50
  Returns a struct of type UnameStruct that contains sysname, nodename,
51
- machine, version, and release. On Solaris, it will also include
52
- architecture and platform. On HP-UX, it will also include id_number.
51
+ machine, version, and release. On HP-UX, it will also include id_number.
53
52
 
54
53
  MS Windows - there are many more, and different, fields in the struct.
55
54
  Please see the MSDN documenation on the Win32_OperatingSystem WMI class
56
55
  for a complete explanation of what each of these members mean.
57
56
 
58
- == Solaris Only
59
- Uname.architecture
60
- Returns the instruction set architecture, e.g. "sparc"
61
-
62
- Uname.platform
63
- Returns the platform identifier, e.g. "SUNW,Sun-Blade-100"
64
-
65
- Uname.isa_list
66
- Returns a space separated string containing a list of all variant
67
- instruction set architectures executable on the current system.
68
-
69
- They are listed in order of performance, from best to worst.
70
-
71
- Uname.hw_provider
72
- Returns the name of the hardware manufacturer.
73
-
74
- Uname.hw_serial_number
75
- Returns the ASCII representation of the hardware-specific serial number
76
- of the machine that executes the function.
77
-
78
- Uname.srpc_domain
79
- Returns the name of the Secure Remote Procedure Call domain, if any.
80
-
81
- Uname.dhcp_cache
82
- Returns a hexidecimal encoding, in String form, of the name of the
83
- interface configured by boot(1M) followed by the DHCPACK reply from
84
- the server.
85
-
86
57
  == BSD Platforms Only (including OS X)
87
58
  Uname.model
88
59
  Returns the model type, e.g. "PowerBook5,1"
@@ -105,14 +76,11 @@ UnameStruct members mean.
105
76
  None that I'm aware of. Please log any bugs on the project page at
106
77
  https://github.com/djberg96/sys-uname
107
78
 
108
- == Future Plans
109
- Add additional info for Linux, Solaris, BSD.
110
-
111
79
  == License
112
80
  Apache-2.0
113
81
 
114
82
  == Copyright
115
- (C) 2002-2020 Daniel J. Berger
83
+ (C) 2002-2024 Daniel J. Berger
116
84
  All Rights Reserved
117
85
 
118
86
  == Warranty
@@ -15,19 +15,7 @@ puts 'Version: ' + Uname.version
15
15
  puts 'Release: ' + Uname.release
16
16
  puts 'Machine: ' + Uname.machine # May be "unknown" on Win32
17
17
 
18
- if RbConfig::CONFIG['host_os'] =~ /sun|solaris/i
19
- print "\nSolaris specific tests\n"
20
- puts "==========================="
21
- puts 'Architecture: ' + Uname.architecture
22
- puts 'Platform: ' + Uname.platform
23
- puts 'Instruction Set List: ' + Uname.isa_list.split.join(", ")
24
- puts 'Hardware Provider: ' + Uname.hw_provider
25
- puts 'Serial Number: ' + Uname.hw_serial_number.to_s
26
- puts 'SRPC Domain: ' + Uname.srpc_domain # might be empty
27
- puts 'DHCP Cache: ' + Uname.dhcp_cache # might be empty
28
- end
29
-
30
- if RbConfig::CONFIG['host_os'] =~ /powerpc|darwin|bsd|mach/i
18
+ if RbConfig::CONFIG['host_os'] =~ /powerpc|darwin|bsd|dragonfly|mach/i
31
19
  print "\nBSD/OS X specific tests\n"
32
20
  puts "======================="
33
21
  puts 'Model: ' + Uname.model
data/lib/sys/platform.rb CHANGED
@@ -1,4 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ # The Sys module is a namespace only.
1
4
  module Sys
5
+ # The Platform class provides singleton methods to tell you what OS you're on.
2
6
  class Platform
3
7
  # The CPU architecture
4
8
  ARCH = File::ALT_SEPARATOR ? Uname.architecture.to_sym : Uname.machine.to_sym
@@ -8,18 +12,16 @@ module Sys
8
12
 
9
13
  # Returns the OS type, :macosx, :linux, :mingw32, etc
10
14
  IMPL = case Uname.sysname
11
- when /darwin|mac/i
12
- :macosx
13
- when /mingw|windows/i
14
- require 'rbconfig'
15
- RbConfig::CONFIG['host_os'].split('_').first[/[a-z]+/i].downcase.to_sym
16
- when /linux/i
17
- :linux
18
- when /sunos|solaris/i
19
- :solaris
20
- when /bsd/i
21
- :bsd
22
- end
15
+ when /darwin|mac/i
16
+ :macosx
17
+ when /mingw|windows/i
18
+ require 'rbconfig'
19
+ RbConfig::CONFIG['host_os'].split('_').first[/[a-z]+/i].downcase.to_sym
20
+ when /linux/i
21
+ :linux
22
+ when /bsd|dragonfly/i
23
+ :bsd
24
+ end
23
25
 
24
26
  # Returns whether or not you're on a Windows OS
25
27
  def self.windows?
@@ -28,7 +30,7 @@ module Sys
28
30
 
29
31
  # Returns whether or not you're on a Unixy (non-Windows) OS
30
32
  def self.unix?
31
- Uname.sysname !~ /microsoft/i ? true : false
33
+ Uname.sysname =~ /microsoft/i ? false : true
32
34
  end
33
35
 
34
36
  # Returns whether or not you're on a mac, i.e. OSX
@@ -41,11 +43,6 @@ module Sys
41
43
  Uname.sysname =~ /linux/i ? true : false
42
44
  end
43
45
 
44
- # Returns whether or not you're on Solaris
45
- def self.solaris?
46
- Uname.sysname =~ /sunos|solaris/i ? true : false
47
- end
48
-
49
46
  # Returns whether or not you're on any BSD platform
50
47
  def self.bsd?
51
48
  Uname.sysname =~ /bsd/i ? true : false
data/lib/sys/uname.rb CHANGED
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Sys
2
4
  class Uname
3
5
  # The version of the sys-uname gem.
4
- VERSION = '1.2.2'.freeze
6
+ VERSION = '1.3.0'
5
7
  end
6
8
 
7
9
  class Platform
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'ffi'
2
4
  require 'rbconfig'
3
5
  require 'ostruct'
@@ -18,10 +20,8 @@ module Sys
18
20
  case RbConfig::CONFIG['host_os']
19
21
  when /linux/i
20
22
  BUFSIZE = 65
21
- when /bsd/i
22
- BUFSIZE = 32 # TODO: version method chopped
23
- when /sunos|solaris/i
24
- BUFSIZE = 257
23
+ when /bsd|dragonfly/i
24
+ BUFSIZE = 32
25
25
  else
26
26
  BUFSIZE = 256
27
27
  end
@@ -30,7 +30,7 @@ module Sys
30
30
  private_class_method :uname_c
31
31
 
32
32
  begin
33
- attach_function :sysctl, [:pointer, :uint, :pointer, :pointer, :pointer, :size_t], :int
33
+ attach_function :sysctl, %i[pointer uint pointer pointer pointer size_t], :int
34
34
  private_class_method :sysctl
35
35
 
36
36
  CTL_HW = 6 # Generic hardware/cpu
@@ -40,7 +40,7 @@ module Sys
40
40
  end
41
41
 
42
42
  begin
43
- attach_function :sysinfo, [:int, :pointer, :long], :long
43
+ attach_function :sysinfo, %i[int pointer long], :long
44
44
  private_class_method :sysinfo
45
45
 
46
46
  SI_SYSNAME = 1 # OS name
@@ -59,6 +59,7 @@ module Sys
59
59
  # Ignore. Not suppored.
60
60
  end
61
61
 
62
+ # FFI class passed to the underlying C uname function.
62
63
  class UnameFFIStruct < FFI::Struct
63
64
  members = [
64
65
  :sysname, [:char, BUFSIZE],
@@ -68,13 +69,8 @@ module Sys
68
69
  :machine, [:char, BUFSIZE]
69
70
  ]
70
71
 
71
- if RbConfig::CONFIG['host_os'] =~ /linux/i
72
- members.push(:domainname, [:char, BUFSIZE])
73
- end
74
-
75
- if RbConfig::CONFIG['host_os'] =~ /hpux/i
76
- members.push(:__id_number, [:char, BUFSIZE])
77
- end
72
+ members.push(:domainname, [:char, BUFSIZE]) if RbConfig::CONFIG['host_os'] =~ /linux/i
73
+ members.push(:__id_number, [:char, BUFSIZE]) if RbConfig::CONFIG['host_os'] =~ /hpux/i
78
74
 
79
75
  layout(*members)
80
76
  end
@@ -87,40 +83,20 @@ module Sys
87
83
  machine
88
84
  ]
89
85
 
90
- if RbConfig::CONFIG['host_os'] =~ /linux/i
91
- fields.push('domainname')
92
- end
93
-
94
- if RbConfig::CONFIG['host_os'] =~ /hpux/i
95
- fields.push('id_number')
96
- end
97
-
98
- if RbConfig::CONFIG['host_os'] =~ /sunos|solaris/i
99
- fields.push(
100
- 'architecture',
101
- 'dhcp_cache',
102
- 'hw_provider',
103
- 'hw_serial',
104
- 'isa_list',
105
- 'platform',
106
- 'srpc_domain'
107
- )
108
- end
86
+ fields.push('domainname') if RbConfig::CONFIG['host_os'] =~ /linux/i
87
+ fields.push('id_number') if RbConfig::CONFIG['host_os'] =~ /hpux/i
88
+ fields.push('model') if RbConfig::CONFIG['host_os'] =~ /darwin|bsd|dragonfly/i
109
89
 
110
- if RbConfig::CONFIG['host_os'] =~ /darwin|bsd/i
111
- fields.push('model')
112
- end
90
+ private_constant :UnameFFIStruct
113
91
 
114
92
  # :startdoc:
115
93
 
116
- UnameStruct = Struct.new("UnameStruct", *fields)
94
+ UnameStruct = Struct.new('UnameStruct', *fields)
117
95
 
118
96
  # Returns a struct that contains the sysname, nodename, machine, version
119
97
  # and release of your system.
120
98
  #
121
- # On OS X it will also include the model.
122
- #
123
- # On Solaris, it will also include the architecture and platform.
99
+ # On OS X and BSD platforms it will also include the model.
124
100
  #
125
101
  # On HP-UX, it will also include the id_number.
126
102
  #
@@ -133,9 +109,7 @@ module Sys
133
109
  def self.uname
134
110
  utsname = UnameFFIStruct.new
135
111
 
136
- if uname_c(utsname) < 0
137
- raise Error, "uname() function call failed"
138
- end
112
+ raise Error, 'uname() function call failed' if uname_c(utsname) < 0
139
113
 
140
114
  struct = UnameStruct.new
141
115
  struct[:sysname] = utsname[:sysname].to_s
@@ -144,42 +118,17 @@ module Sys
144
118
  struct[:version] = utsname[:version].to_s
145
119
  struct[:machine] = utsname[:machine].to_s
146
120
 
147
- if RbConfig::CONFIG['host_os'] =~ /darwin|bsd/i
148
- struct[:model] = get_model()
149
- end
150
-
151
- if RbConfig::CONFIG['host_os'] =~ /sunos|solaris/i
152
- struct[:architecture] = get_si(SI_ARCHITECTURE)
153
- struct[:platform] = get_si(SI_PLATFORM)
154
- struct[:hw_serial] = get_si(SI_HW_SERIAL)
155
- struct[:hw_provider] = get_si(SI_HW_PROVIDER)
156
- struct[:srpc_domain] = get_si(SI_SRPC_DOMAIN)
157
- struct[:isa_list] = get_si(SI_ISALIST)
158
- struct[:dhcp_cache] = get_si(SI_DHCP_CACHE)
159
-
160
- # FFI and Solaris don't get along so well, so we try again
161
- struct[:sysname] = get_si(SI_SYSNAME) if struct.sysname.empty?
162
- struct[:nodename] = get_si(SI_HOSTNAME) if struct.nodename.empty?
163
- struct[:release] = get_si(SI_RELEASE) if struct.release.empty?
164
- struct[:version] = get_si(SI_VERSION) if struct.version.empty?
165
- struct[:machine] = get_si(SI_MACHINE) if struct.machine.empty?
166
- end
167
-
168
- if RbConfig::CONFIG['host_os'] =~ /hpux/i
169
- struct[:id_number] = utsname[:__id_number].to_s
170
- end
171
-
172
- if RbConfig::CONFIG['host_os'] =~ /linux/i
173
- struct[:domainname] = utsname[:domainname].to_s
174
- end
121
+ struct[:model] = get_model() if RbConfig::CONFIG['host_os'] =~ /darwin|bsd|dragonfly/i
122
+ struct[:id_number] = utsname[:__id_number].to_s if RbConfig::CONFIG['host_os'] =~ /hpux/i
123
+ struct[:domainname] = utsname[:domainname].to_s if RbConfig::CONFIG['host_os'] =~ /linux/i
175
124
 
176
125
  # Let's add a members method that works for testing and compatibility
177
126
  if struct.members.nil?
178
- struct.instance_eval(%Q{
127
+ struct.instance_eval <<-RUBY, __FILE__, __LINE__ + 1
179
128
  def members
180
- @table.keys.map{ |k| k.to_s }
129
+ @table.keys.map(&:to_s)
181
130
  end
182
- })
131
+ RUBY
183
132
  end
184
133
 
185
134
  struct.freeze
@@ -189,7 +138,7 @@ module Sys
189
138
  #
190
139
  # Example:
191
140
  #
192
- # Uname.sysname # => 'SunOS'
141
+ # Uname.sysname # => 'Darwin'
193
142
  #
194
143
  def self.sysname
195
144
  uname.sysname
@@ -313,15 +262,5 @@ module Sys
313
262
  end
314
263
 
315
264
  private_class_method :get_model
316
-
317
- # Returns the various sysinfo information based on +flag+.
318
- #
319
- def self.get_si(flag)
320
- buf = 0.chr * BUFSIZE
321
- sysinfo(flag, buf, BUFSIZE)
322
- buf.strip
323
- end
324
-
325
- private_class_method :get_si
326
265
  end
327
266
  end