sysinfo 0.8.0 → 0.9.0.pre.RC1

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 (5) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGES.txt +6 -0
  3. data/lib/sysinfo.rb +64 -55
  4. data/sysinfo.gemspec +21 -40
  5. metadata +26 -45
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 41eb7522683b4f474f8cf49d15c03891eb5ba2718a549a8cec52b57afd21922d
4
+ data.tar.gz: 9d235a1c5f590f5088a55e4c15dfe0ff189dd19b0bd6037677c9530de8ff321c
5
+ SHA512:
6
+ metadata.gz: b84c9a323f1a5a399d0821ef8b85c3e82d2dba38e5ef85f742155a5beb13c46e582e30ad0486299e9428dab41638525ec17db50a7653825a4f2be644412b5194
7
+ data.tar.gz: 4c8860fb1ec0305b623839bdfa07beeb9826ab20a07b939a3c8bde424f513bf1c1cf5a58739da8f6e492cd34441e539a60d835d0efabe612d42371cbdb599ccc
data/CHANGES.txt CHANGED
@@ -1,11 +1,17 @@
1
1
  SYSINFO, CHANGES
2
2
 
3
+
4
+ #### 0.8.1 (2014-02-11) #############################
5
+
6
+ * CHANGE: Use Etc.getpwuid [jperville]
7
+
3
8
  #### 0.8.0 (2012-04-30) #############################
4
9
 
5
10
  * CHANGE: Removed #to_s
6
11
  * CHANGE: #platform now returns VM-OS-IMPL-ARCH
7
12
  * CHANGE: json is the default output format
8
13
 
14
+
9
15
  #### 0.7.2 (2010-02-12) #############################
10
16
 
11
17
  * CHANGE: Removed hanna dependency [Diego Elio 'Flameeyes' Pettenò]
data/lib/sysinfo.rb CHANGED
@@ -1,27 +1,28 @@
1
1
  require 'socket'
2
2
  require 'storable'
3
3
  require 'time'
4
+ require 'tmpdir'
4
5
 
5
6
  # = SysInfo
6
- #
7
- # A container for the platform specific system information.
8
- # Portions of this code were originally from Amazon's EC2 AMI tools,
9
- # specifically lib/platform.rb.
7
+ #
8
+ # A container for the platform specific system information.
9
+ # Portions of this code were originally from Amazon's EC2 AMI tools,
10
+ # specifically lib/platform.rb.
10
11
  class SysInfo < Storable
11
12
  unless defined?(IMPLEMENTATIONS)
