ps-ruby 0.0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b3ff7a462e7aaeba2c9ee15d511328806f0216b9
4
+ data.tar.gz: 4490d6b8aaaa391dde6c75b1222f76d7f3249e83
5
+ SHA512:
6
+ metadata.gz: 71f7b329057d976c46e87db7c33159f11a6eabf684a8face4902ba8289466467b21ef2d84a10a289949edee80a2dcad0c7c5226ac578affe2cce42c3d377dba7
7
+ data.tar.gz: bb5bdeed8cf3b42b21983aa0f3fc07b3db3b4385d6f95c9eb2e570124cadaa97f62f96e810de3806bfb6dfc0fd0530d5994615174f0fe21ec4bb913f0ba65462
@@ -0,0 +1 @@
1
+ pkg
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ps-ruby.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 HondaDai
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 HondaDai
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,10 @@
1
+
2
+ require File.join(File.expand_path(File.dirname(__FILE__)), "../lib/ps-ruby.rb")
3
+
4
+ puts PS.attrs.to_s
5
+ puts PS.find_process("zsh").to_s
6
+
7
+
8
+ # PS.simple_display(/.*zsh.*/i)
9
+ # PS.simple_display("chrome")
10
+ # PS.simple_display
@@ -0,0 +1,5 @@
1
+
2
+ require File.join(File.dirname(__FILE__), 'ps-ruby/ps-ruby')
3
+ require File.join(File.dirname(__FILE__), 'ps-ruby/version')
4
+
5
+
@@ -0,0 +1,60 @@
1
+
2
+ module PS
3
+ module_function
4
+
5
+ def simple_display(name = "", limit_process_name_len=30)
6
+ result = find_process(name)
7
+ picks = ["PID", "%CPU", "%MEM", "COMMAND"]
8
+ if result.size > 0
9
+ puts picks.join("\t")+"\n"
10
+ result.each{|x|
11
+ puts picks.reduce(""){|s, k|
12
+ s += if k == "COMMAND" and x[k].size > limit_process_name_len then
13
+ "#{x[k][0..limit_process_name_len]}...\t"
14
+ else
15
+ "#{x[k]}\t"
16
+ end
17
+ }
18
+ }
19
+ else
20
+ puts "Not found any process called `#{name}`"
21
+ end
22
+ nil
23
+ end
24
+
25
+ def find_process(name)
26
+ regex = if name.class != Regexp then Regexp.new(".*#{name}.*", Regexp::IGNORECASE) else name end
27
+ aux.select{|x| x["COMMAND"] =~ regex }
28
+ end
29
+
30
+ def processes
31
+ pick_attr("COMMAND").uniq.sort
32
+ end
33
+
34
+ def attrs
35
+ return @ps_attrs if @ps_attrs
36
+ @ps_attrs = raw_aux.split("\n").map{|x| x.split(/\s+/) }.shift
37
+ end
38
+
39
+ def pick_attr(attr_name)
40
+ return aux.map{|x| x[attr_name]} if attrs.include?(attr_name)
41
+ end
42
+
43
+ def aux
44
+ table = raw_aux.split("\n").map{|x| x.split(/\s+/) }
45
+ attrs = table.shift
46
+ table = table.reduce([]) {|s, x|
47
+ if x.size > attrs.size
48
+ x = x[0..(attrs.size-2)] + [x[(attrs.size-1)..-1].join(" ")]
49
+ end
50
+ s << Hash[attrs.zip(x)]
51
+ }
52
+ table
53
+ end
54
+
55
+ def raw_aux
56
+ %x{ps aux}
57
+ end
58
+
59
+ end
60
+
@@ -0,0 +1,7 @@
1
+ module PS
2
+ module_function
3
+
4
+ def VERSION
5
+ "0.0.1"
6
+ end
7
+ end
@@ -0,0 +1,20 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ps-ruby/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ps-ruby"
8
+ spec.version = PS.VERSION
9
+ spec.authors = ["HondaDai"]
10
+ spec.email = ["hondadai.tw@gmail.com"]
11
+ spec.summary = %q{PS-Ruby is a simple ps wrapper with ruby}
12
+ spec.homepage = "https://github.com/HondaDai/ps-ruby"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ end
@@ -0,0 +1,60 @@
1
+
2
+ # PS-Ruby
3
+
4
+ PS-Ruby is a simple ps wrapper with ruby. You can see (example.rb)[example.rb] to learn more...
5
+
6
+ # Usage
7
+
8
+
9
+ Display all processes
10
+
11
+ ```
12
+ > PS.simple_display
13
+ ```
14
+
15
+ ```
16
+ PID %CPU %MEM COMMAND
17
+ 36484 21.1 0.6 /Applications/Google Chrome.app...
18
+ 36140 19.0 1.0 /Applications/Google Chrome.app...
19
+ 67812 14.7 0.2 /Applications/Sublime Text.app/...
20
+ 67813 13.7 0.1 ruby example.rb
21
+ ...
22
+ ```
23
+
24
+ Display special process by name
25
+
26
+ ```
27
+ > PS.simple_display("zsh")
28
+ ```
29
+
30
+ or
31
+
32
+ ```
33
+ > PS.simple_display(/.*zsh.*/i)
34
+ ```
35
+
36
+ ```
37
+ PID %CPU %MEM COMMAND
38
+ 59395 0.4 0.0 -zsh
39
+ 67468 0.0 0.0 -zsh
40
+ 83005 0.0 0.0 -zsh
41
+ ```
42
+
43
+ Get special process by name
44
+
45
+
46
+ ```
47
+ > PS.find_process("zsh")
48
+ ```
49
+
50
+ ```
51
+ [{"USER"=>"HondaDai", "PID"=>"59395", "%CPU"=>"0.4", "%MEM"=>"0.0", "VSZ"=>"2462760", "RSS"=>"3308", "TT"=>"s002", "STAT"=>"S", "STARTED"=>"2:21PM", "TIME"=>"0:00.75", "COMMAND"=>"-zsh"}, {"USER"=>"HondaDai", "PID"=>"83005", "%CPU"=>"0.0", "%MEM"=>"0.0", "VSZ"=>"2462760", "RSS"=>"776", "TT"=>"s001", "STAT"=>"S+", "STARTED"=>"10:10PM", "TIME"=>"0:01.07", "COMMAND"=>"-zsh"}, {"USER"=>"HondaDai", "PID"=>"67468", "%CPU"=>"0.0", "%MEM"=>"0.0", "VSZ"=>"2462760", "RSS"=>"196", "TT"=>"s000", "STAT"=>"S", "STARTED"=>"Fri03PM", "TIME"=>"0:00.78", "COMMAND"=>"-zsh"}]
52
+ ```
53
+
54
+ Get all processes
55
+
56
+ ```ruby
57
+ > PS.processes
58
+ ```
59
+
60
+ omited
metadata ADDED
@@ -0,0 +1,56 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ps-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - HondaDai
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-04-02 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email:
15
+ - hondadai.tw@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".gitignore"
21
+ - Gemfile
22
+ - LICENSE
23
+ - LICENSE.txt
24
+ - Rakefile
25
+ - example/example.rb
26
+ - lib/ps-ruby.rb
27
+ - lib/ps-ruby/ps-ruby.rb
28
+ - lib/ps-ruby/version.rb
29
+ - pkg/ps-ruby-0.0.1.gem
30
+ - ps-ruby.gemspec
31
+ - readme.md
32
+ homepage: https://github.com/HondaDai/ps-ruby
33
+ licenses:
34
+ - MIT
35
+ metadata: {}
36
+ post_install_message:
37
+ rdoc_options: []
38
+ require_paths:
39
+ - lib
40
+ required_ruby_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ required_rubygems_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ requirements: []
51
+ rubyforge_project:
52
+ rubygems_version: 2.2.2
53
+ signing_key:
54
+ specification_version: 4
55
+ summary: PS-Ruby is a simple ps wrapper with ruby
56
+ test_files: []