os 0.7.2 → 0.7.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +14 -5
- data/Rakefile +8 -29
- data/VERSION +1 -1
- data/lib/os.rb +23 -11
- data/spec/spec.os.rb +24 -12
- metadata +45 -64
- data/.gitignore +0 -21
data/README.rdoc
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
The OS gem allows for some easy telling if you're on windows or not.
|
2
2
|
|
3
3
|
require 'os'
|
4
|
-
>> OS.windows?
|
5
|
-
=> true
|
4
|
+
>> OS.windows?
|
5
|
+
=> true # also OS.doze?
|
6
6
|
|
7
7
|
>> OS.bits
|
8
8
|
=> 32
|
9
9
|
|
10
10
|
>> OS.java?
|
11
|
-
=> true
|
11
|
+
=> true # if you're running in jruby also OS.jruby?
|
12
12
|
|
13
13
|
>> OS.ruby_bin
|
14
14
|
=> "c:\ruby18\bin\ruby.exe" # or "/usr/local/bin/ruby" or what not
|
@@ -19,11 +19,20 @@ require 'os'
|
|
19
19
|
>> OS.mac?
|
20
20
|
=> false
|
21
21
|
|
22
|
+
>> OS.java? # same as OS.jruby?
|
23
|
+
=> true
|
24
|
+
|
25
|
+
>> OS.dev_null
|
26
|
+
=> "NUL" # or "/dev/null" depending on which platform
|
27
|
+
|
28
|
+
>> OS.rss_bytes
|
29
|
+
=> 12300033 # rss bytes this process is using currently, works in Linux/windows
|
30
|
+
|
22
31
|
If there are any other features you'd like, let me know.
|
23
32
|
|
24
|
-
github.com/rdp/os
|
33
|
+
github.com/rdp/os for feedback et al
|
25
34
|
|
26
|
-
Related:
|
35
|
+
Related projects:
|
27
36
|
|
28
37
|
rubygems:
|
29
38
|
Gem::Platform.local
|
data/Rakefile
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'rake'
|
3
3
|
|
4
|
+
|
5
|
+
begin
|
6
|
+
# require 'psych'
|
7
|
+
rescue ::LoadError
|
8
|
+
end
|
9
|
+
|
4
10
|
begin
|
5
11
|
require 'jeweler'
|
6
12
|
Jeweler::Tasks.new do |gem|
|
@@ -9,39 +15,12 @@ begin
|
|
9
15
|
gem.description = %Q{The OS gem allows for some useful and easy functions, like OS.windows? (=> true or false) OS.bits ( => 32 or 64) etc"}
|
10
16
|
gem.email = "rogerpack2005@gmail.com"
|
11
17
|
gem.homepage = "http://github.com/rdp/os"
|
12
|
-
gem.authors = ["rdp"]
|
13
|
-
gem.add_development_dependency "rspec", ">=
|
18
|
+
gem.authors = ["rdp", "David McCullars"]
|
19
|
+
gem.add_development_dependency "rspec", ">= 2.0"
|
14
20
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
21
|
gem.add_development_dependency "sane"
|
16
22
|
# gem.add_development_dependency "fast_require"
|
17
23
|
end
|
18
|
-
Jeweler::GemcutterTasks.new
|
19
24
|
rescue LoadError
|
20
25
|
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
21
26
|
end
|
22
|
-
|
23
|
-
require 'spec/rake/spectask'
|
24
|
-
Spec::Rake::SpecTask.new(:spec) do |spec|
|
25
|
-
spec.libs << 'lib' << 'spec'
|
26
|
-
spec.spec_files = FileList['spec/**/*_spec.rb']
|
27
|
-
end
|
28
|
-
|
29
|
-
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
30
|
-
spec.libs << 'lib' << 'spec'
|
31
|
-
spec.pattern = 'spec/**/*_spec.rb'
|
32
|
-
spec.rcov = true
|
33
|
-
end
|
34
|
-
|
35
|
-
task :spec => :check_dependencies
|
36
|
-
|
37
|
-
task :default => :spec
|
38
|
-
|
39
|
-
require 'rake/rdoctask'
|
40
|
-
Rake::RDocTask.new do |rdoc|
|
41
|
-
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
42
|
-
|
43
|
-
rdoc.rdoc_dir = 'rdoc'
|
44
|
-
rdoc.title = "os #{version}"
|
45
|
-
rdoc.rdoc_files.include('README*')
|
46
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
47
|
-
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.7.
|
1
|
+
0.7.4
|
data/lib/os.rb
CHANGED
@@ -4,7 +4,8 @@
|
|
4
4
|
class OS
|
5
5
|
|
6
6
|
# true if on windows [and/or jruby]
|
7
|
-
# false if on linux or cygwin
|
7
|
+
# false if on linux or cygwin on windows
|
8
|
+
|
8
9
|
def self.windows?
|
9
10
|
@windows ||= begin
|
10
11
|
if RUBY_PLATFORM =~ /cygwin/ # i386-cygwin
|
@@ -41,10 +42,6 @@ class OS
|
|
41
42
|
|
42
43
|
end
|
43
44
|
|
44
|
-
class << self
|
45
|
-
alias :doze? :windows? # a joke but I use it
|
46
|
-
end
|
47
|
-
|
48
45
|
def self.iron_ruby?
|
49
46
|
@iron_ruby ||= begin
|
50
47
|
if defined?(RUBY_ENGINE) && (RUBY_ENGINE == 'ironruby')
|
@@ -61,7 +58,7 @@ class OS
|
|
61
58
|
host_cpu = RbConfig::CONFIG['host_cpu']
|
62
59
|
if host_cpu =~ /_64$/ # x86_64
|
63
60
|
64
|
64
|
-
elsif RUBY_PLATFORM == 'java' && ENV_JAVA['sun.arch.data.model'] # "32" or "64"
|
61
|
+
elsif RUBY_PLATFORM == 'java' && ENV_JAVA['sun.arch.data.model'] # "32" or "64":http://www.ruby-forum.com/topic/202173#880613
|
65
62
|
ENV_JAVA['sun.arch.data.model'].to_i
|
66
63
|
elsif host_cpu == 'i386'
|
67
64
|
32
|
@@ -114,17 +111,17 @@ class OS
|
|
114
111
|
if OS::Underlying.windows?
|
115
112
|
# MRI, Java, IronRuby, Cygwin
|
116
113
|
if OS.java?
|
117
|
-
# no win32ole
|
114
|
+
# no win32ole on 1.5.x, so leave here for compatibility...maybe for awhile :P
|
118
115
|
require 'java'
|
119
|
-
mem_bean = java.lang.management.ManagementFactory.
|
116
|
+
mem_bean = java.lang.management.ManagementFactory.getMemoryMXBean
|
120
117
|
mem_bean.heap_memory_usage.used + mem_bean.non_heap_memory_usage.used
|
121
118
|
else
|
122
119
|
wmi = nil
|
123
120
|
begin
|
124
121
|
require 'win32ole'
|
125
122
|
wmi = WIN32OLE.connect("winmgmts://")
|
126
|
-
rescue LoadError, NoMethodError # NoMethod for IronRuby currently [sigh]
|
127
|
-
raise 'rss unknown for this platform'
|
123
|
+
rescue LoadError, NoMethodError => e # NoMethod for IronRuby currently [sigh]
|
124
|
+
raise 'rss unknown for this platform ' + e.to_s
|
128
125
|
end
|
129
126
|
processes = wmi.ExecQuery("select * from win32_process where ProcessId = #{Process.pid}")
|
130
127
|
memory_used = nil
|
@@ -132,7 +129,7 @@ class OS
|
|
132
129
|
for process in processes; raise if memory_used; memory_used = process.WorkingSetSize.to_i; end
|
133
130
|
memory_used
|
134
131
|
end
|
135
|
-
elsif OS.posix? #
|
132
|
+
elsif OS.posix? # linux [though I've heard it works in OS X]
|
136
133
|
kb = `ps -o rss= -p #{Process.pid}`.to_i # in kilobytes
|
137
134
|
else
|
138
135
|
raise 'unknown rss for this platform'
|
@@ -156,5 +153,20 @@ class OS
|
|
156
153
|
end
|
157
154
|
end
|
158
155
|
end
|
156
|
+
|
157
|
+
def self.dev_null
|
158
|
+
@dev_null ||= begin
|
159
|
+
if OS.windows?
|
160
|
+
"NUL"
|
161
|
+
else
|
162
|
+
"/dev/null"
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
class << self
|
168
|
+
alias :doze? :windows? # a joke name but I use it and like it :P
|
169
|
+
alias :jruby? :java?
|
170
|
+
end
|
159
171
|
|
160
172
|
end
|
data/spec/spec.os.rb
CHANGED
@@ -1,10 +1,9 @@
|
|
1
|
-
require 'rubygems' if RUBY_VERSION < '1.9'
|
2
|
-
|
3
|
-
require File.dirname(__FILE__) + '/../lib/os.rb' # load before sane
|
1
|
+
require 'rubygems' if RUBY_VERSION < '1.9.0'
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/../lib/os.rb' # load before sane to avoid sane being able to requir the gemified version...
|
4
4
|
require 'sane'
|
5
|
-
load File.dirname(__FILE__) + '/../lib/os.rb'
|
6
|
-
require '
|
7
|
-
require 'rbconfig'
|
5
|
+
load File.dirname(__FILE__) + '/../lib/os.rb' # just in case
|
6
|
+
require 'rspec' # rspec2
|
8
7
|
|
9
8
|
describe "OS" do
|
10
9
|
|
@@ -90,7 +89,7 @@ describe "OS" do
|
|
90
89
|
end
|
91
90
|
end
|
92
91
|
|
93
|
-
it "should have a mac? method" do
|
92
|
+
it "should have a functional mac? method" do
|
94
93
|
if RUBY_PLATFORM =~ /darwin/
|
95
94
|
assert OS.mac? == true
|
96
95
|
else
|
@@ -99,12 +98,25 @@ describe "OS" do
|
|
99
98
|
end
|
100
99
|
|
101
100
|
it "should have a way to get rss_bytes on each platform" do
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
101
|
+
bytes = OS.rss_bytes
|
102
|
+
assert bytes > 0 # should always be true
|
103
|
+
assert bytes.is_a?(Numeric) # don't want strings from any platform...
|
104
|
+
end
|
105
|
+
|
106
|
+
it "should tell you what the right /dev/null is" do
|
107
|
+
if OS.windows?
|
108
|
+
OS.dev_null.should == "NUL"
|
109
|
+
else
|
110
|
+
OS.dev_null.should == "/dev/null"
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should have a jruby method" do
|
115
|
+
if RUBY_DESCRIPTION =~ /^(jruby|java)/
|
116
|
+
assert OS.jruby?
|
117
|
+
else
|
118
|
+
assert !OS.jruby?
|
106
119
|
end
|
107
120
|
end
|
108
|
-
|
109
121
|
|
110
122
|
end
|
metadata
CHANGED
@@ -1,53 +1,41 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: os
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 7
|
9
|
-
- 2
|
10
|
-
version: 0.7.2
|
4
|
+
prerelease:
|
5
|
+
version: 0.7.4
|
11
6
|
platform: ruby
|
12
7
|
authors:
|
13
|
-
- rdp
|
8
|
+
- rdp
|
9
|
+
- David McCullars
|
14
10
|
autorequire:
|
15
11
|
bindir: bin
|
16
12
|
cert_chain: []
|
17
13
|
|
18
|
-
date:
|
14
|
+
date: 2011-02-25 00:00:00 -07:00
|
19
15
|
default_executable:
|
20
16
|
dependencies:
|
21
|
-
- !ruby/object:Gem::Dependency
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
- - ">="
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
hash: 3
|
46
|
-
segments:
|
47
|
-
- 0
|
48
|
-
version: "0"
|
49
|
-
type: :development
|
50
|
-
version_requirements: *id002
|
17
|
+
- !ruby/object:Gem::Dependency
|
18
|
+
name: rspec
|
19
|
+
prerelease: false
|
20
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
21
|
+
none: false
|
22
|
+
requirements:
|
23
|
+
- - ">="
|
24
|
+
- !ruby/object:Gem::Version
|
25
|
+
version: "2.0"
|
26
|
+
type: :development
|
27
|
+
version_requirements: *id001
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: sane
|
30
|
+
prerelease: false
|
31
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
32
|
+
none: false
|
33
|
+
requirements:
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: "0"
|
37
|
+
type: :development
|
38
|
+
version_requirements: *id002
|
51
39
|
description: The OS gem allows for some useful and easy functions, like OS.windows? (=> true or false) OS.bits ( => 32 or 64) etc"
|
52
40
|
email: rogerpack2005@gmail.com
|
53
41
|
executables: []
|
@@ -55,48 +43,41 @@ executables: []
|
|
55
43
|
extensions: []
|
56
44
|
|
57
45
|
extra_rdoc_files:
|
58
|
-
- README.rdoc
|
46
|
+
- README.rdoc
|
59
47
|
files:
|
60
|
-
- .document
|
61
|
-
- .
|
62
|
-
-
|
63
|
-
-
|
64
|
-
-
|
65
|
-
-
|
66
|
-
- spec/spec.os.rb
|
48
|
+
- .document
|
49
|
+
- README.rdoc
|
50
|
+
- Rakefile
|
51
|
+
- VERSION
|
52
|
+
- lib/os.rb
|
53
|
+
- spec/spec.os.rb
|
67
54
|
has_rdoc: true
|
68
55
|
homepage: http://github.com/rdp/os
|
69
56
|
licenses: []
|
70
57
|
|
71
58
|
post_install_message:
|
72
|
-
rdoc_options:
|
73
|
-
|
59
|
+
rdoc_options: []
|
60
|
+
|
74
61
|
require_paths:
|
75
|
-
- lib
|
62
|
+
- lib
|
76
63
|
required_ruby_version: !ruby/object:Gem::Requirement
|
77
64
|
none: false
|
78
65
|
requirements:
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
segments:
|
83
|
-
- 0
|
84
|
-
version: "0"
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: "0"
|
85
69
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
70
|
none: false
|
87
71
|
requirements:
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
segments:
|
92
|
-
- 0
|
93
|
-
version: "0"
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: "0"
|
94
75
|
requirements: []
|
95
76
|
|
96
77
|
rubyforge_project:
|
97
|
-
rubygems_version: 1.
|
78
|
+
rubygems_version: 1.5.1
|
98
79
|
signing_key:
|
99
80
|
specification_version: 3
|
100
81
|
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.
|
101
82
|
test_files:
|
102
|
-
- spec/spec.os.rb
|
83
|
+
- spec/spec.os.rb
|