12
- VERSION = "0.8.0".freeze
13
+ VERSION = "0.9.0".freeze
13
14
  IMPLEMENTATIONS = [
14
-
15
- # These are for JRuby, System.getproperty('os.name').
15
+
16
+ # These are for JRuby, System.getproperty('os.name').
16
17
  # For a list of all values, see: http://lopica.sourceforge.net/os.html
17
-
18
+
18
19
  #regexp matcher os implementation
19
- [/mac\s*os\s*x/i, :unix, :osx ],
20
- [/sunos/i, :unix, :solaris ],
20
+ [/mac\s*os\s*x/i, :unix, :osx ],
21
+ [/sunos/i, :unix, :solaris ],
21
22
  [/windows\s*ce/i, :windows, :wince ],
22
- [/windows/i, :windows, :windows ],
23
+ [/windows/i, :windows, :windows ],
23
24
  [/osx/i, :unix, :osx ],
24
-
25
+
25
26
  # These are for RUBY_PLATFORM and JRuby
26
27
  [/java/i, :java, :java ],
27
28
  [/darwin/i, :unix, :osx ],
@@ -63,14 +64,14 @@ class SysInfo < Storable
63
64
  field :ipaddress_internal => String
64
65
  #field :ipaddress_external => String
65
66
  field :uptime => Float
66
-
67
+
67
68
  field :paths
68
69
  field :tmpdir
69
70
  field :home
70
71
  field :shell
71
72
  field :user
72
73
  field :ruby
73
-
74
+
74
75
  alias :implementation :impl
75
76
  alias :architecture :arch
76
77
 
@@ -78,10 +79,10 @@ class SysInfo < Storable
78
79
  @vm, @os, @impl, @arch = find_platform_info
79
80
  @hostname, @ipaddress_internal, @uptime = find_network_info
80
81
  @ruby = RUBY_VERSION.split('.').collect { |v| v.to_i }
81
- @user = ENV['USER']
82
+ @user = getpwattr(:name) || ENV['USER']
82
83
  require 'Win32API' if @os == :windows && @vm == :ruby
83
84
  end
84
-
85
+
85
86
  # Returns [vm, os, impl, arch]
86
87
  def find_platform_info
87
88
  vm, os, impl, arch = :ruby, :unknown, :unknown, :unknow
@@ -97,25 +98,25 @@ class SysInfo < Storable
97
98
  end
98
99
  os == :java ? guess_java : [vm, os, impl, arch]
99
100
  end
100
-
101
+
101
102
  # Returns [hostname, ipaddr (internal), uptime]
102
103
  def find_network_info
103
104
  hostname, ipaddr, uptime = :unknown, :unknown, :unknown
104
105
  begin
105
106
  hostname = find_hostname
106
107
  ipaddr = find_ipaddress_internal
107
- uptime = find_uptime
108
+ uptime = find_uptime
108
109
  rescue => ex # Be silent!
109
110
  end
110
111
  [hostname, ipaddr, uptime]
111
112
  end
112
-
113
+
113
114
  # Return the hostname for the local machine
114
115
  def find_hostname; Socket.gethostname; end
115
-
116
- # Returns the local uptime in hours. Use Win32API in Windows,
116
+
117
+ # Returns the local uptime in hours. Use Win32API in Windows,
117
118
  # 'sysctl -b kern.boottime' os osx, and 'who -b' on unix.
118
- # Based on Ruby Quiz solutions by: Matthias Reitinger
119
+ # Based on Ruby Quiz solutions by: Matthias Reitinger
119
120
  # On Windows, see also: net statistics server
120
121
  def find_uptime
121
122
  hours = 0
@@ -128,24 +129,24 @@ class SysInfo < Storable
128
129
  hours
129
130
  end
130
131
 
131
-
132
+
132
133
  # Return the local IP address which receives external traffic
133
134
  # from: http://coderrr.wordpress.com/2008/05/28/get-your-local-ip-address/
134
- # NOTE: This <em>does not</em> open a connection to the IP address.
135
+ # NOTE: This <em>does not</em> open a connection to the IP address.
135
136
  def find_ipaddress_internal
136
- # turn off reverse DNS resolution temporarily
137
- orig, Socket.do_not_reverse_lookup = Socket.do_not_reverse_lookup, true
137
+ # turn off reverse DNS resolution temporarily
138
+ orig, Socket.do_not_reverse_lookup = Socket.do_not_reverse_lookup, true
138
139
  UDPSocket.open {|s| s.connect('65.74.177.129', 1); s.addr.last } # GitHub IP
139
- ensure
140
+ ensure
140
141
  Socket.do_not_reverse_lookup = orig
141
142
  end
142
-
143
+
143
144
  # Returns a String of the full platform descriptor in the format: VM-OS-IMPL-ARCH
144
145
  # e.g. <tt>java-unix-osx-x86_64</tt>
145
146
  def platform
146
147
  "#{@vm}-#{@os}-#{@impl}-#{@arch}"
147
148
  end
148
-
149
+
149
150
  # Returns the environment paths as an Array
150
151
  def paths; execute_platform_specific(:paths); end
151
152
  # Returns the path to the current user's home directory
@@ -154,10 +155,10 @@ class SysInfo < Storable
154
155
  def shell; execute_platform_specific(:shell); end
155
156
  # Returns the path to the current temp directory
156
157
  def tmpdir; execute_platform_specific(:tmpdir); end
157
-
158
+
158
159
  private
159
-
160
- # Look for and execute a platform specific method.
160
+
161
+ # Look for and execute a platform specific method.
161
162
  # The name of the method will be in the format: +dtype-VM-OS-IMPL+.
162
163
  # e.g. find_uptime_ruby_unix_osx
163
164
  #
@@ -168,40 +169,40 @@ class SysInfo < Storable
168
169
  return self.send(meth) if SysInfo.private_method_defined?(meth)
169
170
  criteria.pop
170
171
  end
171
- raise "#{dtype}_#{@vm}_#{@os}_#{@impl} not implemented"
172
+ raise "#{dtype}_#{@vm}_#{@os}_#{@impl} not implemented"
172
173
  end
173
-
174
+
174
175
  def paths_ruby_unix; (ENV['PATH'] || '').split(':'); end
175
176
  def paths_ruby_windows; (ENV['PATH'] || '').split(';'); end # Not tested!
176
177
  def paths_java
177
178
  delim = @impl == :windows ? ';' : ':'
178
179
  (ENV['PATH'] || '').split(delim)
179
180
  end
180
-
181
- def tmpdir_ruby_unix; (ENV['TMPDIR'] || '/tmp'); end
182
- def tmpdir_ruby_windows; (ENV['TMPDIR'] || 'C:\\temp'); end
181
+
182
+ def tmpdir_ruby_unix; (Dir.tmpdir || '/tmp'); end
183
+ def tmpdir_ruby_windows; (Dir.tmpdir || 'C:\\temp'); end
183
184
  def tmpdir_java
184
185
  default = @impl == :windows ? 'C:\\temp' : '/tmp'
185
- (ENV['TMPDIR'] || default)
186
+ (Dir.tmpdir || default)
186
187
  end
187
-
188
- def shell_ruby_unix; (ENV['SHELL'] || 'bash').to_sym; end
188
+
189
+ def shell_ruby_unix; (ENV['SHELL'] || getpwattr(:shell) || 'bash').to_sym; end
189
190
  def shell_ruby_windows; :dos; end
190
191
  alias_method :shell_java_unix, :shell_ruby_unix
191
192
  alias_method :shell_java_windows, :shell_ruby_windows
192
-
193
- def home_ruby_unix; File.expand_path(ENV['HOME']); end
193
+
194
+ def home_ruby_unix; File.expand_path(getpwattr(:dir)); end
194
195
  def home_ruby_windows; File.expand_path(ENV['USERPROFILE']); end
195
196
  def home_java
196
197
  if @impl == :windows
197
198
  File.expand_path(ENV['USERPROFILE'])
198
199
  else
199
- File.expand_path(ENV['HOME'])
200
+ File.expand_path(getpwattr(:dir))
200
201
  end
201
202
  end
202
-
203
+
203
204
  # Ya, this is kinda wack. Ruby -> Java -> Kernel32. See:
204
- # http://www.oreillynet.com/ruby/blog/2008/01/jruby_meets_the_windows_api_1.html
205
+ # http://www.oreillynet.com/ruby/blog/2008/01/jruby_meets_the_windows_api_1.html
205
206
  # http://msdn.microsoft.com/en-us/library/ms724408(VS.85).aspx
206
207
  # Ruby 1.9.1: Win32API is now deprecated in favor of using the DL library.
207
208
  def find_uptime_java_windows_windows
@@ -215,30 +216,30 @@ class SysInfo < Storable
215
216
  ((getTickCount.call()).to_f / 1000).to_f
216
217
  end
217
218
  def find_uptime_ruby_unix_osx
218
- # This is faster than "who" and could work on BSD also.
219
+ # This is faster than "who" and could work on BSD also.
219
220
  (Time.now.to_f - Time.at(`sysctl -b kern.boottime 2>/dev/null`.unpack('L').first).to_f).to_f
220
221
  end
221
-
222
+
222
223
  # This should work for most unix flavours.
223
224
  def find_uptime_ruby_unix
224
225
  # who is sloooooow. Use File.read('/proc/uptime')
225
226
  (Time.now.to_i - Time.parse(`who -b 2>/dev/null`).to_f)
226
227
  end
227
228
  alias_method :find_uptime_java_unix_osx, :find_uptime_ruby_unix
228
-
229
- # Determine the values for vm, os, impl, and arch when running on Java.
229
+
230
+ # Determine the values for vm, os, impl, and arch when running on Java.
230
231
  def guess_java
231
232
  vm, os, impl, arch = :java, :unknown, :unknown, :unknown
232
233
  require 'java'
233
234
  include_class java.lang.System unless defined?(System)
234
-
235
+
235
236
  osname = System.getProperty("os.name")
236
237
  IMPLEMENTATIONS.each do |r, o, i|
237
238
  next unless osname =~ r
238
239
  os, impl = [o, i]
239
240
  break
240
241
  end
241
-
242
+
242
243
  osarch = System.getProperty("os.arch")
243
244
  ARCHITECTURES.each do |r, a|
244
245
  next unless osarch =~ r
@@ -247,12 +248,12 @@ class SysInfo < Storable
247
248
  end
248
249
  [vm, os, impl, arch]
249
250
  end
250
-
251
- # Returns the local IP address based on the hostname.
251
+
252
+ # Returns the local IP address based on the hostname.
252
253
  # According to coderrr (see comments on blog link above), this implementation
253
254
  # doesn't guarantee that it will return the address for the interface external
254
255
  # traffic goes through. It's also possible the hostname isn't resolvable to the
255
- # local IP.
256
+ # local IP.
256
257
  #
257
258
  # NOTE: This code predates the current ip_address_internal. It was just as well
258
259
  # but the other code is cleaner. I'm keeping this old version here for now.
@@ -265,9 +266,17 @@ class SysInfo < Storable
265
266
  end
266
267
  ipaddr
267
268
  end
269
+
270
+ # Returns a named attribute of the user's /etc/password entry, or nil.
271
+ # As an example, `getpwdattr(:home)` will return the user's home directory
272
+ # without relying on ENV['HOME'] being present.
273
+ def getpwattr(pwattr)
274
+ passwd = Etc.getpwuid(Process::Sys.getuid) || {}
275
+ passwd[pwattr]
276
+ end
268
277
  end
269
278
 
270
279
 
271
280
  if $0 == __FILE__
272
281
  puts SysInfo.new.dump('json')
273
- end
282
+ end
data/sysinfo.gemspec CHANGED
@@ -1,44 +1,25 @@
1
- @spec = Gem::Specification.new do |s|
2
- s.name = "sysinfo"
3
- s.rubyforge_project = "sysinfo"
4
- s.version = "0.8.0"
5
- s.summary = "SysInfo: All your system-independent infoz in one handy class. "
1
+ Gem::Specification.new do |s|
2
+ s.name = "sysinfo"
3
+ s.version = "0.9.0-RC1"
4
+ s.summary = "SysInfo: All your system-independent infoz in one handy class. "
6
5
  s.description = s.summary
7
- s.author = "Delano Mandelbaum"
8
- s.email = "delano@solutious.com"
9
- s.homepage = "http://solutious.com/"
10
-
11
-
12
- # = EXECUTABLES =
13
- # The list of executables in your project (if any). Don't include the path,
14
- # just the base filename.
6
+ s.author = "Delano Mandelbaum"
7
+ s.email = "delano@solutious.com"
8
+ s.homepage = "https://github.com/username/sysinfo" # replace with actual URL
9
+ s.license = "MIT" # replace with actual license
10
+
15
11
  s.executables = %w[sysinfo]
16
-
17
- # = DEPENDENCIES =
18
- # Add all gem dependencies
19
- s.add_dependency 'storable'
20
- s.add_dependency 'drydock'
21
-
22
- # = MANIFEST =
23
- # The complete list of files to be included in the release. When GitHub packages your gem,
24
- # it doesn't allow you to run any command that accesses the filesystem. You will get an
25
- # error. You can ask your VCS for the list of versioned files:
26
- # git ls-files
27
- # svn list -R
12
+
13
+ s.add_dependency 'storable', '0.10.pre.RC1'
14
+ s.add_dependency 'drydock', '<1.0'
15
+
28
16
  s.files = %w(
29
- CHANGES.txt
30
- LICENSE.txt
31
- README.rdoc
32
- Rakefile
33
- bin/sysinfo
34
- lib/sysinfo.rb
35
- sysinfo.gemspec
17
+ CHANGES.txt
18
+ LICENSE.txt
19
+ README.rdoc
20
+ Rakefile
21
+ bin/sysinfo
22
+ lib/sysinfo.rb
23
+ sysinfo.gemspec
36
24
  )
37
-
38
- s.extra_rdoc_files = %w[README.rdoc LICENSE.txt]
39
- s.has_rdoc = true
40
- s.rdoc_options = ["--line-numbers", "--title", s.summary, "--main", "README.rdoc"]
41
- s.require_paths = %w[lib]
42
- s.rubygems_version = '1.3.0'
43
-
44
- end
25
+ end
metadata CHANGED
@@ -1,56 +1,49 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sysinfo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
5
- prerelease:
4
+ version: 0.9.0.pre.RC1
6
5
  platform: ruby
7
6
  authors:
8
7
  - Delano Mandelbaum
9
- autorequire:
8
+ autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-04-30 00:00:00.000000000 Z
11
+ date: 2024-04-03 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: storable
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '='
20
18
  - !ruby/object:Gem::Version
21
- version: '0'
19
+ version: 0.10.pre.RC1
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - '='
28
25
  - !ruby/object:Gem::Version
29
- version: '0'
26
+ version: 0.10.pre.RC1
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: drydock
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - "<"
36
32
  - !ruby/object:Gem::Version
37
- version: '0'
33
+ version: '1.0'
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - "<"
44
39
  - !ruby/object:Gem::Version
45
- version: '0'
46
- description: ! 'SysInfo: All your system-independent infoz in one handy class.'
40
+ version: '1.0'
41
+ description: 'SysInfo: All your system-independent infoz in one handy class.'
47
42
  email: delano@solutious.com
48
43
  executables:
49
44
  - sysinfo
50
45
  extensions: []
51
- extra_rdoc_files:
52
- - README.rdoc
53
- - LICENSE.txt
46
+ extra_rdoc_files: []
54
47
  files:
55
48
  - CHANGES.txt
56
49
  - LICENSE.txt
@@ -59,39 +52,27 @@ files:
59
52
  - bin/sysinfo
60
53
  - lib/sysinfo.rb
61
54
  - sysinfo.gemspec
62
- homepage: http://solutious.com/
63
- licenses: []
64
- post_install_message:
65
- rdoc_options:
66
- - --line-numbers
67
- - --title
68
- - ! 'SysInfo: All your system-independent infoz in one handy class.'
69
- - --main
70
- - README.rdoc
55
+ homepage: https://github.com/username/sysinfo
56
+ licenses:
57
+ - MIT
58
+ metadata: {}
59
+ post_install_message:
60
+ rdoc_options: []
71
61
  require_paths:
72
62
  - lib
73
63
  required_ruby_version: !ruby/object:Gem::Requirement
74
- none: false
75
64
  requirements:
76
- - - ! '>='
65
+ - - ">="
77
66
  - !ruby/object:Gem::Version
78
67
  version: '0'
79
- segments:
80
- - 0
81
- hash: 1706058782098846642
82
68
  required_rubygems_version: !ruby/object:Gem::Requirement
83
- none: false
84
69
  requirements:
85
- - - ! '>='
70
+ - - ">"
86
71
  - !ruby/object:Gem::Version
87
- version: '0'
88
- segments:
89
- - 0
90
- hash: 1706058782098846642
72
+ version: 1.3.1
91
73
  requirements: []
92
- rubyforge_project: sysinfo
93
- rubygems_version: 1.8.22
94
- signing_key:
95
- specification_version: 3
96
- summary: ! 'SysInfo: All your system-independent infoz in one handy class.'
74
+ rubygems_version: 3.3.26
75
+ signing_key:
76
+ specification_version: 4
77
+ summary: 'SysInfo: All your system-independent infoz in one handy class.'
97
78
  test_files: []