os 1.0.0 → 1.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: dc56c95ef4834741ffeced9727a5750f13fafe33
4
- data.tar.gz: a2844070c1b7e6abcc8ed1d121f9b7d47e360be3
2
+ SHA256:
3
+ metadata.gz: 8ceda108b09b3210f4cab0b411d8fe76bb69c74b3054a86e15ba533074086ffe
4
+ data.tar.gz: c59bede2a6e772a83b13543951b7824a1811c376c1e313e16ec20e96a37f7986
5
5
  SHA512:
6
- metadata.gz: 9defce3f1298173d446d40af5d7c1b99c945f8daf02159874cc90ad39ba7148327bc004a5891c864ed7df5bfe480280546aa01f2160d9924a4fd7c7a899842b7
7
- data.tar.gz: e554eef3d21a36fbf876f6230050d43837ba9f4eb8a77c40c9d11ec5966d77839742cad6b621d5320ba362771e6089600a7d9c16d7a5099c8271806bb7cd75a3
6
+ metadata.gz: b574706218e68b4ce5d9d9c82abb967032ec5fa1d4363c268cbd89e3261955de0d8e0c56834d6e813c06b23900cade81087b86ff52f166418ab339d03ced7197
7
+ data.tar.gz: 6a692f3db11e912c795a66450a1e2ae70e9819c2f079b956584339f0be0b7241204cacf10153dd8e57e2b9ab4eb9730603d323ddfa801509774f24279435733c
data/ChangeLog CHANGED
@@ -1,3 +1,21 @@
1
+ 1.1.4
2
+ Fix circular dependency
3
+
4
+ 1.1.2
5
+ Make rss_bytes return bytes in linux/OS X, like it always should have
6
+
7
+ 1.1.1
8
+ fix skip blank lines in OS#parse_os_release
9
+
10
+ 1.1.0
11
+ Add app_config_path method
12
+ Cleans up dev dependency specs
13
+ Detect underlying Docker containers method
14
+ Add Linux-specific OS#parse_os_release method
15
+
16
+ 1.0.1
17
+ add within docker method
18
+
1
19
  0.10.0
2
20
  freebsd? also some cleanup
3
21
 
data/Gemfile CHANGED
@@ -1,3 +1,3 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- #gem 'rspec', ">= 2"
3
+ gemspec
data/Gemfile.lock CHANGED
@@ -1,29 +1,25 @@
1
1
  PATH
2
2
  remote: .
3
+ specs:
4
+ os (1.0.1)
3
5
 
4
6
  GEM
5
7
  remote: http://rubygems.org/
6
8
  specs:
7
- diff-lcs (1.1.2)
8
- git (1.2.5)
9
- jeweler (1.6.0)
10
- bundler (~> 1.0.0)
11
- git (>= 1.2.5)
12
- rake
13
- rake (0.8.7)
14
- rspec (2.5.0)
15
- rspec-core (~> 2.5.0)
16
- rspec-expectations (~> 2.5.0)
17
- rspec-mocks (~> 2.5.0)
18
- rspec-core (2.5.1)
19
- rspec-expectations (2.5.0)
20
- diff-lcs (~> 1.1.2)
21
- rspec-mocks (2.5.0)
9
+ diff-lcs (1.1.3)
10
+ power_assert (1.0.2)
11
+ rake (0.9.6)
12
+ test-unit (3.2.3)
13
+ power_assert
22
14
 
23
15
  PLATFORMS
24
16
  ruby
25
17
  x86-mingw32
26
18
 
27
19
  DEPENDENCIES
