knjrbfw 0.0.62 → 0.0.63

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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.62
1
+ 0.0.63
data/knjrbfw.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{knjrbfw}
8
- s.version = "0.0.62"
8
+ s.version = "0.0.63"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Kasper Johansen"]
12
- s.date = %q{2012-07-14}
12
+ s.date = %q{2012-07-16}
13
13
  s.description = %q{Including stuff for HTTP, SSH and much more.}
14
14
  s.email = %q{k@spernj.org}
15
15
  s.extra_rdoc_files = [
data/lib/knj/gtk2_tv.rb CHANGED
@@ -166,6 +166,22 @@ module Knj::Gtk2::Tv
166
166
 
167
167
  renderer = args[:renderers][col_no]
168
168
 
169
+ if args[:on_edit]
170
+ renderer.signal_connect("editing-started") do |renderer, row_no, path|
171
+ iter = args[:tv].model.get_iter(path)
172
+ id = args[:tv].model.get_value(iter, args[:id_col])
173
+ model_obj = args[:ob].get(args[:model_class], id)
174
+
175
+ args[:on_edit].call(:renderer => renderer, :row_no => row_no, :path => path, :args => args, :model => model_obj, :col_no => col_no, :col_data => col_data)
176
+ end
177
+ end
178
+
179
+ if args[:on_edit_done]
180
+ renderer.signal_connect("editing-canceled") do |renderer|
181
+ args[:on_edit_done].call(:renderer => renderer, :done_mode => :canceled, :args => args, :col_no => col_no, :col_data => col_data)
182
+ end
183
+ end
184
+
169
185
  if renderer.is_a?(Gtk::CellRendererText)
170
186
  renderer.editable = true
171
187
  renderer.signal_connect("edited") do |renderer, row_no, value|
@@ -175,6 +191,10 @@ module Knj::Gtk2::Tv
175
191
  cancel = false
176
192
  callback_hash = {:args => args, :value => value, :model => model_obj, :col_no => col_no, :col_data => col_data}
177
193
 
194
+ if args[:on_edit_done]
195
+ args[:on_edit_done].call(:renderer => renderer, :row_no => row_no, :done_mode => :canceled, :args => args, :model => model_obj, :col_no => col_no, :col_data => col_data)
196
+ end
197
+
178
198
  if col_data[:value_callback]
179
199
  begin
180
200
  value = col_data[:value_callback].call(callback_hash)
@@ -7,15 +7,18 @@ class Knj::SSHRobot
7
7
  @args[:port] = 22 if !@args.key?(:port)
8
8
  end
9
9
 
10
+ #Spawns a session if it hasnt already been spawned and returns it.
10
11
  def session
11
12
  @session = self.session_spawn if !@session
12
13
  return @session
13
14
  end
14
15
 
16
+ #Spawns a new net-ssh-instance.
15
17
  def session_spawn
16
18
  return Net::SSH.start(@args[:host], @args[:user], :password => @args[:passwd], :port => @args[:port].to_i)
17
19
  end
18
20
 
21
+ #Returns the a shell-session.
19
22
  def shell
20
23
  return self.session.shell.sync
21
24
  end
@@ -24,10 +27,18 @@ class Knj::SSHRobot
24
27
  @sftp = Net::SFTP.start(@args[:host], @args[:user], @args[:passwd], :port => @args[:port].to_i)
25
28
  end
26
29
 
27
- def exec(command)
28
- return self.session.exec!(command)
30
+ #Executes a command.
31
+ def exec(command, &block)
32
+ if block
33
+ return self.session.exec!(command) do |channel, stream, line|
34
+ block.call(:channel => channel, :stream => stream, :line => line)
35
+ end
36
+ else
37
+ return self.session.exec!(command)
38
+ end
29
39
  end
30
40
 
41
+ #Executes a command as "root" via "sudo". Accepts the "sudo"-password and a command.
31
42
  def sudo_exec(sudo_passwd, command)
32
43
  result = ""
33
44
 
@@ -46,7 +57,6 @@ class Knj::SSHRobot
46
57
  end
47
58
 
48
59
  self.session.loop
49
-
50
60
  return result
51
61
  end
52
62
 
data/lib/knj/unix_proc.rb CHANGED
@@ -119,6 +119,11 @@ class Knj::Unix_proc
119
119
  @data = data
120
120
  end
121
121
 
122
+ #Returns the PID of the process.
123
+ def pid
124
+ return @data["pid"].to_i
125
+ end
126
+
122
127
  #Returns a key from the data or raises an error.
123
128
  def [](key)
124
129
  raise "No such data: #{key}" if !@data.key?(key)
@@ -134,4 +139,31 @@ class Knj::Unix_proc
134
139
  def kill!
135
140
  Process.kill(9, @data["pid"].to_i)
136
141
  end
142
+
143
+ #Tries to kill the process gently, waits a couple of secs to check if the process is actually dead, then sends -9 kill signals.
144
+ def kill_ensure(args = {})
145
+ begin
146
+ self.kill
147
+ sleep 0.1
148
+ return nil if !self.alive?
149
+
150
+ args[:sleep] = 2 if !args.key(:sleep)
151
+
152
+ 0.upto(5) do
153
+ sleep args[:sleep]
154
+ self.kill!
155
+ sleep 0.1
156
+ return nil if !self.alive?
157
+ end
158
+
159
+ raise "Could not kill the process."
160
+ rescue Errno::ESRCH
161
+ return nil
162
+ end
163
+ end
164
+
165
+ #Returns true if the process is still alive.
166
+ def alive?
167
+ return Knj::Unix_proc.pid_running?(@data["pid"].to_i)
168
+ end
137
169
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: knjrbfw
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.62
5
+ version: 0.0.63
6
6
  platform: ruby
7
7
  authors:
8
8
  - Kasper Johansen
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2012-07-14 00:00:00 +02:00
13
+ date: 2012-07-16 00:00:00 +02:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -398,7 +398,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
398
398
  requirements:
399
399
  - - ">="
400
400
  - !ruby/object:Gem::Version
401
- hash: -733667267458829383
401
+ hash: 269497940070767822
402
402
  segments:
403
403
  - 0
404
404
  version: "0"