knjrbfw 0.0.110 → 0.0.114

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +5 -5
  2. data/Rakefile +0 -14
  3. data/lib/knj/autoload.rb +1 -2
  4. data/lib/knj/gtk2_window.rb +7 -7
  5. data/lib/knj/image.rb +60 -51
  6. data/lib/knj/scripts/php_to_rb_helper.rb +13 -20
  7. data/lib/knj/unix_proc.rb +35 -35
  8. data/lib/knj/web.rb +135 -136
  9. metadata +32 -85
  10. data/.document +0 -5
  11. data/.rspec +0 -1
  12. data/Gemfile +0 -22
  13. data/Gemfile.lock +0 -90
  14. data/VERSION +0 -1
  15. data/knjrbfw.gemspec +0 -318
  16. data/lib/knj/.gitignore +0 -1
  17. data/lib/knj/datarow.rb +0 -873
  18. data/lib/knj/datarow_custom.rb +0 -153
  19. data/lib/knj/db.rb +0 -1
  20. data/lib/knj/knjdb/dbtime.rb +0 -35
  21. data/lib/knj/knjdb/drivers/mysql/knjdb_mysql.rb +0 -604
  22. data/lib/knj/knjdb/drivers/mysql/knjdb_mysql_columns.rb +0 -155
  23. data/lib/knj/knjdb/drivers/mysql/knjdb_mysql_indexes.rb +0 -69
  24. data/lib/knj/knjdb/drivers/mysql/knjdb_mysql_sqlspecs.rb +0 -5
  25. data/lib/knj/knjdb/drivers/mysql/knjdb_mysql_tables.rb +0 -443
  26. data/lib/knj/knjdb/drivers/sqlite3/knjdb_sqlite3.rb +0 -184
  27. data/lib/knj/knjdb/drivers/sqlite3/knjdb_sqlite3_columns.rb +0 -177
  28. data/lib/knj/knjdb/drivers/sqlite3/knjdb_sqlite3_indexes.rb +0 -29
  29. data/lib/knj/knjdb/drivers/sqlite3/knjdb_sqlite3_sqlspecs.rb +0 -5
  30. data/lib/knj/knjdb/drivers/sqlite3/knjdb_sqlite3_tables.rb +0 -449
  31. data/lib/knj/knjdb/dump.rb +0 -122
  32. data/lib/knj/knjdb/idquery.rb +0 -109
  33. data/lib/knj/knjdb/libknjdb.rb +0 -797
  34. data/lib/knj/knjdb/libknjdb_java_sqlite3.rb +0 -83
  35. data/lib/knj/knjdb/libknjdb_row.rb +0 -153
  36. data/lib/knj/knjdb/libknjdb_sqlite3_ironruby.rb +0 -69
  37. data/lib/knj/knjdb/query_buffer.rb +0 -87
  38. data/lib/knj/knjdb/revision.rb +0 -342
  39. data/lib/knj/knjdb/sqlspecs.rb +0 -5
  40. data/lib/knj/objects.rb +0 -957
  41. data/lib/knj/process.rb +0 -480
  42. data/lib/knj/process_meta.rb +0 -569
  43. data/lib/knj/scripts/process_meta_exec.rb +0 -144
  44. data/lib/knj/sshrobot/sshrobot.rb +0 -135
  45. data/lib/knj/sshrobot.rb +0 -1
  46. data/lib/knj/translations.rb +0 -133
  47. data/spec/amixer_spec.rb +0 -32
  48. data/spec/arrayext_spec.rb +0 -42
  49. data/spec/autoload_spec.rb +0 -7
  50. data/spec/cmd_parser_spec.rb +0 -25
  51. data/spec/db_spec.rb +0 -282
  52. data/spec/db_spec_encoding_test_file.txt +0 -1
  53. data/spec/knjrbfw_spec.rb +0 -109
  54. data/spec/locales_spec.rb +0 -9
  55. data/spec/objects_spec.rb +0 -394
  56. data/spec/process_meta_spec.rb +0 -172
  57. data/spec/process_spec.rb +0 -115
  58. data/spec/spec_helper.rb +0 -12
  59. data/spec/strings_spec.rb +0 -65
  60. data/spec/web_spec.rb +0 -77
  61. data/testfiles/image.jpg +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: c894f6dac2d6899c0d42d2874968ed41d5878145
