knjrbfw 0.0.41 → 0.0.42
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/knjrbfw.gemspec +3 -2
- data/lib/knj/eruby.rb +4 -4
- data/lib/knj/gtk2_cb.rb +19 -0
- data/lib/knj/gtk2_tv.rb +67 -10
- data/lib/knj/gtk2_window.rb +15 -0
- data/lib/knj/http2.rb +3 -4
- data/lib/knj/knjdb/drivers/mysql/knjdb_mysql.rb +1 -4
- data/lib/knj/knjdb/drivers/sqlite3/knjdb_sqlite3_columns.rb +4 -4
- data/lib/knj/knjdb/dump.rb +2 -2
- data/lib/knj/knjdb/libknjdb.rb +5 -3
- data/lib/knj/knjdb/revision.rb +5 -0
- data/lib/knj/memory_analyzer.rb +1 -1
- data/lib/knj/objects.rb +2 -2
- data/lib/knj/php.rb +18 -17
- data/lib/knj/process.rb +5 -5
- data/lib/knj/rhodes/rhodes.rb +2 -1
- data/lib/knj/sshrobot/sshrobot.rb +1 -1
- data/lib/knj/strings.rb +28 -0
- data/lib/knj/thread.rb +1 -1
- data/lib/knj/thread2.rb +1 -1
- data/lib/knj/threadpool.rb +0 -7
- data/lib/knj/win_tightvnc.rb +2 -2
- data/spec/strings_spec.rb +6 -0
- metadata +4 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.42
|
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.
|
8
|
+
s.version = "0.0.42"
|
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-
|
12
|
+
s.date = %q{2012-06-08}
|
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 = [
|
@@ -94,6 +94,7 @@ Gem::Specification.new do |s|
|
|
94
94
|
"lib/knj/gtk2_menu.rb",
|
95
95
|
"lib/knj/gtk2_statuswindow.rb",
|
96
96
|
"lib/knj/gtk2_tv.rb",
|
97
|
+
"lib/knj/gtk2_window.rb",
|
97
98
|
"lib/knj/hash_methods.rb",
|
98
99
|
"lib/knj/http.rb",
|
99
100
|
"lib/knj/http2.rb",
|
data/lib/knj/eruby.rb
CHANGED
@@ -85,7 +85,7 @@ class Knj::Eruby
|
|
85
85
|
end
|
86
86
|
rescue SystemExit
|
87
87
|
#do nothing.
|
88
|
-
rescue
|
88
|
+
rescue => e
|
89
89
|
@error = true
|
90
90
|
self.handle_error(e)
|
91
91
|
end
|
@@ -212,7 +212,7 @@ class Knj::Eruby
|
|
212
212
|
self.printcont(tmp_out, args)
|
213
213
|
rescue SystemExit => e
|
214
214
|
self.printcont(tmp_out, args)
|
215
|
-
rescue
|
215
|
+
rescue => e
|
216
216
|
self.handle_error(e)
|
217
217
|
self.printcont(tmp_out, args)
|
218
218
|
end
|
@@ -227,8 +227,8 @@ class Knj::Eruby
|
|
227
227
|
end
|
228
228
|
end
|
229
229
|
rescue SystemExit => e
|
230
|
-
|
231
|
-
rescue
|
230
|
+
raise e
|
231
|
+
rescue => e
|
232
232
|
#An error occurred while trying to run the on-error-block - show this as an normal error.
|
233
233
|
print "\n\n<pre>\n\n"
|
234
234
|
print "<b>#{Knj::Web.html(e.class.name)}: #{Knj::Web.html(e.message)}</b>\n\n"
|
data/lib/knj/gtk2_cb.rb
CHANGED
@@ -33,6 +33,18 @@ class Gtk::ComboBox
|
|
33
33
|
}
|
34
34
|
end
|
35
35
|
end
|
36
|
+
elsif items.is_a?(Hash)
|
37
|
+
@knj[:type] = :hash
|
38
|
+
|
39
|
+
items.each do |key, val|
|
40
|
+
iter = ls.append
|
41
|
+
iter[0] = val
|
42
|
+
|
43
|
+
@knj[:items] << {
|
44
|
+
:iter => iter,
|
45
|
+
:object => key
|
46
|
+
}
|
47
|
+
end
|
36
48
|
else
|
37
49
|
raise "Unsupported type: '#{items.class.name}'."
|
38
50
|
end
|
@@ -68,6 +80,13 @@ class Gtk::ComboBox
|
|
68
80
|
return nil
|
69
81
|
end
|
70
82
|
end
|
83
|
+
elsif @knj[:type] == :hash
|
84
|
+
@knj[:items].each do |item|
|
85
|
+
if item[:object] == actob
|
86
|
+
self.active_iter = item[:iter]
|
87
|
+
return nil
|
88
|
+
end
|
89
|
+
end
|
71
90
|
else
|
72
91
|
self.model.each do |model, path, iter|
|
73
92
|
text = self.model.get_value(iter, 0)
|
data/lib/knj/gtk2_tv.rb
CHANGED
@@ -1,21 +1,64 @@
|
|
1
1
|
module Knj::Gtk2::Tv
|
2
2
|
def self.init(tv, columns)
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
ret = {
|
4
|
+
:renderers => []
|
5
|
+
}
|
6
|
+
|
7
|
+
model_args = []
|
8
|
+
columns.each do |args|
|
9
|
+
if args.is_a?(String)
|
10
|
+
args = {:type => :string, :title => args}
|
11
|
+
end
|
12
|
+
|
13
|
+
if args[:type] == :string
|
14
|
+
model_args << String
|
15
|
+
elsif args[:type] == :toggle
|
16
|
+
model_args << Integer
|
17
|
+
elsif args[:type] == :combo
|
18
|
+
model_args << String
|
19
|
+
else
|
20
|
+
raise "Invalid type: '#{args[:type]}'."
|
21
|
+
end
|
6
22
|
end
|
7
23
|
|
8
|
-
list_store = Gtk::ListStore.new(*
|
24
|
+
list_store = Gtk::ListStore.new(*model_args)
|
9
25
|
tv.model = list_store
|
10
26
|
|
11
27
|
count = 0
|
12
|
-
columns.each do |
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
28
|
+
columns.each do |args|
|
29
|
+
if args.is_a?(String)
|
30
|
+
args = {:type => :string, :title => args}
|
31
|
+
end
|
32
|
+
|
33
|
+
if args[:type] == :string
|
34
|
+
renderer = Gtk::CellRendererText.new
|
35
|
+
col = Gtk::TreeViewColumn.new(args[:title], renderer, :text => count)
|
36
|
+
col.resizable = true
|
37
|
+
tv.append_column(col)
|
38
|
+
elsif args[:type] == :toggle
|
39
|
+
renderer = Gtk::CellRendererToggle.new
|
40
|
+
col = Gtk::TreeViewColumn.new(args[:title], renderer, :active => count)
|
41
|
+
tv.append_column(col)
|
42
|
+
elsif args[:type] == :combo
|
43
|
+
renderer = Gtk::CellRendererCombo.new
|
44
|
+
renderer.text_column = 0
|
45
|
+
|
46
|
+
col = Gtk::TreeViewColumn.new(args[:title])
|
47
|
+
col.pack_start(renderer, false)
|
48
|
+
col.add_attribute(renderer, :text, count)
|
49
|
+
|
50
|
+
renderer.model = args[:model] if args.key?(:model)
|
51
|
+
tv.append_column(col)
|
52
|
+
else
|
53
|
+
raise "Invalid type: '#{args[:type]}'."
|
54
|
+
end
|
55
|
+
|
17
56
|
count += 1
|
57
|
+
|
58
|
+
ret[:renderers] << renderer
|
18
59
|
end
|
60
|
+
|
61
|
+
return ret
|
19
62
|
end
|
20
63
|
|
21
64
|
def self.append(tv, data)
|
@@ -23,9 +66,23 @@ module Knj::Gtk2::Tv
|
|
23
66
|
|
24
67
|
count = 0
|
25
68
|
data.each do |value|
|
26
|
-
|
69
|
+
col = tv.columns[count]
|
70
|
+
renderer = col.cell_renderers.first
|
71
|
+
|
72
|
+
if renderer.is_a?(Gtk::CellRendererText)
|
73
|
+
iter[count] = value.to_s
|
74
|
+
elsif renderer.is_a?(Gtk::CellRendererToggle)
|
75
|
+
iter[count] = Knj::Strings.yn_str(value, 1, 0)
|
76
|
+
elsif renderer.is_a?(Gtk::CellRendererCombo)
|
77
|
+
iter[count] = value.to_s
|
78
|
+
else
|
79
|
+
raise "Unknown renderer: '#{renderer.class.name}'."
|
80
|
+
end
|
81
|
+
|
27
82
|
count += 1
|
28
83
|
end
|
84
|
+
|
85
|
+
return {:iter => iter}
|
29
86
|
end
|
30
87
|
|
31
88
|
def self.sel(tv)
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class Knj::Gtk2::Window
|
2
|
+
require "wref"
|
3
|
+
@@uniques = Wref_map.new
|
4
|
+
|
5
|
+
def self.unique!(id)
|
6
|
+
instance = @@uniques.get!(id)
|
7
|
+
|
8
|
+
if instance and !instance.gui["window"].destroyed?
|
9
|
+
instance.gui["window"].activate_focus
|
10
|
+
else
|
11
|
+
obj = yield
|
12
|
+
@@uniques[id] = obj
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/knj/http2.rb
CHANGED
@@ -126,14 +126,13 @@ class Knj::Http2
|
|
126
126
|
@sock.write(@nl)
|
127
127
|
|
128
128
|
res = @sock.gets
|
129
|
-
if res.to_s.downcase != "http/1.0 200 connection established#{@nl}"
|
130
|
-
raise res
|
131
|
-
end
|
129
|
+
raise res if res.to_s.downcase != "http/1.0 200 connection established#{@nl}"
|
132
130
|
|
133
131
|
res_empty = @sock.gets
|
134
132
|
raise "Empty res wasnt empty." if res_empty != @nl
|
135
133
|
else
|
136
|
-
|
134
|
+
print "Http2: Opening socket connection to '#{@args[:host]}:#{@args[:port]}'.\n" if @debug
|
135
|
+
@sock_plain = TCPSocket.new(@args[:host], @args[:port].to_i)
|
137
136
|
end
|
138
137
|
|
139
138
|
if @args[:ssl]
|
@@ -164,10 +164,7 @@ class KnjDB_mysql
|
|
164
164
|
sleep 0.5
|
165
165
|
self.reconnect
|
166
166
|
retry
|
167
|
-
elsif e.message == "This connection is still waiting for a result, try again once you have the result"
|
168
|
-
sleep 0.1
|
169
|
-
retry
|
170
|
-
elsif e.to_s.index("No operations allowed after connection closed") != nil
|
167
|
+
elsif e.to_s.index("No operations allowed after connection closed") != nil or e.message == "This connection is still waiting for a result, try again once you have the result"
|
171
168
|
self.reconnect
|
172
169
|
retry
|
173
170
|
end
|
@@ -10,7 +10,7 @@ class KnjDB_sqlite3::Columns
|
|
10
10
|
#Returns SQL for a knjdb-compatible hash.
|
11
11
|
def data_sql(data)
|
12
12
|
raise "No type given." if !data["type"]
|
13
|
-
type = data["type"]
|
13
|
+
type = data["type"].to_s
|
14
14
|
|
15
15
|
if type == "enum"
|
16
16
|
type = "varchar"
|
@@ -18,12 +18,13 @@ class KnjDB_sqlite3::Columns
|
|
18
18
|
end
|
19
19
|
|
20
20
|
data["maxlength"] = 255 if type == "varchar" and !data.key?("maxlength")
|
21
|
+
data["maxlength"] = 11 if type == "int" and !data.key?("maxlength") and !data["autoincr"] and !data["primarykey"]
|
21
22
|
type = "integer" if @args[:db].int_types.index(type) and (data["autoincr"] or data["primarykey"])
|
22
23
|
|
23
24
|
sql = "`#{data["name"]}` #{type}"
|
24
25
|
sql << "(#{data["maxlength"]})" if data["maxlength"] and !data["autoincr"]
|
25
|
-
sql << "(11)" if !data.key?("maxlength") and !data["autoincr"]
|
26
26
|
sql << " PRIMARY KEY" if data["primarykey"]
|
27
|
+
sql << " AUTOINCREMENT" if data["autoincr"]
|
27
28
|
sql << " NOT NULL" if !data["null"] and data.key?("null")
|
28
29
|
|
29
30
|
if data.key?("default_func")
|
@@ -134,8 +135,7 @@ class KnjDB_sqlite3::Columns::Column
|
|
134
135
|
|
135
136
|
#Returns true if the column is auto-increasing.
|
136
137
|
def autoincr?
|
137
|
-
return true if
|
138
|
-
return true if @args[:data][:pk].to_i >= 1
|
138
|
+
return true if @args[:data][:pk].to_i == 1 and @args[:data][:type].to_s == "integer"
|
139
139
|
return false
|
140
140
|
end
|
141
141
|
|
data/lib/knj/knjdb/dump.rb
CHANGED
@@ -26,7 +26,7 @@ class Knj::Db::Dump
|
|
26
26
|
if @args[:tables]
|
27
27
|
tables = @args[:tables]
|
28
28
|
else
|
29
|
-
tables = @args[:db].tables.list
|
29
|
+
tables = @args[:db].tables.list.values
|
30
30
|
end
|
31
31
|
|
32
32
|
if @on_status
|
@@ -38,7 +38,7 @@ class Knj::Db::Dump
|
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
-
tables.each do |
|
41
|
+
tables.each do |table_obj|
|
42
42
|
table_obj = @args[:db].tables[table_obj] if table_obj.is_a?(String) or table_obj.is_a?(Symbol)
|
43
43
|
|
44
44
|
#Figure out keys.
|
data/lib/knj/knjdb/libknjdb.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
-
|
2
|
-
require "
|
1
|
+
if !Kernel.const_defined?(:Wref)
|
2
|
+
require "rubygems"
|
3
|
+
require "wref"
|
4
|
+
end
|
3
5
|
|
4
6
|
#A wrapper of several possible database-types.
|
5
7
|
#
|
@@ -82,7 +84,7 @@ class Knj::Db
|
|
82
84
|
#===Examples
|
83
85
|
# driver_instance = db.spawn
|
84
86
|
def spawn
|
85
|
-
raise "No type given." if !@opts[:type]
|
87
|
+
raise "No type given (#{@opts.keys.join(",")})." if !@opts[:type]
|
86
88
|
|
87
89
|
fpaths = [
|
88
90
|
"drivers/#{@opts[:type]}/knjdb_#{@opts[:type]}.rb",
|
data/lib/knj/knjdb/revision.rb
CHANGED
@@ -100,6 +100,11 @@ class Knj::Db::Revision
|
|
100
100
|
dochange = true
|
101
101
|
end
|
102
102
|
|
103
|
+
if col_data.has_key?("autoincr") and col_obj.autoincr? != col_data["autoincr"]
|
104
|
+
print "Auto-increment mismatch for #{col_str}: #{col_data["autoincr"]}, #{col_obj.autoincr?}\n" if args["debug"]
|
105
|
+
dochange = true
|
106
|
+
end
|
107
|
+
|
103
108
|
if col_data.has_key?("maxlength") and col_obj.maxlength.to_s != col_data["maxlength"].to_s
|
104
109
|
print "Maxlength mismatch on #{col_str}: #{col_data["maxlength"]}, #{col_obj.maxlength}\n" if args["debug"]
|
105
110
|
dochange = true
|
data/lib/knj/memory_analyzer.rb
CHANGED
@@ -259,7 +259,7 @@ class Knj::Memory_analyzer
|
|
259
259
|
ObjectSpace.each_object(classobj) do |obj|
|
260
260
|
instances += 1
|
261
261
|
end
|
262
|
-
rescue
|
262
|
+
rescue => e
|
263
263
|
emsg = e.message.to_s
|
264
264
|
if emsg.index("no such file to load") != nil or emsg.index("class or module required") != nil or emsg.index("uninitialized constant") != nil
|
265
265
|
#return false
|
data/lib/knj/objects.rb
CHANGED
@@ -18,7 +18,7 @@ class Knj::Objects
|
|
18
18
|
@data = {}
|
19
19
|
@lock_require = Monitor.new
|
20
20
|
|
21
|
-
require "wref" if @args[:cache] == :weak
|
21
|
+
require "wref" if @args[:cache] == :weak and !Kernel.const_defined?(:Wref)
|
22
22
|
|
23
23
|
#Set up various events.
|
24
24
|
@events = Knj::Event_handler.new
|
@@ -497,7 +497,7 @@ class Knj::Objects
|
|
497
497
|
|
498
498
|
raise "Could not figure out which name-method to call?" if !objhtml
|
499
499
|
html << ">#{objhtml}</option>"
|
500
|
-
rescue
|
500
|
+
rescue => e
|
501
501
|
html << ">[#{object.class.name}: #{e.message}]</option>"
|
502
502
|
end
|
503
503
|
end
|
data/lib/knj/php.rb
CHANGED
@@ -38,14 +38,16 @@ module Knj::Php
|
|
38
38
|
supercl = argument.class.superclass
|
39
39
|
superstr = supercl.to_s if supercl
|
40
40
|
|
41
|
-
|
41
|
+
valids = ["Apache::Table", "CGI", "Hash", "Knj::Datarow", "Knj::Datarow_custom", "Knj::Db_row", "Knj::Hash_methods", "Knjappserver::Session_accessor", "SQLite3::ResultSet::HashWithTypes"]
|
42
|
+
|
43
|
+
if Knj::Strings.is_a?(argument, valids) or argument.respond_to?(:to_hash)
|
42
44
|
if argument.respond_to?(:to_hash)
|
43
45
|
argument_use = argument.to_hash
|
44
46
|
else
|
45
47
|
argument_use = argument
|
46
48
|
end
|
47
49
|
|
48
|
-
retstr << argument.class.
|
50
|
+
retstr << "#{argument.class.name}{\n"
|
49
51
|
argument_use.each do |pair|
|
50
52
|
i = 0
|
51
53
|
while(i < count)
|
@@ -71,7 +73,7 @@ module Knj::Php
|
|
71
73
|
|
72
74
|
retstr << "}\n"
|
73
75
|
elsif cstr == "Dictionary"
|
74
|
-
retstr << argument.class.
|
76
|
+
retstr << "#{argument.class.name}{\n"
|
75
77
|
argument.each do |key, val|
|
76
78
|
i = 0
|
77
79
|
while(i < count)
|
@@ -97,7 +99,7 @@ module Knj::Php
|
|
97
99
|
|
98
100
|
retstr << "}\n"
|
99
101
|
elsif argument.is_a?(MatchData) or argument.is_a?(Array) or cstr == "Array" or supercl.is_a?(Array)
|
100
|
-
retstr << argument.class.
|
102
|
+
retstr << "#{argument.class.name}{\n"
|
101
103
|
|
102
104
|
arr_count = 0
|
103
105
|
argument.to_a.each do |i|
|
@@ -403,7 +405,7 @@ module Knj::Php
|
|
403
405
|
if File.file?(filepath)
|
404
406
|
return true
|
405
407
|
end
|
406
|
-
rescue
|
408
|
+
rescue
|
407
409
|
return false
|
408
410
|
end
|
409
411
|
|
@@ -412,10 +414,8 @@ module Knj::Php
|
|
412
414
|
|
413
415
|
def is_dir(filepath)
|
414
416
|
begin
|
415
|
-
if File.directory?(filepath)
|
416
|
-
|
417
|
-
end
|
418
|
-
rescue Exception
|
417
|
+
return true if File.directory?(filepath)
|
418
|
+
rescue
|
419
419
|
return false
|
420
420
|
end
|
421
421
|
|
@@ -484,7 +484,7 @@ module Knj::Php
|
|
484
484
|
begin
|
485
485
|
Kernel.const_get(classname)
|
486
486
|
return true
|
487
|
-
rescue
|
487
|
+
rescue
|
488
488
|
return false
|
489
489
|
end
|
490
490
|
end
|
@@ -527,7 +527,7 @@ module Knj::Php
|
|
527
527
|
def fopen(filename, mode)
|
528
528
|
begin
|
529
529
|
return File.open(filename, mode)
|
530
|
-
rescue
|
530
|
+
rescue
|
531
531
|
return false
|
532
532
|
end
|
533
533
|
end
|
@@ -535,7 +535,7 @@ module Knj::Php
|
|
535
535
|
def fwrite(fp, str)
|
536
536
|
begin
|
537
537
|
fp.print str
|
538
|
-
rescue
|
538
|
+
rescue
|
539
539
|
return false
|
540
540
|
end
|
541
541
|
|
@@ -545,7 +545,7 @@ module Knj::Php
|
|
545
545
|
def fputs(fp, str)
|
546
546
|
begin
|
547
547
|
fp.print str
|
548
|
-
rescue
|
548
|
+
rescue
|
549
549
|
return false
|
550
550
|
end
|
551
551
|
|
@@ -799,7 +799,7 @@ module Knj::Php
|
|
799
799
|
stdout.each do |str|
|
800
800
|
$stdout.print str
|
801
801
|
end
|
802
|
-
rescue
|
802
|
+
rescue => e
|
803
803
|
$stdout.print Knj::Errors.error_str(e)
|
804
804
|
end
|
805
805
|
end
|
@@ -810,7 +810,7 @@ module Knj::Php
|
|
810
810
|
stderr.each do |str|
|
811
811
|
$stderr.print str
|
812
812
|
end
|
813
|
-
rescue
|
813
|
+
rescue => e
|
814
814
|
$stderr.print Knj::Errors.error_str(e)
|
815
815
|
end
|
816
816
|
end
|
@@ -819,6 +819,7 @@ module Knj::Php
|
|
819
819
|
terr.join
|
820
820
|
end
|
821
821
|
else
|
822
|
+
require "open3"
|
822
823
|
Open3.popen3(cmd) do |stdin, stdout, stderr|
|
823
824
|
tout = Thread.new do
|
824
825
|
begin
|
@@ -826,7 +827,7 @@ module Knj::Php
|
|
826
827
|
stdout.each do |str|
|
827
828
|
$stdout.print str
|
828
829
|
end
|
829
|
-
rescue
|
830
|
+
rescue => e
|
830
831
|
$stdout.print Knj::Errors.error_str(e)
|
831
832
|
end
|
832
833
|
end
|
@@ -837,7 +838,7 @@ module Knj::Php
|
|
837
838
|
stderr.each do |str|
|
838
839
|
$stderr.print str
|
839
840
|
end
|
840
|
-
rescue
|
841
|
+
rescue => e
|
841
842
|
$stderr.print Knj::Errors.error_str(e)
|
842
843
|
end
|
843
844
|
end
|
data/lib/knj/process.rb
CHANGED
@@ -49,7 +49,7 @@ class Knj::Process
|
|
49
49
|
@listen_thread = Knj::Thread.new do
|
50
50
|
begin
|
51
51
|
self.listen
|
52
|
-
rescue
|
52
|
+
rescue => e
|
53
53
|
$stderr.print "#{Knj::Errors.error_str(e)}\n\n" if @debug
|
54
54
|
@thread_error = e
|
55
55
|
end
|
@@ -125,9 +125,9 @@ class Knj::Process
|
|
125
125
|
|
126
126
|
begin
|
127
127
|
@on_rec.call(result_obj)
|
128
|
-
rescue SystemExit => e
|
128
|
+
rescue SystemExit, Interrupt => e
|
129
129
|
raise e
|
130
|
-
rescue
|
130
|
+
rescue => e
|
131
131
|
#Error was raised - try to forward it to the server.
|
132
132
|
result_obj.answer("type" => "process_error", "class" => e.class.name, "msg" => e.message, "backtrace" => e.backtrace)
|
133
133
|
end
|
@@ -255,7 +255,7 @@ class Knj::Process
|
|
255
255
|
ensure
|
256
256
|
buffer_thread.join
|
257
257
|
end
|
258
|
-
rescue
|
258
|
+
rescue => e
|
259
259
|
$stderr.print Knj::Errors.error_str(e) if @debug
|
260
260
|
#Error was raised - try to forward it to the server.
|
261
261
|
result_obj.answer("type" => "process_error", "class" => e.class.name, "msg" => e.message, "backtrace" => e.backtrace)
|
@@ -276,7 +276,7 @@ class Knj::Process
|
|
276
276
|
$stderr.print "Unknown command: '#{data[0]}'."
|
277
277
|
raise "Unknown command: '#{data[0]}'."
|
278
278
|
end
|
279
|
-
rescue
|
279
|
+
rescue => e
|
280
280
|
$stderr.print Knj::Errors.error_str(e) if @debug
|
281
281
|
#Error was raised - try to forward it to the server.
|
282
282
|
result_obj = Knj::Process::Resultobject.new(:process => self, :id => id, :obj => obj)
|
data/lib/knj/rhodes/rhodes.rb
CHANGED
data/lib/knj/strings.rb
CHANGED
@@ -12,6 +12,15 @@ module Knj::Strings
|
|
12
12
|
return Knj::Strings.UnixSafe(string)
|
13
13
|
end
|
14
14
|
|
15
|
+
#Returns true if given string is regex-compatible.
|
16
|
+
def self.is_regex?(str)
|
17
|
+
if str.to_s.match(/^\/(.+)\/(i|m|x|)$/)
|
18
|
+
return true
|
19
|
+
else
|
20
|
+
return false
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
15
24
|
#Returns a Regexp-object from the string formatted as what you would give to Php's preg_match.
|
16
25
|
def self.regex(str)
|
17
26
|
first_char = str[0, 1]
|
@@ -285,4 +294,23 @@ module Knj::Strings
|
|
285
294
|
total = (hours * 3600) + (minutes * 60) + secs
|
286
295
|
return total
|
287
296
|
end
|
297
|
+
|
298
|
+
#Same as 'Class#is_a?' but takes a string instead of the actual class. Then it doesnt get autoloaded or anything like that. It can also test against an array containing string-class-names.
|
299
|
+
def self.is_a?(obj, str)
|
300
|
+
obj_class = obj.class
|
301
|
+
str = str.to_s if !str.is_a?(Array)
|
302
|
+
|
303
|
+
loop do
|
304
|
+
if str.is_a?(Array)
|
305
|
+
return true if str.index(obj_class.name.to_s) != nil
|
306
|
+
else
|
307
|
+
return true if obj_class.name.to_s == str
|
308
|
+
end
|
309
|
+
|
310
|
+
obj_class = obj_class.superclass
|
311
|
+
break if !obj_class
|
312
|
+
end
|
313
|
+
|
314
|
+
return false
|
315
|
+
end
|
288
316
|
end
|
data/lib/knj/thread.rb
CHANGED
data/lib/knj/thread2.rb
CHANGED
data/lib/knj/threadpool.rb
CHANGED
data/lib/knj/win_tightvnc.rb
CHANGED
@@ -101,7 +101,7 @@ class Knj::Win::TightVNC
|
|
101
101
|
begin
|
102
102
|
@process.GetOwner
|
103
103
|
return true
|
104
|
-
rescue
|
104
|
+
rescue => e
|
105
105
|
return false
|
106
106
|
end
|
107
107
|
end
|
@@ -111,7 +111,7 @@ class Knj::Win::TightVNC
|
|
111
111
|
|
112
112
|
begin
|
113
113
|
@process.Terminate
|
114
|
-
rescue
|
114
|
+
rescue => e
|
115
115
|
if e.class.to_s == "WIN32OLERuntimeError" and e.message.index("Terminate") != nil
|
116
116
|
#do nothing.
|
117
117
|
else
|
data/spec/strings_spec.rb
CHANGED
@@ -17,5 +17,11 @@ describe "Strings" do
|
|
17
17
|
rescue Knj::Errors::InvalidData
|
18
18
|
#this should happen - Ruby doesnt support U-modifier...
|
19
19
|
end
|
20
|
+
|
21
|
+
res = Knj::Strings.is_regex?("Kasper")
|
22
|
+
raise "Expected res to be false but it wasnt." if res
|
23
|
+
|
24
|
+
res = Knj::Strings.is_regex?("/^Kasper$/")
|
25
|
+
raise "Expected res to be true but it wasnt." if !res
|
20
26
|
end
|
21
27
|
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.
|
5
|
+
version: 0.0.42
|
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-
|
13
|
+
date: 2012-06-08 00:00:00 +02:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -188,6 +188,7 @@ files:
|
|
188
188
|
- lib/knj/gtk2_menu.rb
|
189
189
|
- lib/knj/gtk2_statuswindow.rb
|
190
190
|
- lib/knj/gtk2_tv.rb
|
191
|
+
- lib/knj/gtk2_window.rb
|
191
192
|
- lib/knj/hash_methods.rb
|
192
193
|
- lib/knj/http.rb
|
193
194
|
- lib/knj/http2.rb
|
@@ -377,7 +378,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
377
378
|
requirements:
|
378
379
|
- - ">="
|
379
380
|
- !ruby/object:Gem::Version
|
380
|
-
hash:
|
381
|
+
hash: -1360014744473154414
|
381
382
|
segments:
|
382
383
|
- 0
|
383
384
|
version: "0"
|