os 0.8.0 → 0.9.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.
- data/Gemfile.lock +1 -0
- data/README.rdoc +15 -15
- data/VERSION +1 -1
- data/lib/os.rb +41 -1
- data/os.gemspec +48 -60
- data/spec/os_spec.rb +21 -2
- data/spec/spec_helper.rb +1 -0
- metadata +56 -19
- data/.gitignore +0 -21
data/Gemfile.lock
CHANGED
data/README.rdoc
CHANGED
@@ -3,13 +3,13 @@ The OS gem allows for some easy telling if you're on windows or not.
|
|
3
3
|
require 'os'
|
4
4
|
|
5
5
|
>> OS.windows?
|
6
|
-
=> true #
|
6
|
+
=> true # or OS.doze?
|
7
7
|
|
8
8
|
>> OS.bits
|
9
9
|
=> 32
|
10
10
|
|
11
11
|
>> OS.java?
|
12
|
-
=> true # if you're running in jruby
|
12
|
+
=> true # if you're running in jruby. Also OS.jruby?
|
13
13
|
|
14
14
|
>> OS.ruby_bin
|
15
15
|
=> "c:\ruby18\bin\ruby.exe" # or "/usr/local/bin/ruby" or what not
|
@@ -20,14 +20,11 @@ The OS gem allows for some easy telling if you're on windows or not.
|
|
20
20
|
>> OS.mac?
|
21
21
|
=> false
|
22
22
|
|
23
|
-
>> OS.java? # same as OS.jruby?
|
24
|
-
=> true
|
25
|
-
|
26
23
|
>> OS.dev_null
|
27
24
|
=> "NUL" # or "/dev/null" depending on which platform
|
28
25
|
|
29
26
|
>> OS.rss_bytes
|
30
|
-
=> 12300033 # rss bytes this process is using currently
|
27
|
+
=> 12300033 # number of rss bytes this process is using currently. Basically "total in memory footprint" (doesn't include RAM used by the process that's in swap/page file)
|
31
28
|
|
32
29
|
>> puts OS.report
|
33
30
|
==> # a yaml report of helpful values
|
@@ -43,20 +40,23 @@ The OS gem allows for some easy telling if you're on windows or not.
|
|
43
40
|
host: i386-apple-darwin10.6.0
|
44
41
|
RUBY_PLATFORM: x86_64-darwin10.6.0
|
45
42
|
|
46
|
-
|
43
|
+
>> OS.cpu_count
|
44
|
+
=> 2 # number of cores
|
45
|
+
|
46
|
+
If there are any other features you'd like, let me know, I'll do what I can to add them :)
|
47
47
|
|
48
|
-
github.com/rdp/os for feedback et al
|
48
|
+
http://github.com/rdp/os for feedback et al
|
49
49
|
|
50
50
|
Related projects:
|
51
51
|
|
52
52
|
rubygems:
|
53
|
-
Gem::Platform.local
|
54
|
-
Gem.ruby
|
53
|
+
Gem::Platform.local
|
54
|
+
Gem.ruby
|
55
55
|
|
56
|
-
facets gem (similar to rubygems, above)
|
57
|
-
require 'facets/platform'
|
58
|
-
Platform.local
|
56
|
+
the facets gem (has a class similar to rubygems, above)
|
57
|
+
require 'facets/platform'
|
58
|
+
Platform.local
|
59
59
|
|
60
|
-
the "platform" gem, itself (different gem)
|
60
|
+
the "platform" gem, itself (a different gem)
|
61
61
|
|
62
|
-
The reason Gem::Platform.local felt wrong to me is that it treated cygwin as windows--which for most build environments, is wrong.
|
62
|
+
The reason Gem::Platform.local felt wrong to me is that it treated cygwin as windows--which for most build environments, is wrong. Hence the creation of this.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.9.0
|
data/lib/os.rb
CHANGED
@@ -143,7 +143,10 @@ class OS
|
|
143
143
|
processes = wmi.ExecQuery("select * from win32_process where ProcessId = #{Process.pid}")
|
144
144
|
memory_used = nil
|
145
145
|
# only allow for one...
|
146
|
-
for process in processes
|
146
|
+
for process in processes
|
147
|
+
raise if memory_used
|
148
|
+
memory_used = process.WorkingSetSize.to_i
|
149
|
+
end
|
147
150
|
memory_used
|
148
151
|
end
|
149
152
|
elsif OS.posix? # linux [though I've heard it works in OS X]
|
@@ -205,6 +208,36 @@ class OS
|
|
205
208
|
RbConfig::CONFIG.reject {|key, val| !relevant_keys.include? key }.merge({'RUBY_PLATFORM' => RUBY_PLATFORM}).to_yaml
|
206
209
|
end
|
207
210
|
|
211
|
+
def self.cpu_count
|
212
|
+
@cpu_count ||=
|
213
|
+
case RUBY_PLATFORM
|
214
|
+
when /darwin9/
|
215
|
+
`hwprefs cpu_count`.to_i
|
216
|
+
when /darwin10/
|
217
|
+
(hwprefs_available? ? `hwprefs thread_count` : `sysctl -n hw.ncpu`).to_i
|
218
|
+
when /linux/
|
219
|
+
`cat /proc/cpuinfo | grep processor | wc -l`.to_i
|
220
|
+
when /freebsd/
|
221
|
+
`sysctl -n hw.ncpu`.to_i
|
222
|
+
else
|
223
|
+
if RbConfig::CONFIG['host_os'] =~ /darwin/
|
224
|
+
(hwprefs_available? ? `hwprefs thread_count` : `sysctl -n hw.ncpu`).to_i
|
225
|
+
elsif self.windows?
|
226
|
+
out = ENV['NUMBER_OF_PROCESSORS'].to_i
|
227
|
+
if out == 0
|
228
|
+
# in case env. variable not set
|
229
|
+
require 'win32ole'
|
230
|
+
wmi = WIN32OLE.connect("winmgmts://")
|
231
|
+
cpu = wmi.ExecQuery("select NumberOfCores from Win32_Processor") # don't count hyper-threaded in this
|
232
|
+
out = cpu.to_enum.first.NumberOfCores
|
233
|
+
end
|
234
|
+
out
|
235
|
+
else
|
236
|
+
raise 'unknown platform processor_count'
|
237
|
+
end
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
208
241
|
class << self
|
209
242
|
alias :doze? :windows? # a joke name but I use it and like it :P
|
210
243
|
alias :jruby? :java?
|
@@ -213,6 +246,13 @@ class OS
|
|
213
246
|
%w(host host_cpu host_os).each do |method_name|
|
214
247
|
define_method(method_name) { config[method_name] }
|
215
248
|
end
|
249
|
+
|
250
|
+
end
|
251
|
+
|
252
|
+
private
|
253
|
+
|
254
|
+
def self.hwprefs_available?
|
255
|
+
`which hwprefs` != ''
|
216
256
|
end
|
217
257
|
|
218
258
|
end
|
data/os.gemspec
CHANGED
@@ -1,60 +1,48 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in
|
4
|
-
# -*- encoding: utf-8 -*-
|
5
|
-
|
6
|
-
Gem::Specification.new do |s|
|
7
|
-
s.name = %q{os}
|
8
|
-
s.version = "0.
|
9
|
-
|
10
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = ["rdp", "David McCullars"]
|
12
|
-
s.date = %q{2011-05-
|
13
|
-
s.description = %q{The OS gem allows for some useful and easy functions, like OS.windows? (=> true or false) OS.bits ( => 32 or 64) etc"}
|
14
|
-
s.email = %q{rogerpack2005@gmail.com}
|
15
|
-
s.extra_rdoc_files = [
|
16
|
-
"README.rdoc"
|
17
|
-
]
|
18
|
-
s.files = [
|
19
|
-
".
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
s.specification_version = 3
|
50
|
-
|
51
|
-
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
52
|
-
s.add_development_dependency(%q<rspec>, [">= 2.0"])
|
53
|
-
else
|
54
|
-
s.add_dependency(%q<rspec>, [">= 2.0"])
|
55
|
-
end
|
56
|
-
else
|
57
|
-
s.add_dependency(%q<rspec>, [">= 2.0"])
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{os}
|
8
|
+
s.version = "0.7.4"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["rdp", "David McCullars"]
|
12
|
+
s.date = %q{2011-05-03}
|
13
|
+
s.description = %q{The OS gem allows for some useful and easy functions, like OS.windows? (=> true or false) OS.bits ( => 32 or 64) etc"}
|
14
|
+
s.email = %q{rogerpack2005@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"README.rdoc"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
".document",
|
20
|
+
"README.rdoc",
|
21
|
+
"Rakefile",
|
22
|
+
"VERSION",
|
23
|
+
"lib/os.rb",
|
24
|
+
]
|
25
|
+
s.homepage = %q{http://github.com/rdp/os}
|
26
|
+
s.require_paths = ["lib"]
|
27
|
+
s.rubygems_version = %q{1.7.2}
|
28
|
+
s.summary = %q{Simple and easy way to know if you're on windows or not (reliably), as well as how many bits the OS is, etc.}
|
29
|
+
s.test_files = [
|
30
|
+
"spec/spec.os.rb"
|
31
|
+
]
|
32
|
+
|
33
|
+
if s.respond_to? :specification_version then
|
34
|
+
s.specification_version = 3
|
35
|
+
|
36
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
37
|
+
s.add_development_dependency(%q<jeweler>)
|
38
|
+
s.add_development_dependency(%q<rspec>, [">= 2.0"])
|
39
|
+
else
|
40
|
+
s.add_dependency(%q<jeweler>)
|
41
|
+
s.add_dependency(%q<rspec>, [">= 2.0"])
|
42
|
+
end
|
43
|
+
else
|
44
|
+
s.add_dependency(%q<jeweler>)
|
45
|
+
s.add_dependency(%q<rspec>, [">= 2.0"])
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
data/spec/os_spec.rb
CHANGED
@@ -7,7 +7,7 @@ describe "OS" do
|
|
7
7
|
unless RUBY_PLATFORM =~ /cygwin/
|
8
8
|
assert OS.windows? == true
|
9
9
|
assert OS.doze? == true
|
10
|
-
assert OS.posix? == false
|
10
|
+
assert OS.posix? == false # can fail in error at times...I guess because some other spec has reset ENV on us...
|
11
11
|
else
|
12
12
|
assert OS::Underlying.windows?
|
13
13
|
assert OS.windows? == false
|
@@ -88,7 +88,11 @@ describe "OS" do
|
|
88
88
|
if RUBY_PLATFORM =~ /darwin/
|
89
89
|
assert OS.mac? == true
|
90
90
|
else
|
91
|
-
|
91
|
+
if OS.host_os == 'darwin'
|
92
|
+
assert OS.mac? == true
|
93
|
+
else
|
94
|
+
assert OS.mac? == false
|
95
|
+
end
|
92
96
|
end
|
93
97
|
end
|
94
98
|
|
@@ -114,6 +118,21 @@ describe "OS" do
|
|
114
118
|
end
|
115
119
|
end
|
116
120
|
|
121
|
+
it "has working cpu count method" do
|
122
|
+
assert OS.cpu_count >= 1
|
123
|
+
if OS.mac?
|
124
|
+
assert OS.cpu_count == 2 # my own developer box :P
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
it "has working cpu count method with no env. variable" do
|
129
|
+
OS.instance_variable_set(:@cpu_count, nil) # reset it
|
130
|
+
if OS.windows?
|
131
|
+
ENV.delete('NUMBER_OF_PROCESSORS')
|
132
|
+
assert OS.cpu_count >= 1
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
117
136
|
end
|
118
137
|
|
119
138
|
describe OS, "provides access to to underlying config values" do
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: os
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 59
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 9
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.9.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- rdp
|
@@ -16,13 +16,38 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2011-
|
20
|
-
default_executable:
|
19
|
+
date: 2011-06-01 00:00:00 Z
|
21
20
|
dependencies:
|
22
21
|
- !ruby/object:Gem::Dependency
|
23
|
-
|
22
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
23
|
+
none: false
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
hash: 3
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
version: "0"
|
31
|
+
type: :runtime
|
24
32
|
prerelease: false
|
25
|
-
|
33
|
+
name: os
|
34
|
+
requirement: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
hash: 3
|
42
|
+
segments:
|
43
|
+
- 0
|
44
|
+
version: "0"
|
45
|
+
type: :development
|
46
|
+
prerelease: false
|
47
|
+
name: jeweler
|
48
|
+
requirement: *id002
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
26
51
|
none: false
|
27
52
|
requirements:
|
28
53
|
- - ">="
|
@@ -33,7 +58,24 @@ dependencies:
|
|
33
58
|
- 0
|
34
59
|
version: "2.0"
|
35
60
|
type: :development
|
36
|
-
|
61
|
+
prerelease: false
|
62
|
+
name: rspec
|
63
|
+
requirement: *id003
|
64
|
+
- !ruby/object:Gem::Dependency
|
65
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
hash: 3
|
71
|
+
segments:
|
72
|
+
- 2
|
73
|
+
- 0
|
74
|
+
version: "2.0"
|
75
|
+
type: :development
|
76
|
+
prerelease: false
|
77
|
+
name: rspec
|
78
|
+
requirement: *id004
|
37
79
|
description: The OS gem allows for some useful and easy functions, like OS.windows? (=> true or false) OS.bits ( => 32 or 64) etc"
|
38
80
|
email: rogerpack2005@gmail.com
|
39
81
|
executables: []
|
@@ -45,7 +87,6 @@ extra_rdoc_files:
|
|
45
87
|
files:
|
46
88
|
- .autotest
|
47
89
|
- .document
|
48
|
-
- .gitignore
|
49
90
|
- Gemfile
|
50
91
|
- Gemfile.lock
|
51
92
|
- README.rdoc
|
@@ -58,13 +99,12 @@ files:
|
|
58
99
|
- spec/os_spec.rb
|
59
100
|
- spec/osx_spec.rb
|
60
101
|
- spec/spec_helper.rb
|
61
|
-
has_rdoc: true
|
62
102
|
homepage: http://github.com/rdp/os
|
63
103
|
licenses: []
|
64
104
|
|
65
105
|
post_install_message:
|
66
|
-
rdoc_options:
|
67
|
-
|
106
|
+
rdoc_options: []
|
107
|
+
|
68
108
|
require_paths:
|
69
109
|
- lib
|
70
110
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -88,12 +128,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
88
128
|
requirements: []
|
89
129
|
|
90
130
|
rubyforge_project:
|
91
|
-
rubygems_version: 1.
|
131
|
+
rubygems_version: 1.8.2
|
92
132
|
signing_key:
|
93
133
|
specification_version: 3
|
94
134
|
summary: Simple and easy way to know if you're on windows or not (reliably), as well as how many bits the OS is, etc.
|
95
|
-
test_files:
|
96
|
-
|
97
|
-
- spec/osx_spec.rb
|
98
|
-
- spec/os_spec.rb
|
99
|
-
- spec/spec_helper.rb
|
135
|
+
test_files: []
|
136
|
+
|