4
- data.tar.gz: cbeeb680377f41ec8783cf6cf266532d86de000c
2
+ SHA256:
3
+ metadata.gz: 07fe0af5b28cf7ca05f3046d0790968c1296b06bd7cb62d5c66736824f08e7c8
4
+ data.tar.gz: b2e0be27b9cc06223b8a87439b6d676d611f8220038a1b95fba83de9dda51688
5
5
  SHA512:
6
- metadata.gz: 8173fec01b767f6e7865ee7fd7b6270471eee04803457d6547d24cd9bfad8b6b417c5397ef78185638dd06b90d4de99a4b57645a12d51bb48715aff663ae4f1c
7
- data.tar.gz: 126e0ebe86a1c640a4c75d41ffaad9e6ba6585b75aa3c0c6e27d10cca5de585f73812395bf011b1cedaf74933568aaa762f3e071333abc2cadd93e7ac32a9c0c
6
+ metadata.gz: ad7ecf818020effd32d3d8bf4efd2c87f1f3672dee5fbaf23970cd497bd89f031bbb4bb2803e483b5c32b16daf33c863e2b5317448ab0d0c601e99c1c1ff3efb
7
+ data.tar.gz: 16085e10575051841201d32398601aecd47c9134788b52e97555d0b5d9671f83d8660571dee7d11a1da45f4236a250d605e11dd596c52b2c83c51f21d036c196
data/Rakefile CHANGED
@@ -11,20 +11,6 @@ rescue Bundler::BundlerError => e
11
11
  end
12
12
  require 'rake'
13
13
 
14
- require 'jeweler'
15
- Jeweler::Tasks.new do |gem|
16
- # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
- gem.name = "knjrbfw"
18
- gem.homepage = "http://github.com/kaspernj/knjrbfw"
19
- gem.license = "MIT"
20
- gem.summary = %Q{A framework with lots of stuff for Ruby.}
21
- gem.description = %Q{Including stuff for HTTP, SSH and much more.}
22
- gem.email = "k@spernj.org"
23
- gem.authors = ["Kasper Johansen"]
24
- # dependencies defined in Gemfile
25
- end
26
- Jeweler::RubygemsDotOrgTasks.new
27
-
28
14
  require 'rspec/core'
29
15
  require 'rspec/core/rake_task'
30
16
  RSpec::Core::RakeTask.new(:spec) do |spec|
data/lib/knj/autoload.rb CHANGED
@@ -63,7 +63,7 @@ else
63
63
  autoload :GetText, $knjpath + "autoload/gettext"
64
64
  autoload :Gtk, $knjpath + "autoload/gtk2"
65
65
  autoload :GladeXML, "libglade2"
66
-
66
+
67
67
  #this bugs?
68
68
  #autoload :Gdk, $knjpath + "autoload/gtk2"
69
69
  end
@@ -90,4 +90,3 @@ autoload :Cinch, $knjpath + "autoload/cinch"
90
90
  autoload :Facebooker, $knjpath + "autoload/facebooker"
91
91
  autoload :Tsafe, "tsafe"
92
92
  autoload :Wref, $knjpath + "autoload/wref"
93
- autoload :Wref_map, $knjpath + "autoload/wref"
@@ -2,21 +2,21 @@ Knj.gem_require(:wref)
2
2
 
3
3
  #Containing various helper methods for Gtk2-windows.
4
4
  class Knj::Gtk2::Window
5
- @@uniques = Wref_map.new
6
-
5
+ @@uniques = Wref::Map.new
6
+
7
7
  #Used to make a window-instance unique. If it already exists when unique! is called, then it will pass focus to the existing window instead of yielding the block, which should contain code to create the window.
8
8
  #===Examples
9
9
  #This should only create a single window.
10
10
  # Knj::Gtk2::Window.unique!("my_window") do
11
11
  # Gtk::Window.new
12
12
  # end
13
- #
13
+ #
14
14
  # Knj::Gtk2::Window.unique!("my_window") do
15
15
  # Gtk::Window.new
16
16
  # end
17
17
  def self.unique!(id)
18
18
  instance = @@uniques.get!(id)
19
-
19
+
20
20
  if instance and !instance.gui["window"].destroyed?
