rlps 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d61a68df5edd1909af9aca5cf6c5c1c3219fe6a0
4
+ data.tar.gz: 6cc743712c12c4948412678658147c29330f7927
5
+ SHA512:
6
+ metadata.gz: c6e8b7b6341b42f9e43f15aabbd8c6ad193e3c4d7d6793e1b36ac726bb3f100d57d6bcf7de618c38751614838b4e2dbddfe93d45ed13d1a4ff356f79cce5a2ad
7
+ data.tar.gz: 11efb6930e540d746694c32425bc85e056c976c23dc1636019708ecd5e1e1164fae0b1b945ec04ed90076ad6806996802f8747c727907ec06b598efbbd340ca3
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rlps.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Ahmed Khaled
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,48 @@
1
+ # RLPS
2
+
3
+ **RLPS** is a very simple and pure Ruby gem which sole prupose is to get a **list** of the currently **running processes** in a **Linux** system by reading data from Linux /proc/ directory.
4
+ More information read The Linux Documentation Project [topic](http://tldp.org/LDP/Linux-Filesystem-Hierarchy/html/proc.html) on this subject.
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'rlps'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install rlps
20
+
21
+ ## Documentation
22
+ See https://nemoload.github.io/rlps/
23
+ ## Usage
24
+ ``` ruby
25
+ require 'rlps'
26
+
27
+ my_processes = RLPS.processes
28
+
29
+ p my_processes[0] # => systemd: 1
30
+ p my_processes[0].name # => systemd
31
+ p my_processes[0].pid # => 1
32
+ ```
33
+ Returns a list of [RLPS::Process](http://www.github.com/nemoload) objects.
34
+ ## CLI
35
+ **TL;DR: Don't.**
36
+ Although this gem wasn't made to be used as a CLI application, it can act as a very bad, ineffecient version of Linux ``` $ ps -e ```:
37
+
38
+ $ rlps
39
+
40
+ ## Contributing
41
+
42
+ Bug reports and pull requests are welcome on GitHub at https://github.com/nemoload/rlps.
43
+
44
+
45
+ ## License
46
+
47
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
48
+
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rdoc/task'
3
+
4
+ task default: :spec
5
+
6
+ RDoc::Task.new :rdoc do |rdoc|
7
+ rdoc.main = 'README.md'
8
+ rdoc.rdoc_files.include('README.md', 'lib/*.rb',
9
+ 'lib/rlps/*.rb', 'lib/rlps/helper/*.rb')
10
+ rdoc.rdoc_dir = 'doc/'
11
+ rdoc.title = 'RLPS Documentation'
12
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'rlps'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/exe/rlps ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ $LOAD_PATH.push File.expand_path('../../lib', __FILE__)
3
+ require 'rlps'
4
+ RLPS.processes.each { |p| print "#{p.name}\t#{p.pid}\n" }
data/lib/rlps.rb ADDED
@@ -0,0 +1,32 @@
1
+ require 'rlps/version'
2
+ require 'rlps/process'
3
+ require 'rlps/string'
4
+ require 'rlps/helper/parser'
5
+
6
+ module RLPS
7
+ class << self
8
+ attr_accessor :processes
9
+ end
10
+
11
+ module_function
12
+
13
+ # Get the currently runing processes as a list.
14
+ def processes
15
+ @processes ||= parse_processes
16
+ end
17
+
18
+ # Update the already fetched processes list.
19
+ def update!
20
+ @process = parse_processes
21
+ end
22
+
23
+ private
24
+
25
+ def self.parse_processes
26
+ processes_arr = []
27
+ Dir.entries('/proc/').each do |dir|
28
+ processes_arr << RLPS::Parser.process_from_dir(dir) if dir.int?
29
+ end
30
+ processes_arr
31
+ end
32
+ end
@@ -0,0 +1,22 @@
1
+ require 'rlps/string'
2
+ require 'rlps/process'
3
+
4
+ module RLPS
5
+
6
+ # This class parses Linux's /proc/ directory status file.
7
+ class Parser
8
+ # This method gets a /proc/ directory, then it parses
9
+ # its status file and returns a new RLPS::Process object.
10
+ def self.process_from_dir(dir)
11
+ status = {}
12
+ File.open(File.join(File.join('/proc', dir), 'status'), 'r') do |f|
13
+ f.each_line do |line|
14
+ res = line.match(/(^\w+):\s*(\d+|[\w\(\)\-]+)?/).captures
15
+ res[1] ||= nil
16
+ status[res[0]] = res[1]
17
+ end
18
+ end
19
+ RLPS::Process.new name: status['Name'], pid: status['Pid'].to_i
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,54 @@
1
+ module RLPS
2
+ ##
3
+ # Represents a process
4
+ ##
5
+ class Process
6
+ attr_reader :name, :pid
7
+ # Takes two arguments _:name_ and _:pid_
8
+ # If called without any arguments it calls RLPS::Process.this_process.
9
+ # ==== Examples
10
+ # RLPS::Process.new name: "ruby", pid: 2365
11
+ def initialize(**args)
12
+ #-- other = args.select { |k, _v| ((k == :name) &&
13
+ # !args[k].nil?) || ((k == :pid) && !args[k].nil?) }
14
+ # raise if (other.count == 0) || (args.count != 2)
15
+ # TODO check if this process actually exists
16
+ @name = args[:name] || this_process.name
17
+ @pid = args[:pid] || this_process.pid
18
+ end
19
+
20
+ def to_s
21
+ "#{@name}: #{@pid}"
22
+ end
23
+
24
+ def to_i
25
+ @pid
26
+ end
27
+
28
+ # Returns true if the process is still running.
29
+ def still_running?
30
+ !RLPS.processes.select do |p|
31
+ p.pid == @pid &&
32
+ p.name.casecmp(@name.downcase).zero?
33
+ end.empty?
34
+ end
35
+
36
+ # Send INT signal to the process as a default behaviour.
37
+ # It accepts any signal Kernel#Process takes.
38
+ # More info: Kernel[https://ruby-doc.org/core/Kernel.html]
39
+ def kill!(signal = 'INT')
40
+ ::Process.kill(signal, @pid)
41
+ end
42
+
43
+ # Return this process RLPS::Process object.
44
+ def self.this_process
45
+ process = RLPS.processes.select { |p| p.pid == ::Process.pid }
46
+ RLPS::Process.new name: process[0].name, pid: ::Process.pid
47
+ end
48
+
49
+ def self.get(name: nil, pid: nil) #:nodoc:
50
+ # TODO
51
+ end
52
+ alias inspect to_s
53
+ end
54
+ end
@@ -0,0 +1,12 @@
1
+ # Monkey patch the Ruby's core string class
2
+ # to check whether this /proc/ directory
3
+ # represents an actual process or not which
4
+ # always displayed as an integer.
5
+ # More info: {The Linux Documentation Project}[http://tldp.org/LDP/Linux-Filesystem-Hierarchy/html/proc.html]
6
+ class String
7
+ # Reeturns true if the string represents
8
+ # an actual integer.
9
+ def int?
10
+ to_i.to_s == self
11
+ end
12
+ end
@@ -0,0 +1,4 @@
1
+ module RLPS
2
+ # The current gem version.
3
+ VERSION = '0.1.0'.freeze
4
+ end
data/rlps.gemspec ADDED
@@ -0,0 +1,39 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rlps/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'rlps'
8
+ spec.version = RLPS::VERSION
9
+ spec.authors = ['Ahmed Khaled']
10
+ spec.email = ['nemoload@aol.com']
11
+
12
+ spec.summary = 'Pure Ruby impelementation to walk through Linux\'s proc'
13
+ spec.description = 'A pure and intutive way to walk \
14
+ through the current running processes \
15
+ on Linux machine'
16
+ spec.homepage = 'https://nemoload.github.io'
17
+ spec.license = 'MIT'
18
+
19
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
20
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
21
+ # if spec.respond_to?(:metadata)
22
+ # spec.metadata['allowed_push_host'] = 'http://rubygems.org/'
23
+ # else
24
+ # raise 'RubyGems 2.0 or newer is required to protect against ' \
25
+ # 'public gem pushes.'
26
+ # end
27
+
28
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
29
+ f.match(%r{^(test|spec|features)/})
30
+ end
31
+ spec.bindir = 'exe'
32
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
33
+ spec.require_paths = ['lib']
34
+
35
+ spec.add_development_dependency 'bundler', '~> 1.14'
36
+ spec.add_development_dependency 'rake', '~> 10.0'
37
+ spec.add_development_dependency 'rspec', '~> 3.5'
38
+ spec.add_development_dependency 'rdoc', '~> 5.0'
39
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rlps
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ahmed Khaled
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-02-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.14'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.14'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.5'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rdoc
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '5.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '5.0'
69
+ description: |-
70
+ A pure and intutive way to walk \
71
+ through the current running processes \
72
+ on Linux machine
73
+ email:
74
+ - nemoload@aol.com
75
+ executables:
76
+ - rlps
77
+ extensions: []
78
+ extra_rdoc_files: []
79
+ files:
80
+ - ".gitignore"
81
+ - Gemfile
82
+ - LICENSE.txt
83
+ - README.md
84
+ - Rakefile
85
+ - bin/console
86
+ - bin/setup
87
+ - exe/rlps
88
+ - lib/rlps.rb
89
+ - lib/rlps/helper/parser.rb
90
+ - lib/rlps/process.rb
91
+ - lib/rlps/string.rb
92
+ - lib/rlps/version.rb
93
+ - rlps.gemspec
94
+ homepage: https://nemoload.github.io
95
+ licenses:
96
+ - MIT
97
+ metadata: {}
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubyforge_project:
114
+ rubygems_version: 2.6.8
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: Pure Ruby impelementation to walk through Linux's proc
118
+ test_files: []