os 0.6.3 → 0.7.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +4 -2
- data/Rakefile +1 -0
- data/VERSION +1 -1
- data/lib/os.rb +75 -8
- data/spec/spec.os.rb +65 -20
- metadata +35 -13
data/README.rdoc
CHANGED
@@ -29,8 +29,10 @@ rubygems:
|
|
29
29
|
Gem::Platform.local
|
30
30
|
Gem.ruby
|
31
31
|
|
32
|
-
facets gem (similar)
|
32
|
+
facets gem (similar to rubygems, above)
|
33
33
|
require 'facets/platform'
|
34
34
|
Platform.local
|
35
35
|
|
36
|
-
the
|
36
|
+
the "platform" gem, itself (different gem)
|
37
|
+
|
38
|
+
The reason Gem::Platform.local felt wrong to me is that it treated cygwin as windows--which for most build environments, is wrong.
|
data/Rakefile
CHANGED
@@ -13,6 +13,7 @@ begin
|
|
13
13
|
gem.add_development_dependency "rspec", ">= 1.2.9"
|
14
14
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
15
|
gem.add_development_dependency "sane"
|
16
|
+
# gem.add_development_dependency "fast_require"
|
16
17
|
end
|
17
18
|
Jeweler::GemcutterTasks.new
|
18
19
|
rescue LoadError
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.7.2
|
data/lib/os.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# a set of friendly files for determining your Ruby runtime
|
1
|
+
# a set of friendly files for determining your Ruby runtime
|
2
2
|
# treats cygwin as linux
|
3
3
|
# also treats IronRuby on mono as...linux
|
4
4
|
class OS
|
@@ -29,7 +29,7 @@ class OS
|
|
29
29
|
# untested, of course
|
30
30
|
Process.wait fork{}
|
31
31
|
true
|
32
|
-
rescue NotImplementedError
|
32
|
+
rescue NotImplementedError, NoMethodError
|
33
33
|
false
|
34
34
|
end
|
35
35
|
end
|
@@ -44,17 +44,27 @@ class OS
|
|
44
44
|
class << self
|
45
45
|
alias :doze? :windows? # a joke but I use it
|
46
46
|
end
|
47
|
+
|
48
|
+
def self.iron_ruby?
|
49
|
+
@iron_ruby ||= begin
|
50
|
+
if defined?(RUBY_ENGINE) && (RUBY_ENGINE == 'ironruby')
|
51
|
+
true
|
52
|
+
else
|
53
|
+
false
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
47
57
|
|
48
58
|
def self.bits
|
49
59
|
@bits ||= begin
|
50
60
|
require 'rbconfig'
|
51
|
-
host_cpu = RbConfig::CONFIG['host_cpu']
|
61
|
+
host_cpu = RbConfig::CONFIG['host_cpu']
|
52
62
|
if host_cpu =~ /_64$/ # x86_64
|
53
63
|
64
|
54
64
|
elsif RUBY_PLATFORM == 'java' && ENV_JAVA['sun.arch.data.model'] # "32" or "64" http://www.ruby-forum.com/topic/202173#880613
|
55
|
-
|
56
|
-
elsif host_cpu == 'i386'
|
57
|
-
32
|
65
|
+
ENV_JAVA['sun.arch.data.model'].to_i
|
66
|
+
elsif host_cpu == 'i386'
|
67
|
+
32
|
58
68
|
elsif RbConfig::CONFIG['host_os'] =~ /32$/ # mingw32, mswin32
|
59
69
|
32
|
60
70
|
else # cygwin only...I think
|
@@ -85,9 +95,66 @@ class OS
|
|
85
95
|
File::join(config['bindir'], config['ruby_install_name']) + config['EXEEXT']
|
86
96
|
end
|
87
97
|
end
|
88
|
-
|
98
|
+
|
89
99
|
def self.mac?
|
90
|
-
|
100
|
+
@mac = begin
|
101
|
+
if RUBY_PLATFORM =~ /darwin/
|
102
|
+
true
|
103
|
+
else
|
104
|
+
false
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
# amount of memory the current process "is using", in RAM
|
110
|
+
# (doesn't include any swap memory that it may be using, just that in actual RAM)
|
111
|
+
# raises 'unknown' on jruby currently
|
112
|
+
def self.rss_bytes
|
113
|
+
# attempt to do this in a jruby friendly way
|
114
|
+
if OS::Underlying.windows?
|
115
|
+
# MRI, Java, IronRuby, Cygwin
|
116
|
+
if OS.java?
|
117
|
+
# no win32ole yet available...
|
118
|
+
require 'java'
|
119
|
+
mem_bean = java.lang.management.ManagementFactory.memory_mxbean
|
120
|
+
mem_bean.heap_memory_usage.used + mem_bean.non_heap_memory_usage.used
|
121
|
+
else
|
122
|
+
wmi = nil
|
123
|
+
begin
|
124
|
+
require 'win32ole'
|
125
|
+
wmi = WIN32OLE.connect("winmgmts://")
|
126
|
+
rescue LoadError, NoMethodError # NoMethod for IronRuby currently [sigh]
|
127
|
+
raise 'rss unknown for this platform'
|
128
|
+
end
|
129
|
+
processes = wmi.ExecQuery("select * from win32_process where ProcessId = #{Process.pid}")
|
130
|
+
memory_used = nil
|
131
|
+
# only allow for one...
|
132
|
+
for process in processes; raise if memory_used; memory_used = process.WorkingSetSize.to_i; end
|
133
|
+
memory_used
|
134
|
+
end
|
135
|
+
elsif OS.posix? # assume linux I guess...
|
136
|
+
kb = `ps -o rss= -p #{Process.pid}`.to_i # in kilobytes
|
137
|
+
else
|
138
|
+
raise 'unknown rss for this platform'
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
class Underlying
|
143
|
+
|
144
|
+
def self.windows?
|
145
|
+
ENV['OS'] == 'Windows_NT'
|
146
|
+
end
|
147
|
+
|
91
148
|
end
|
92
149
|
|
150
|
+
def self.cygwin?
|
151
|
+
@cygwin = begin
|
152
|
+
if RUBY_PLATFORM =~ /-cygwin/
|
153
|
+
true
|
154
|
+
else
|
155
|
+
false
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
93
160
|
end
|
data/spec/spec.os.rb
CHANGED
@@ -1,65 +1,110 @@
|
|
1
1
|
require 'rubygems' if RUBY_VERSION < '1.9'
|
2
|
+
#require 'fast_require'
|
2
3
|
require File.dirname(__FILE__) + '/../lib/os.rb' # load before sane
|
3
4
|
require 'sane'
|
4
5
|
load File.dirname(__FILE__) + '/../lib/os.rb'
|
5
6
|
require 'spec/autorun'
|
7
|
+
require 'rbconfig'
|
6
8
|
|
7
9
|
describe "OS" do
|
8
10
|
|
9
11
|
it "has a windows? method" do
|
10
|
-
if
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
if ENV['OS'] == 'Windows_NT'
|
13
|
+
unless RUBY_PLATFORM =~ /cygwin/
|
14
|
+
assert OS.windows? == true
|
15
|
+
assert OS.doze? == true
|
16
|
+
assert OS.posix? == false
|
17
|
+
else
|
18
|
+
assert OS::Underlying.windows?
|
16
19
|
assert OS.windows? == false
|
17
20
|
assert OS.posix? == true
|
18
21
|
end
|
22
|
+
assert OS::Underlying.windows?
|
23
|
+
elsif (RbConfig::CONFIG["host_os"] == 'linux') || RUBY_PLATFORM =~ /linux/
|
24
|
+
assert OS.windows? == false
|
25
|
+
assert OS.posix? == true
|
26
|
+
assert !OS::Underlying.windows?
|
27
|
+
else
|
28
|
+
pending "create test"
|
19
29
|
end
|
20
30
|
end
|
21
31
|
|
22
32
|
it "has a bits method" do
|
23
33
|
if RUBY_PLATFORM =~ /mingw32/
|
24
|
-
|
34
|
+
assert OS.bits == 32
|
25
35
|
elsif RUBY_PLATFORM =~ /64/ # linux...
|
26
|
-
|
36
|
+
assert OS.bits == 64
|
27
37
|
elsif RUBY_PLATFORM =~ /i686/
|
28
|
-
|
38
|
+
assert OS.bits == 32
|
29
39
|
elsif RUBY_PLATFORM =~ /java/ && RbConfig::CONFIG['host_os'] =~ /32$/
|
30
|
-
|
40
|
+
assert OS.bits == 32
|
31
41
|
elsif RUBY_PLATFORM =~ /java/ && RbConfig::CONFIG['host_cpu'] =~ /i386/
|
32
|
-
|
42
|
+
assert OS.bits == 32
|
33
43
|
elsif RUBY_PLATFORM =~ /i386/
|
34
44
|
assert OS.bits == 32
|
35
|
-
else
|
36
|
-
|
45
|
+
else
|
46
|
+
pending "os bits not tested!" + RUBY_PLATFORM + ' ' + RbConfig::CONFIG['host_os']
|
37
47
|
end
|
38
48
|
|
39
49
|
end
|
50
|
+
|
51
|
+
it "should have an iron_ruby method" do
|
52
|
+
if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'ironruby'
|
53
|
+
assert OS.iron_ruby? == true
|
54
|
+
else
|
55
|
+
assert OS.iron_ruby? == false
|
56
|
+
end
|
57
|
+
end
|
40
58
|
|
41
59
|
it "should know if you're on java" do
|
42
60
|
if RUBY_PLATFORM == 'java'
|
43
|
-
assert OS.java? == true #
|
61
|
+
assert OS.java? == true # must be [true | false]
|
44
62
|
else
|
45
63
|
assert OS.java? == false
|
46
64
|
end
|
47
65
|
end
|
48
|
-
|
49
|
-
it "should have a
|
66
|
+
|
67
|
+
it "should have a ruby_bin method" do
|
50
68
|
if OS.windows?
|
51
|
-
assert OS.ruby_bin.include?('
|
69
|
+
assert OS.ruby_bin.include?('.exe')
|
70
|
+
if OS.iron_ruby?
|
71
|
+
assert OS.ruby_bin.include?('ir.exe')
|
72
|
+
else
|
73
|
+
assert OS.ruby_bin.include?('ruby.exe')
|
74
|
+
end
|
52
75
|
else
|
53
76
|
assert OS.ruby_bin.include?('ruby') && OS.ruby_bin.include?('/')
|
54
77
|
end
|
78
|
+
|
79
|
+
if OS.java?
|
80
|
+
assert OS.ruby_bin.include?('jruby') # I think
|
81
|
+
end
|
82
|
+
|
55
83
|
end
|
56
84
|
|
85
|
+
it "should have a cygwin? method" do
|
86
|
+
if RUBY_PLATFORM =~ /cygwin/
|
87
|
+
assert OS.cygwin? == true
|
88
|
+
else
|
89
|
+
assert OS.cygwin? == false
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
57
93
|
it "should have a mac? method" do
|
58
94
|
if RUBY_PLATFORM =~ /darwin/
|
59
|
-
assert OS.mac?
|
95
|
+
assert OS.mac? == true
|
60
96
|
else
|
61
|
-
assert
|
97
|
+
assert OS.mac? == false
|
62
98
|
end
|
63
99
|
end
|
64
|
-
|
100
|
+
|
101
|
+
it "should have a way to get rss_bytes on each platform" do
|
102
|
+
if !OS.iron_ruby?
|
103
|
+
bytes = OS.rss_bytes
|
104
|
+
assert bytes > 0 # should always be true
|
105
|
+
assert bytes.is_a?(Numeric) # don't want strings from any platform...
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
|
65
110
|
end
|
metadata
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: os
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 7
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 7
|
9
|
+
- 2
|
10
|
+
version: 0.7.2
|
5
11
|
platform: ruby
|
6
12
|
authors:
|
7
13
|
- rdp
|
@@ -9,29 +15,39 @@ autorequire:
|
|
9
15
|
bindir: bin
|
10
16
|
cert_chain: []
|
11
17
|
|
12
|
-
date: 2010-
|
18
|
+
date: 2010-05-18 00:00:00 -06:00
|
13
19
|
default_executable:
|
14
20
|
dependencies:
|
15
21
|
- !ruby/object:Gem::Dependency
|
16
22
|
name: rspec
|
17
|
-
|
18
|
-
|
19
|
-
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
20
26
|
requirements:
|
21
27
|
- - ">="
|
22
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 13
|
30
|
+
segments:
|
31
|
+
- 1
|
32
|
+
- 2
|
33
|
+
- 9
|
23
34
|
version: 1.2.9
|
24
|
-
|
35
|
+
type: :development
|
36
|
+
version_requirements: *id001
|
25
37
|
- !ruby/object:Gem::Dependency
|
26
38
|
name: sane
|
27
|
-
|
28
|
-
|
29
|
-
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
30
42
|
requirements:
|
31
43
|
- - ">="
|
32
44
|
- !ruby/object:Gem::Version
|
45
|
+
hash: 3
|
46
|
+
segments:
|
47
|
+
- 0
|
33
48
|
version: "0"
|
34
|
-
|
49
|
+
type: :development
|
50
|
+
version_requirements: *id002
|
35
51
|
description: The OS gem allows for some useful and easy functions, like OS.windows? (=> true or false) OS.bits ( => 32 or 64) etc"
|
36
52
|
email: rogerpack2005@gmail.com
|
37
53
|
executables: []
|
@@ -58,21 +74,27 @@ rdoc_options:
|
|
58
74
|
require_paths:
|
59
75
|
- lib
|
60
76
|
required_ruby_version: !ruby/object:Gem::Requirement
|
77
|
+
none: false
|
61
78
|
requirements:
|
62
79
|
- - ">="
|
63
80
|
- !ruby/object:Gem::Version
|
81
|
+
hash: 3
|
82
|
+
segments:
|
83
|
+
- 0
|
64
84
|
version: "0"
|
65
|
-
version:
|
66
85
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
none: false
|
67
87
|
requirements:
|
68
88
|
- - ">="
|
69
89
|
- !ruby/object:Gem::Version
|
90
|
+
hash: 3
|
91
|
+
segments:
|
92
|
+
- 0
|
70
93
|
version: "0"
|
71
|
-
version:
|
72
94
|
requirements: []
|
73
95
|
|
74
96
|
rubyforge_project:
|
75
|
-
rubygems_version: 1.3.
|
97
|
+
rubygems_version: 1.3.7
|
76
98
|
signing_key:
|
77
99
|
specification_version: 3
|
78
100
|
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.
|