21
21
  instance.gui["window"].present
22
22
  else
@@ -24,18 +24,18 @@ class Knj::Gtk2::Window
24
24
  @@uniques[id] = obj
25
25
  end
26
26
  end
27
-
27
+
28
28
  #Returns the object if it hasnt been destroyed.
29
29
  #===Examples
30
30
  # Knj::Gtk2::Window.get("my_window") #=> nil
31
31
  # Knj::Gtk2::Window.get("my_window") #=> Gtk::Builder-object
32
32
  def self.get(id)
33
33
  instance = @@uniques.get!(id)
34
-
34
+
35
35
  if instance and !instance.gui["window"].destroyed?
36
36
  return instance
37
37
  end
38
-
38
+
39
39
  return nil
40
40
  end
41
41
  end
data/lib/knj/image.rb CHANGED
@@ -4,114 +4,125 @@ class Knj::Image
4
4
  #===Examples
5
5
  # img = Magick::Image.read(path_str)
6
6
  # Knj::Image.rounded_corners(
7
- # :img => img,
8
- # :radius => 25,
9
- # :border => 1,
10
- # :border_color => "#000000"
7
+ # img: img,
8
+ # radius: 25,
9
+ # border: 1,
10
+ # border_color: "#000000"
11
11
  # )
12
12
  def self.rounded_corners(args)
13
- raise "No or invalid ':img' given: '#{args}'." if !args[:img]
13
+ raise "No or invalid ':img' given: '#{args}'." unless args[:img]
14
14
  raise "No or invalid ':radius' given: '#{args}'." if !args[:radius].respond_to?(:to_i) || args[:radius].to_i <= 0
15
-
15
+
16
16
  pic = args[:img]
17
17
  raise "Format '#{pic.format}' does not support transparency." if pic.format == "JPEG"
18
-
18
+
19
19
  r = args[:radius].to_i
20
20
  r_half = r / 2
21
21
  r2 = r * r
22
22
  d = r * 2
23
-
23
+
24
24
  center_x = r - 1
25
25
  center_y = 1
26
-
26
+
27
27
  coords = {}
28
28
  0.upto(r) do |x|
29
29
  y = center_y + ::Math.sqrt(r2 - ((x - center_x) * (x - center_x)))
30
30
  coords[x] = y.to_i
31
31
  end
32
-
32
+
33
33
  if args[:border]
34
34
  draw = ::Magick::Draw.new
35
35
  draw.stroke(args[:border_color])
36
36
  draw.stroke_width(1)
37
-
37
+
38
38
  0.upto(args[:border] - 1) do |x|
39
39
  draw.line(x, 0, x, pic.rows)
40
40
  draw.line(pic.columns-x-1, 0, pic.columns-x-1, pic.rows)
41
-
41
+
42
42
  draw.line(0, x, pic.columns, x)
43
43
  draw.line(0, pic.rows-x-1, pic.columns, pic.rows-x-1)
44
44
  end
45
-
45
+
46
46
  draw.draw(pic)
47
47
  end
48
-
48
+
49
49
  borders = [] if args[:border]
50
-
50
+
51
51
  1.upto(4) do |count|
52
52
  r.times do |x|
53
53
  border_from = nil
54
54
  border_to = nil
55
55
  border_mode = nil
56
-
56
+
57
57
  case count
58
58
  when 1
59
59
  x_from = x
60
-
60
+
61
61
  y_from = 0
62
62
  y_to = r - coords[x]
63
-
64
- if borders and x > 0 and x < r_half
63
+
64
+ if borders && x > 0 && x < r_half
65
65
  border_from = y_to
66
66
  border_to = r - coords[x - 1]
67
67
  border_to = 1 if border_to < 1
68
-
68
+
69
69
  #top left
70
- borders << {:x => x_from, :yf => border_from, :yt => border_to}
71
- borders << {:y => x_from, :xf => border_from, :xt => border_to}
72
-
70
+ borders << {x: x_from, yf: border_from, yt: border_to}
71
+ borders << {y: x_from, xf: border_from, xt: border_to}
72
+
73
73
  #top right
