seppuku 0.2

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.
Files changed (7) hide show
  1. data/Manifest +5 -0
  2. data/README +34 -0
  3. data/Rakefile +12 -0
  4. data/bin/seppuku +6 -0
  5. data/lib/seppuku.rb +123 -0
  6. data/seppuku.gemspec +32 -0
  7. metadata +79 -0
data/Manifest ADDED
@@ -0,0 +1,5 @@
1
+ README
2
+ Rakefile
3
+ bin/seppuku
4
+ lib/seppuku.rb
5
+ Manifest
data/README ADDED
@@ -0,0 +1,34 @@
1
+ = Project: Seppuku
2
+
3
+ = Description:
4
+
5
+ Seppuku is a cmdline utility that simplifies killing procs listed in your ps table.
6
+ You simply specify the kill level and program name you want to kill - Seppuku will
7
+ prompt you to either kill *all* matches in the ps table, or, prompt you for each process
8
+ entry found.
9
+
10
+ = Usage
11
+
12
+ seppku -h
13
+ Usage: seppuku [options]
14
+ -n, --name NAME Process name within ps table
15
+ -l, --level LEVEL Kill level for operation
16
+ -h, --help Show this screen
17
+
18
+ = Example
19
+
20
+ seppuku -l 9 - n deathrow_program
21
+
22
+
23
+ = Installation
24
+
25
+ Gem is hosted on gemcutter.org
26
+
27
+ 1.) gem install seppuku
28
+
29
+ = Notes:
30
+ the ps scan regexp might not work with *all* system ps utilities; if you experience any problems try to change
31
+ the ps related constants within the main lib file.
32
+
33
+
34
+
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'echoe'
4
+
5
+ Echoe.new('seppuku', '0.2') do |p|
6
+ p.description = "a ruby cmdline utility that simplifies killing procs listed in your ps table"
7
+ p.url = "http://github.com/gadogado/seppuku"
8
+ p.author = "Geoff Ereth"
9
+ p.email = "geoffereth @nospamplease@ gmail com"
10
+ p.ignore_pattern = ["tmp/*", "script/*"]
11
+ p.development_dependencies = []
12
+ end
data/bin/seppuku ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # G Ereth, 2010
3
+
4
+ require File.join(File.dirname(__FILE__), '/../lib/seppuku')
5
+
6
+ Seppuku.run
data/lib/seppuku.rb ADDED
@@ -0,0 +1,123 @@
1
+ require 'rubygems'
2
+ require 'optparse'
3
+ require 'open3'
4
+
5
+ REGEXP = /^(\d+)\s+(.*?)$/
6
+ PS = 'ps ax -o pid -o command'
7
+
8
+ class Seppuku
9
+ class<<self
10
+
11
+ def run
12
+ ready
13
+ draw!
14
+ end
15
+
16
+ def search
17
+ @search ||= Regexp.new(@opts[:name])
18
+ end
19
+
20
+ def command
21
+ Proc.new do |cmd|
22
+ Open3.popen3(cmd) do |si,so,se|
23
+ stderr = se.readlines
24
+ raise stderr.join('.') unless stderr.empty?
25
+ so.readlines
26
+ end
27
+ end
28
+ end
29
+
30
+ def matches
31
+ matches=[]
32
+ command.call(PS).each do |line|
33
+ if line =~ search
34
+ if line !~ /#{$0}/
35
+ matches << line.scan(REGEXP).flatten.map {|m| m.strip }
36
+ end
37
+ end
38
+ end
39
+ matches.delete_if{|m| m.empty?}
40
+ end
41
+
42
+ def draw!
43
+ disengage if matches.empty?
44
+ dots = "."*23
45
+ hding = "#{dots}\n#{matches.size} matches were found!\n"
46
+ puts matches.map {|m| match(m) }.push(hding)
47
+ kill_all_or_wisely
48
+ end
49
+
50
+ def kill_all(matches)
51
+ matches.each { |m| kill(m) }
52
+ end
53
+
54
+ def kill_wisely(matches)
55
+ matches.each do |m|
56
+ kill_ques(m.last)
57
+ ans = gets
58
+ proceed.call(ans) ? kill(m) : next
59
+ end
60
+ end
61
+
62
+ def kill_all_or_wisely
63
+ if matches.size > 1
64
+ kill_ques('*ALL*')
65
+ ans = gets
66
+ proceed.call(ans) ? kill_all(matches) : kill_wisely(matches)
67
+ else
68
+ kill_wisely(matches)
69
+ end
70
+ end
71
+
72
+ def disengage
73
+ puts '<-> nothing to kill <->'
74
+ exit
75
+ end
76
+
77
+ def kill(m)
78
+ begin
79
+ pid = m.first
80
+ cmd = "kill -#{@opts[:level]} #{pid}"
81
+ command.call(cmd)
82
+ puts "<.> killed:#{pid} <.>"
83
+
84
+ rescue Exception => msg
85
+ puts "#{msg} #{msg.backtrace.join(' ')}"
86
+ end
87
+ end
88
+
89
+ def proceed
90
+ Proc.new { |ans| true if ans =~ /y/i }
91
+ end
92
+
93
+ def match(m)
94
+ "> #{m.join(' : ')}"
95
+ end
96
+
97
+ def kill_ques(type)
98
+ puts "> (y/n) ? kill -#{@opts[:level]} [#{type}]"
99
+ end
100
+
101
+ def ready
102
+ @opts={}
103
+ options = OptionParser.new do |op|
104
+ op.on('-n','--name NAME',"Process name within ps table") { |n| @opts[:name] = n }
105
+ op.on('-l','--level LEVEL',"Kill level for operation") { |l| @opts[:level] = l }
106
+ op.on('-h', '--help', 'Show this screen') { puts options; exit }
107
+ end
108
+ parse(options)
109
+ end
110
+
111
+ def parse(options)
112
+ options.parse!
113
+ if @opts[:level].nil? || @opts[:name].nil?
114
+ puts options
115
+ raise OptionParser::MissingArgument
116
+ end
117
+ end
118
+
119
+ end
120
+ end
121
+
122
+
123
+
data/seppuku.gemspec ADDED
@@ -0,0 +1,32 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{seppuku}
5
+ s.version = "0.2"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Geoff Ereth"]
9
+ s.date = %q{2010-07-01}
10
+ s.default_executable = %q{seppuku}
11
+ s.description = %q{a ruby cmdline utility that simplifies killing procs listed in your ps table}
12
+ s.email = %q{geoffereth @nospamplease@ gmail com}
13
+ s.executables = ["seppuku"]
14
+ s.extra_rdoc_files = ["README", "bin/seppuku", "lib/seppuku.rb"]
15
+ s.files = ["README", "Rakefile", "bin/seppuku", "lib/seppuku.rb", "Manifest", "seppuku.gemspec"]
16
+ s.homepage = %q{http://github.com/gadogado/seppuku}
17
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Seppuku", "--main", "README"]
18
+ s.require_paths = ["lib"]
19
+ s.rubyforge_project = %q{seppuku}
20
+ s.rubygems_version = %q{1.3.7}
21
+ s.summary = %q{a ruby cmdline utility that simplifies killing procs listed in your ps table}
22
+
23
+ if s.respond_to? :specification_version then
24
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
25
+ s.specification_version = 3
26
+
27
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
28
+ else
29
+ end
30
+ else
31
+ end
32
+ end
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: seppuku
3
+ version: !ruby/object:Gem::Version
4
+ hash: 15
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 2
9
+ version: "0.2"
10
+ platform: ruby
11
+ authors:
12
+ - Geoff Ereth
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-07-01 00:00:00 -07:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: a ruby cmdline utility that simplifies killing procs listed in your ps table
22
+ email: geoffereth @nospamplease@ gmail com
23
+ executables:
24
+ - seppuku
25
+ extensions: []
26
+
27
+ extra_rdoc_files:
28
+ - README
29
+ - bin/seppuku
30
+ - lib/seppuku.rb
31
+ files:
32
+ - README
33
+ - Rakefile
34
+ - bin/seppuku
35
+ - lib/seppuku.rb
36
+ - Manifest
37
+ - seppuku.gemspec
38
+ has_rdoc: true
39
+ homepage: http://github.com/gadogado/seppuku
40
+ licenses: []
41
+
42
+ post_install_message:
43
+ rdoc_options:
44
+ - --line-numbers
45
+ - --inline-source
46
+ - --title
47
+ - Seppuku
48
+ - --main
49
+ - README
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ hash: 3
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ hash: 11
67
+ segments:
68
+ - 1
69
+ - 2
70
+ version: "1.2"
71
+ requirements: []
72
+
73
+ rubyforge_project: seppuku
74
+ rubygems_version: 1.3.7
75
+ signing_key:
76
+ specification_version: 3
77
+ summary: a ruby cmdline utility that simplifies killing procs listed in your ps table
78
+ test_files: []
79
+