28
- jeweler
29
- rspec (>= 2.0)
20
+ rake (~> 0.8)
21
+ rspec (~> 2.5.0)
22
+ test-unit (~> 3)
23
+
24
+ BUNDLED WITH
25
+ 2.1.4
data/README.md ADDED
@@ -0,0 +1,104 @@
1
+ The OS gem allows for some easy telling if you're on windows or not.
2
+
3
+ ```ruby
4
+ require 'os'
5
+
6
+ >> OS.windows?
7
+ => true # or OS.doze?
8
+
9
+ >> OS.bits
10
+ => 32
11
+
12
+ >> OS.java?
13
+ => true # if you're running in jruby. Also OS.jruby?
14
+
15
+ >> OS.ruby_bin
16
+ => "c:\ruby18\bin\ruby.exe" # or "/usr/local/bin/ruby" or what not
17
+
18
+ >> OS.posix?
19
+ => false # true for linux, os x, cygwin
20
+
21
+ >> OS.mac? # or OS.osx? or OS.x?
22
+ => false
23
+
24
+ >> OS.dev_null
25
+ => "NUL" # or "/dev/null" depending on which platform
26
+
27
+ >> OS.rss_bytes
28
+ => 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)
29
+
30
+ >> puts OS.report
31
+ ==> # a yaml report of helpful values
32
+ ---
33
+ arch: x86_64-darwin10.6.0
34
+ target_os: darwin10.6.0
35
+ target_vendor: apple
36
+ target_cpu: x86_64
37
+ target: x86_64-apple-darwin10.6.0
38
+ host_os: darwin10.6.0
39
+ host_vendor: apple
40
+ host_cpu: i386
41
+ host: i386-apple-darwin10.6.0
42
+ RUBY_PLATFORM: x86_64-darwin10.6.0
43
+
44
+ >> OS.cpu_count
45
+ => 2 # number of cores, doesn't include hyper-threaded cores.
46
+
47
+ >> OS.open_file_command
48
+ => "start" # or open on mac, or xdg-open on linux (all designed to open a file)
49
+
50
+ >> OS::Underlying.windows?
51
+ => true # true for cygwin or MRI, whereas OS.windows? is false for cygwin
52
+
53
+ >> OS::Underlying.bsd?
54
+ => true # true for OS X
55
+
56
+ >> OS::Underlying.docker?
57
+ => false # true if running inside a Docker container
58
+
59
+ >> pp OS.parse_os_release
60
+ ==> # A hash of details on the current Linux distro (or an exception if not Linux)
61
+ {:NAME=>"Ubuntu",
62
+ :VERSION=>"18.04.4 LTS (Bionic Beaver)",
63
+ :ID=>"ubuntu",
64
+ :ID_LIKE=>"debian",
65
+ :PRETTY_NAME=>"Ubuntu 18.04.4 LTS",
66
+ :VERSION_ID=>"18.04",
67
+ :HOME_URL=>"https://www.ubuntu.com/",
68
+ :SUPPORT_URL=>"https://help.ubuntu.com/",
69
+ :BUG_REPORT_URL=>"https://bugs.launchpad.net/ubuntu/",
70
+ :PRIVACY_POLICY_URL=>
71
+ "https://www.ubuntu.com/legal/terms-and-policies/privacy-policy",
72
+ :VERSION_CODENAME=>"bionic",
73
+ :UBUNTU_CODENAME=>"bionic"}
74
+ ```
75
+
76
+ If there are any other features you'd like, let me know, I'll do what I can to add them :)
77
+
78
+ http://github.com/rdp/os for feedback et al
79
+
80
+ Related projects:
81
+
82
+ rubygems:
83
+
84
+ ```ruby
85
+ Gem::Platform.local
86
+ Gem.ruby
87
+ ```
88
+
89
+ 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 gem.
90
+
91
+ the facets gem (has a class similar to rubygems, above)
92
+
93
+ ```ruby
94
+ require 'facets/platform'
95
+ Platform.local
96
+ ```
97
+
98
+ the ["platform" gem](http://rubydoc.info/github/ffi/ffi/master/FFI/Platform), itself (a different gem)
99
+
100
+ ```ruby
101
+ FFI::Platform::OS
102
+ ```
103
+
104
+ License: MIT (see LICENSE file)
data/Rakefile CHANGED
@@ -1,6 +1,14 @@
1
1
  require 'rubygems' if RUBY_VERSION < '1.9.0'
2
2
 
3
+ # HOW TO DEPLOY
4
+ # bump VERSION file manually
5
+ # rake release seems all messed up, doesn't publish it anyway...
3
6
  # Don't forget to run rake gemspec with each release! ... I think...
7
+ # then manually edit os.gemspec remove duplicatee rspecs, circular dependency on os? HUH?
8
+ # # then gem build os.gemspec
9
+ # rake build doesn't work???
10
+ # sooo...
11
+ # ...gem push os-1.1.2.gem
4
12
 
5
13
  begin
6
14
  require 'jeweler'
@@ -11,12 +19,13 @@ begin
11
19
  gem.email = "rogerpack2005@gmail.com"
12
20
  gem.homepage = "http://github.com/rdp/os"
13
21
  gem.authors = ["rdp", "David McCullars"]
22
+ gem.license = "MIT"
14
23
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
24
  # gem.add_development_dependency "fast_require"
16
- gem.add_development_dependency "rspec", ">= 2.0"
25
+ # gem.add_development_dependency "rspec", ">= 2.0"
17
26
  end
18
- rescue LoadError
19
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
27
+ rescue LoadError => e
28
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler #{e}"
20
29
  end
21
30
 
22
31
  require 'rspec/core/rake_task'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0
1
+ 1.1.4
data/lib/os.rb CHANGED
@@ -155,15 +155,15 @@ class OS
155
155
  end
156
156
  processes = wmi.ExecQuery("select * from win32_process where ProcessId = #{Process.pid}")
157
157
  memory_used = nil
158
- # only allow for one...
158
+ # only allow for one process...
159
159
  for process in processes
160
- raise if memory_used
160
+ raise "multiple processes same pid?" if memory_used
161
161
  memory_used = process.WorkingSetSize.to_i
162
162
  end
163
163
  memory_used
164
164
  end
165
165
  elsif OS.posix? # linux [though I've heard it works in OS X]
166
- `ps -o rss= -p #{Process.pid}`.to_i # in kilobytes
166
+ `ps -o rss= -p #{Process.pid}`.to_i * 1024 # in kiloBytes
167
167
  else
168
168
  raise 'unknown rss for this platform'
169
169
  end
@@ -183,6 +183,10 @@ class OS
183
183
  OS.host_os =~ /linux/ ? true : false
184
184
  end
185
185
 
186
+ def self.docker?
187
+ system('grep -q docker /proc/self/cgroup') if OS.linux?
188
+ end
189
+
186
190
  end
187
191
 
188
192
  def self.cygwin?
@@ -260,6 +264,39 @@ class OS
260
264
 
261
265
  end
262
266
 
267
+ def self.app_config_path(name)
268
+ if OS.doze?
269
+ if ENV['LOCALAPPDATA']
270
+ return File.join(ENV['LOCALAPPDATA'], name)
271
+ end
272
+
273
+ File.join ENV['USERPROFILE'], 'Local Settings', 'Application Data', name
274
+ elsif OS.mac?
275
+ File.join ENV['HOME'], 'Library', 'Application Support', name
276
+ else
277
+ if ENV['XDG_CONFIG_HOME']
278
+ return File.join(ENV['XDG_CONFIG_HOME'], name)
279
+ end
280
+
281
+ File.join ENV['HOME'], '.config', name
282
+ end
283
+ end
284
+
285
+ def self.parse_os_release
286
+ if OS.linux? && File.exist?('/etc/os-release')
287
+ output = {}
288
+
289
+ File.read('/etc/os-release').each_line do |line|
290
+ parsed_line = line.chomp.tr('"', '').split('=')
291
+ next if parsed_line.empty?
292
+ output[parsed_line[0].to_sym] = parsed_line[1]
293
+ end
294
+ output
295
+ else
296
+ raise "File /etc/os-release doesn't exists or not Linux"
297
+ end
298
+ end
299
+
263
300
  class << self
264
301
  alias :doze? :windows? # a joke name but I use it and like it :P
265
302
  alias :jruby? :java?
data/os.gemspec CHANGED
@@ -2,22 +2,22 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: os 1.0.0 ruby lib
5
+ # stub: os 1.1.4 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "os".freeze
9
- s.version = "1.0.0"
9
+ s.version = "1.1.4"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib".freeze]
13
13
  s.authors = ["rdp".freeze, "David McCullars".freeze]
14
- s.date = "2017-02-20"
14
+ s.date = "2021-11-07"
15
15
  s.description = "The OS gem allows for some useful and easy functions, like OS.windows? (=> true or false) OS.bits ( => 32 or 64) etc\"".freeze
16
16
  s.email = "rogerpack2005@gmail.com".freeze
17
17
  s.extra_rdoc_files = [
18
18
  "ChangeLog",
19
19
  "LICENSE",
20
- "README.rdoc"
20
+ "README.md"
21
21
  ]
22
22
  s.files = [
23
23
  ".autotest",
@@ -26,7 +26,7 @@ Gem::Specification.new do |s|
26
26
  "Gemfile",
27
27
  "Gemfile.lock",
28
28
  "LICENSE",
29
- "README.rdoc",
29
+ "README.md",
30
30
  "Rakefile",
31
31
  "VERSION",
32
32
  "autotest/discover.rb",
@@ -38,18 +38,25 @@ Gem::Specification.new do |s|
38
38
  "spec/spec_helper.rb"
39
39
  ]
40
40
  s.homepage = "http://github.com/rdp/os".freeze
41
- s.rubygems_version = "2.5.2".freeze
41
+ s.licenses = ["MIT".freeze]
42
+ s.rubygems_version = "2.7.6".freeze
42
43
  s.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.".freeze
43
44
 
44
45
  if s.respond_to? :specification_version then
45
46
  s.specification_version = 4
46
47
 
47
48
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
49
+ s.add_development_dependency(%q<rake>.freeze, ["~> 0.8"])
50
+ s.add_development_dependency(%q<test-unit>.freeze, ["~> 3"])
48
51
  s.add_development_dependency(%q<rspec>.freeze, [">= 2.0"])
49
52
  else
53
+ s.add_dependency(%q<rake>.freeze, ["~> 0.8"])
54
+ s.add_dependency(%q<test-unit>.freeze, ["~> 3"])
50
55
  s.add_dependency(%q<rspec>.freeze, [">= 2.0"])
51
56
  end
52
57
  else
58
+ s.add_dependency(%q<rake>.freeze, ["~> 0.8"])
59
+ s.add_dependency(%q<test-unit>.freeze, ["~> 3"])
53
60
  s.add_dependency(%q<rspec>.freeze, [">= 2.0"])
54
61
  end
55
62
  end
data/spec/os_spec.rb CHANGED
@@ -119,10 +119,9 @@ describe "OS" do
119
119
  end
120
120
 
121
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
122
+ cpu_count = OS.cpu_count
123
+ assert cpu_count >= 1
124
+ assert (cpu_count & (cpu_count - 1)) == 0 # CPU count is normally a power of 2
126
125
  end
127
126
 
128
127
  it "has working cpu count method with no env. variable" do
@@ -143,6 +142,23 @@ describe "OS" do
143
142
  end
144
143
  end
145
144
 
145
+ it "should provide a path to directory for application config" do
146
+ ENV.stub(:[])
147
+
148
+ if OS.mac?
149
+ ENV.stub(:[]).with('HOME').and_return('/home/user')
150
+ assert OS.app_config_path('appname') == '/home/xdg/Library/Application Support/appname'
151
+ elsif OS.doze?
152
+ # TODO
153
+ else
154
+ ENV.stub(:[]).with('HOME').and_return('/home/user')
155
+ assert OS.app_config_path('appname') == '/home/user/.config/appname'
156
+
157
+ ENV.stub(:[]).with('XDG_CONFIG_HOME').and_return('/home/xdg/.config')
158
+ assert OS.app_config_path('appname') == '/home/xdg/.config/appname'
159
+ end
160
+ end
161
+
146
162
  it "should have a freebsd? method" do
147
163
  if OS.host_os =~ /freebsd/
148
164
  assert OS.freebsd? == true
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: os
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - rdp
@@ -9,8 +9,36 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-02-20 00:00:00.000000000 Z
12
+ date: 2021-11-07 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '0.8'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '0.8'
28
+ - !ruby/object:Gem::Dependency
29
+ name: test-unit
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '3'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '3'
14
42
  - !ruby/object:Gem::Dependency
15
43
  name: rspec
16
44
  requirement: !ruby/object:Gem::Requirement
@@ -33,7 +61,7 @@ extensions: []
33
61
  extra_rdoc_files:
34
62
  - ChangeLog
35
63
  - LICENSE
36
- - README.rdoc
64
+ - README.md
37
65
  files:
38
66
  - ".autotest"
39
67
  - ".document"
@@ -41,7 +69,7 @@ files:
41
69
  - Gemfile
42
70
  - Gemfile.lock
43
71
  - LICENSE
44
- - README.rdoc
72
+ - README.md
45
73
  - Rakefile
46
74
  - VERSION
47
75
  - autotest/discover.rb
@@ -52,7 +80,8 @@ files:
52
80
  - spec/osx_spec.rb
53
81
  - spec/spec_helper.rb
54
82
  homepage: http://github.com/rdp/os
55
- licenses: []
83
+ licenses:
84
+ - MIT
56
85
  metadata: {}
57
86
  post_install_message:
58
87
  rdoc_options: []
@@ -70,7 +99,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
70
99
  version: '0'
71
100
  requirements: []
72
101
  rubyforge_project:
73
- rubygems_version: 2.5.2
102
+ rubygems_version: 2.7.6
74
103
  signing_key:
75
104
  specification_version: 4
76
105
  summary: Simple and easy way to know if you're on windows or not (reliably), as well
data/README.rdoc DELETED
@@ -1,75 +0,0 @@
1
- The OS gem allows for some easy telling if you're on windows or not.
2
-
3
- require 'os'
4
-
5
- >> OS.windows?
6
- => true # or OS.doze?
7
-
8
- >> OS.bits
9
- => 32
10
-
11
- >> OS.java?
12
- => true # if you're running in jruby. Also OS.jruby?
13
-
14
- >> OS.ruby_bin
15
- => "c:\ruby18\bin\ruby.exe" # or "/usr/local/bin/ruby" or what not
16
-
17
- >> OS.posix?
18
- => false # true for linux, os x, cygwin
19
-
20
- >> OS.mac? # or OS.osx? or OS.x?
21
- => false
22
-
23
- >> OS.dev_null
24
- => "NUL" # or "/dev/null" depending on which platform
25
-
26
- >> OS.rss_bytes
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)
28
-
29
- >> puts OS.report
30
- ==> # a yaml report of helpful values
31
- ---
32
- arch: x86_64-darwin10.6.0
33
- target_os: darwin10.6.0
34
- target_vendor: apple
35
- target_cpu: x86_64
36
- target: x86_64-apple-darwin10.6.0
37
- host_os: darwin10.6.0
38
- host_vendor: apple
39
- host_cpu: i386
40
- host: i386-apple-darwin10.6.0
41
- RUBY_PLATFORM: x86_64-darwin10.6.0
42
-
43
- >> OS.cpu_count
44
- => 2 # number of cores, doesn't include hyper-threaded cores.
45
-
46
- >> OS.open_file_command
47
- => "start" # or open on mac, or xdg-open on linux (all designed to open a file)
48
-
49
- >> OS::Underlying.windows?
50
- => true # true for cygwin or MRI, whereas OS.windows? is false for cygwin
51
-
52
- >> OS::Underlying.bsd?
53
- => true # true for OS X
54
-
55
- If there are any other features you'd like, let me know, I'll do what I can to add them :)
56
-
57
- http://github.com/rdp/os for feedback et al
58
-
59
- Related projects:
60
-
61
- rubygems:
62
- Gem::Platform.local
63
- Gem.ruby
64
- 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 gem.
65
-
66
- the facets gem (has a class similar to rubygems, above)
67
- require 'facets/platform'
68
- Platform.local
69
-
70
- the "platform" gem, itself (a different gem)
71
-
72
- FFI::Platform::OS
73
- http://rubydoc.info/github/ffi/ffi/master/FFI/Platform
74
-
75
- License: MIT (see LICENSE file)