74
- borders << {:x => pic.columns - x - 1, :yf => border_from, :yt => border_to}
75
- borders << {:y => x_from, :xf => pic.columns - border_to, :xt => pic.columns - border_from}
76
-
74
+ borders << {x: pic.columns - x - 1, yf: border_from, yt: border_to}
75
+ borders << {y: x_from, xf: pic.columns - border_to, xt: pic.columns - border_from}
76
+
77
77
  #bottom left
78
- borders << {:x => x_from, :yf => pic.rows - border_to, :yt => pic.rows - border_from}
79
- borders << {:y => pic.rows - x - 1, :xf => border_from, :xt => border_to}
80
-
78
+ borders << {x: x_from, yf: pic.rows - border_to, yt: pic.rows - border_from}
79
+ borders << {y: pic.rows - x - 1, xf: border_from, xt: border_to}
80
+
81
81
  #bottom right
82
- borders << {:x => pic.columns - x - 1, :yf => pic.rows - border_to, :yt => pic.rows - border_from}
83
- borders << {:y => pic.rows - x - 1, :xf => pic.columns - border_to, :xt => pic.columns - border_from}
82
+ borders << {x: pic.columns - x - 1, yf: pic.rows - border_to, yt: pic.rows - border_from}
83
+ borders << {y: pic.rows - x - 1, xf: pic.columns - border_to, xt: pic.columns - border_from}
84
84
  end
85
85
  when 2
86
86
  x_from = pic.columns - r + x
87
-
87
+
88
88
  y_from = 0
89
89
  y_to = r - coords[r - x - 1]
90
90
  when 3
91
91
  x_from = x
92
-
92
+
93
93
  y_from = pic.rows - r + coords[x]
94
94
  y_to = pic.rows - y_from
95
95
  when 4
96
96
  x_from = pic.columns - r + x
97
-
97
+
98
98
  y_from = pic.rows - r + coords[r - x - 1]
99
99
  y_to = pic.rows - y_from
100
100
  end
101
-
101
+
102
102
  next if y_to <= 0
103
-
104
- pixels = pic.get_pixels(x_from, y_from, 1, y_to)
105
- pixels.each do |pixel|
106
- pixel.opacity = ::Magick::TransparentOpacity
103
+
104
+ if RUBY_ENGINE == "jruby"
105
+ # Hack around missing method in rmagick4j Image#get_pixels. It will be black :-(
106
+ pixels = []
107
+ y_to.times do |count|
108
+ pixel = Magick::Pixel.new(0, 0, 0, 255)
109
+ pixels << pixel
110
+ end
111
+
112
+ pic.store_pixels(x_from, y_from, 1, y_to, pixels)
113
+ else
114
+ pixels = pic.get_pixels(x_from, y_from, 1, y_to)
115
+ pixels.each do |pixel|
116
+ pixel.alpha = ::Magick::QuantumRange
117
+ end
118
+ pic.store_pixels(x_from, y_from, 1, y_to, pixels)
107
119
  end
108
- pic.store_pixels(x_from, y_from, 1, y_to, pixels)
109
120
  end
110
121
  end
111
-
122
+
112
123
  if borders
113
124
  color = args[:border_color]
114
-
125
+
115
126
  borders.each do |border|
116
127
  if border.key?(:x)
117
128
  count_from = border[:yf]
@@ -120,18 +131,18 @@ class Knj::Image
120
131
  count_from = border[:xf]
121
132
  count_to = border[:xt]
122
133
  end
123
-
134
+
124
135
  count_from.upto(count_to - 1) do |coord|
125
- if RUBY_ENGINE == "jruby" and color[0, 1] == "#"
136
+ if RUBY_ENGINE == "jruby" && color[0, 1] == "#"
126
137
  r = color[1, 2].hex
127
138
  b = color[3, 2].hex
128
139
  g = color[5, 2].hex
129
-
140
+
130
141
  pixel = ::Magick::Pixel.new(r, b, g)
131
142
  else
132
143
  pixel = ::Magick::Pixel.from_color(color)
133
144
  end
134
-
145
+
135
146
  if border.key?(:x)
136
147
  if RUBY_ENGINE == "jruby"
137
148
  pic.store_pixels(border[:x], coord, 1, 1, [pixel])
@@ -148,21 +159,19 @@ class Knj::Image
148
159
  end
149
160
  end
150
161
  end
151
-
152
- pic.matte = true
153
162
  end
154
-
163
+
155
164
  #Returns the width relative to the height.
156
165
  #===Examples
157
166
  # Knj::Image.width_for_height(640, 480, 400) #=> 533
158
167
  def self.width_for_height(orig_width, orig_height, new_height)
159
168
  return (orig_width.to_f / (orig_height.to_f / new_height.to_f)).to_i
160
169
  end
161
-
170
+
162
171
  #Returns the height relative to the width.
163
172
  #===Examples
164
173
  # Knj::Image.height_for_width(640, 480, 533) #=> 399
165
174
  def self.height_for_width(orig_width, orig_height, new_width)
166
175
  return (orig_height.to_f / (orig_width.to_f / new_width.to_f)).to_i
167
176
  end
168
- end
177
+ end
@@ -7,11 +7,11 @@ begin
7
7
  options = {}
8
8
  OptionParser.new do |opts|
9
9
  opts.banner = "Usage: example.rb [options]"
10
-
10
+
11
11
  opts.on("-f PHPFILE", "--file", "The PHP-file you want help to convert.") do |f|
12
12
  options[:file] = f
13
13
  end
14
-
14
+
15
15
  opts.on("-t", "--tags-remove", "Removes the PHP-tags completely.") do |t|
16
16
  options[:tags] = false
17
17
  end
@@ -37,15 +37,8 @@ cont.gsub!(/\A#!\/usr\/bin\/env\s+php5/, "!#/usr/bin/env ruby1.9.1")
37
37
  #Replace class extends.
38
38
  cont.scan(/(class\s+(.+?)\s+extends\s+(.+?){)/) do |match|
39
39
  rb_classname = "#{match[1][0..0].upcase}#{match[1][1..999]}"
40
-
41
- if match[2] == "knjdb_row"
42
- extends = "Knj::Datarow"
43
- else
44
- extends = "#{match[2][0..0].upcase}#{match[2][1..999]}"
45
- end
46
-
40
+ extends = "#{match[2][0..0].upcase}#{match[2][1..999]}"
47
41
  rb_str = "class #{rb_classname} < #{extends}"
48
-
49
42
  cont = cont.gsub(match[0], rb_str)
50
43
  end
51
44
 
@@ -54,7 +47,7 @@ end
54
47
  cont.scan(/(class\s+(.+?)\s*{)/) do |match|
55
48
  rb_classname = "#{match[1][0..0].upcase}#{match[1][1..999]}"
56
49
  rb_str = "class #{rb_classname}"
57
-
50
+
58
51
  cont = cont.gsub(match[0], rb_str)
59
52
  end
60
53
 
@@ -68,7 +61,7 @@ cont.scan(/(static\s+function\s+(.+?)\((.*?)\)\s*{)/) do |match|
68
61
  else
69
62
  func_name = match[1]
70
63
  end
71
-
64
+
72
65
  rb_str = "def self.#{func_name}(#{match[2]})"
73
66
  cont = cont.gsub(match[0], rb_str)
74
67
  end
@@ -101,7 +94,7 @@ end
101
94
  cont.scan(/((\s+?)}\s*catch\s*\(\s*(#{regexes["class"]})\s+\$(#{regexes["var"]})\s*\)\s*{(\s+))/) do |match|
102
95
  classname = "#{match[2][0..0].upcase}#{match[2][1..999]}"
103
96
  classname = "Errno::ENOENT" if classname == "Knjdb_rownotfound_exception"
104
-
97
+
105
98
  rb_str = "#{match[1]}rescue #{classname} => #{match[3]}#{match[4]}"
106
99
  cont = cont.gsub(match[0], rb_str)
107
100
  end
@@ -111,7 +104,7 @@ end
111
104
  cont.scan(/((\s+?)require_once\s+\"(.+)\"\s*;(\s+?))/) do |match|
112
105
  filename = match[2]
113
106
  filename.gsub!(/\.php$/, ".rb")
114
-
107
+
115
108
  rb_str = "#{match[1]}require \"#{filename}\"#{match[3]}"
116
109
  cont = cont.gsub(match[0], rb_str)
117
110
  end
@@ -123,7 +116,7 @@ cont.scan(/(function\s(.+?)\((.*?)\))/) do |match|
123
116
  def_args.scan(/(([A-z]+)\s+\$(#{regexes["var"]}))/) do |match_arg|
124
117
  def_args = def_args.gsub(match_arg[0], "#{match_arg[2]}")
125
118
  end
126
-
119
+
127
120
  rb_str = "def #{match[1]}(#{def_args})"
128
121
  cont = cont.gsub(match[0], rb_str)
129
122
  end
@@ -267,11 +260,11 @@ end
267
260
  #Replace multi-line comments.
268
261
  cont.scan(/((\s+|<\?)\/\*([\s\S]+?)\*\/)/) do |match|
269
262
  rb_str = "\n=begin\n#{match[2]}\n=end\n"
270
-
263
+
271
264
  if match[1] == "<?"
272
265
  rb_str = "<%#{rb_str}"
273
266
  end
274
-
267
+
275
268
  cont = cont.gsub(match[0], rb_str)
276
269
  end
277
270
 
@@ -300,14 +293,14 @@ end
300
293
  #Replace variable-names.
301
294
  cont.scan(/(([^%\d])(\$(#{regexes["var"]})))/) do |match|
302
295
  vname = match[3]
303
-
296
+
304
297
  if vname[-1..-1] == "["
305
298
  vname = vname[0..-2]
306
299
  match[0] = match[0][0..-2]
307
300
  match[2] = match[2][0..-2]
308
301
  match[3] = match[3][0..-2]
309
302
  end
310
-
303
+
311
304
  if vname == "this"
312
305
  rb_varname = "self"
313
306
  elsif global_vars.key?(vname)
@@ -315,7 +308,7 @@ cont.scan(/(([^%\d])(\$(#{regexes["var"]})))/) do |match|
315
308
  else
316
309
  rb_varname = "#{vname}"
317
310
  end
318
-
311
+
319
312
  cont = cont.gsub(match[2], rb_varname)
320
313
  end
321
314
 
data/lib/knj/unix_proc.rb CHANGED
@@ -4,47 +4,47 @@ require "wref" if !Kernel.const_defined?(:Wref)
4
4
  #This class handels various stuff regarding Unix-processes.
5
5
  class Knj::Unix_proc
6
6
  attr_reader :data
7
-
8
- PROCS = Wref_map.new
7
+
8
+ PROCS = Wref::Map.new
9
9
  MUTEX = Mutex.new
10
-
10
+
11
11
  #Spawns a process if it doesnt already exist in the wrap-map.
12
12
  def self.spawn(data)
13
13
  pid = data["pid"].to_i
14
-
14
+
15
15
  begin
16
- proc_ele = PROCS[pid]
16
+ proc_ele = PROCS.get!(pid)
17
17
  proc_ele.update_data(data)
18
18
  rescue Wref::Recycled
19
19
  proc_ele = Knj::Unix_proc.new(data)
20
20
  PROCS[pid] = proc_ele
21
21
  end
22
-
22
+
23
23
  return proc_ele
24
24
  end
25
-
25
+
26
26
  #Returns an array with (or yields if block given) Unix_proc. Hash-arguments as 'grep'.
27
27
  def self.list(args = {})
28
28
  cmdstr = "ps aux"
29
29
  grepstr = ""
30
-
30
+
31
31
  if args["grep"]
32
32
  grepstr = "grep #{args["grep"]}" #used for ignoring the grep-process later.
33
33
  cmdstr << " | grep #{Knj::Strings.unixsafe(args["grep"])}"
34
34
  end
35
-
35
+
36
36
  MUTEX.synchronize do
37
37
  ret = [] unless block_given?
38
-
38
+
39
39
  if args["psaux_str"]
40
40
  res = args["psaux_str"]
41
41
  else
42
42
  res = Knj::Os.shellcmd(cmdstr)
43
43
  end
44
-
44
+
45
45
  res.scan(/^(\S+)\s+([0-9]+)\s+([0-9.]+)\s+([0-9.]+)\s+\S+\s+\S+\s+\S+\s+\S+\s+\S+\s+\S+ (.+)($|\n)/) do |match|
46
46
  pid = match[1]
47
-
47
+
48
48
  data = {
49
49
  "user" => match[0],
50
50
  "pid" => pid,
@@ -53,10 +53,10 @@ class Knj::Unix_proc
53
53
  "cmd" => match[4],
54
54
  "app" => File.basename(match[4])
55
55
  }
56
-
56
+
57
57
  next if (!args.key?("ignore_self") or args["ignore_self"]) and match[1].to_i == $$.to_i
58
58
  next if grepstr.length > 0 and match[4].index(grepstr) != nil #dont return current process.
59
-
59
+
60
60
  if args.key?("pids")
61
61
  found = false
62
62
  args["pids"].each do |pid_given|
@@ -65,15 +65,15 @@ class Knj::Unix_proc
65
65
  break
66
66
  end
67
67
  end
68
-
68
+
69
69
  next if !found
70
70
  end
71
-
71
+
72
72
  if args["yield_data"]
73
73
  yield(data)
74
74
  else
75
75
  proc_obj = Knj::Unix_proc.spawn(data)
76
-
76
+
77
77
  if block_given?
78
78
  yield(proc_obj)
79
79
  else
@@ -81,9 +81,9 @@ class Knj::Unix_proc
81
81
  end
82
82
  end
83
83
  end
84
-
84
+
85
85
  PROCS.clean
86
-
86
+
87
87
  if block_given?
88
88
  return nil
89
89
  else
@@ -91,12 +91,12 @@ class Knj::Unix_proc
91
91
  end
92
92
  end
93
93
  end
94
-
94
+
95
95
  #Returns the "Knj::Unix_proc" for the current process.
96
96
  def self.find_self
97
97
  procs = Knj::Unix_proc.list("ignore_self" => false)
98
98
  pid_find = Process.pid
99
-
99
+
100
100
  proc_find = false
101
101
  procs.each do |proc_ele|
102
102
  if proc_ele["pid"].to_i == pid_find.to_i
@@ -104,10 +104,10 @@ class Knj::Unix_proc
104
104
  break
105
105
  end
106
106
  end
107
-
107
+
108
108
  return proc_find
109
109
  end
110
-
110
+
111
111
  #Return true if the given PID is running.
112
112
  def self.pid_running?(pid)
113
113
  begin
@@ -117,65 +117,65 @@ class Knj::Unix_proc
117
117
  return false
118
118
  end
119
119
  end
120
-
120
+
121
121
  #Initializes various data for a Unix_proc-object. This should not be called manually but through "Unix_proc.list".
122
122
  def initialize(data)
123
123
  @data = data
124
124
  end
125
-
125
+
126
126
  #Updates the data. This should not be called manually, but is exposed because of various code in "Unix_proc.list".
127
127
  def update_data(data)
128
128
  @data = data
129
129
  end
130
-
130
+
131
131
  #Returns the PID of the process.
132
132
  def pid
133
133
  return @data["pid"].to_i
134
134
  end
135
-
135
+
136
136
  #Returns a key from the data or raises an error.
137
137
  def [](key)
138
138
  raise "No such data: #{key}" if !@data.key?(key)
139
139
  return @data[key]
140
140
  end
141
-
141
+
142
142
  #Kills the process.
143
143
  def kill
144
144
  Process.kill("TERM", @data["pid"].to_i)
145
145
  end
146
-
146
+
147
147
  #Kills the process with 9.
148
148
  def kill!
149
149
  Process.kill(9, @data["pid"].to_i)
150
150
  end
151
-
151
+
152
152
  #Hash-compatible.
153
153
  def to_h
154
154
  return @data.clone
155
155
  end
156
-
156
+
157
157
  #Tries to kill the process gently, waits a couple of secs to check if the process is actually dead, then sends -9 kill signals.
158
158
  def kill_ensure(args = {})
159
159
  begin
160
160
  self.kill
161
161
  sleep 0.1
162
162
  return nil if !self.alive?
163
-
163
+
164
164
  args[:sleep] = 2 if !args.key(:sleep)
165
-
165
+
166
166
  0.upto(5) do
167
167
  sleep args[:sleep]
168
168
  self.kill!
169
169
  sleep 0.1
170
170
  return nil if !self.alive?
171
171
  end
172
-
172
+
173
173
  raise "Could not kill the process."
174
174
  rescue Errno::ESRCH
175
175
  return nil
176
176
  end
177
177
  end
178
-
178
+
179
179
  #Returns true if the process is still alive.
180
180
  def alive?
181
181
  return Knj::Unix_proc.pid_running?(@data["pid"].to_i)