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
@@ -1,449 +0,0 @@
1
- class KnjDB_sqlite3::Tables
2
- attr_reader :db, :driver
3
-
4
- def initialize(args)
5
- @args = args
6
- @db = @args[:db]
7
-
8
- @list_mutex = Mutex.new
9
- @list = Wref_map.new
10
- end
11
-
12
- def [](table_name)
13
- table_name = table_name.to_s
14
-
15
- begin
16
- ret = @list[table_name]
17
- return ret
18
- rescue Wref::Recycled
19
- #ignore.
20
- end
21
-
22
- self.list do |table_obj|
23
- return table_obj if table_obj.name.to_s == table_name.to_s
24
- end
25
-
26
- raise Errno::ENOENT, "Table was not found: #{table_name}."
27
- end
28
-
29
- def list
30
- ret = {} unless block_given?
31
-
32
- @list_mutex.synchronize do
33
- q_tables = @db.select("sqlite_master", {"type" => "table"}, {"orderby" => "name"}) do |d_tables|
34
- next if d_tables[:name] == "sqlite_sequence"
35
-
36
- obj = @list.get!(d_tables[:name])
37
-
38
- if !obj
39
- obj = KnjDB_sqlite3::Tables::Table.new(
40
- :db => @db,
41
- :data => d_tables
42
- )
43
- @list[d_tables[:name]] = obj
44
- end
45
-
46
- if block_given?
47
- yield(obj)
48
- else
49
- ret[d_tables[:name]] = obj
50
- end
51
- end
52
- end
53
-
54
- if block_given?
55
- return nil
56
- else
57
- return ret
58
- end
59
- end
60
-
61
- def create(name, data, args = nil)
62
- sql = "CREATE TABLE `#{name}` ("
63
-
64
- first = true
65
- data["columns"].each do |col_data|
66
- sql << ", " if !first
67
- first = false if first
68
- sql << @db.cols.data_sql(col_data)
69
- end
70
-
71
- sql << ")"
72
-
73
- if args and args[:return_sql]
74
- ret = [sql]
75
- else
76
- @db.query(sql)
77
- end
78
-
79
- if data.key?("indexes") and data["indexes"]
80
- table_obj = self[name]
81
-
82
- if args and args[:return_sql]
83
- ret += table_obj.create_indexes(data["indexes"], :return_sql => true)
84
- else
85
- table_obj.create_indexes(data["indexes"])
86
- end
87
- end
88
-
89
- if args and args[:return_sql]
90
- return ret
91
- else
92
- return nil
93
- end
94
- end
95
- end
96
-
97
- class KnjDB_sqlite3::Tables::Table
98
- def initialize(args)
99
- @db = args[:db]
100
- @data = args[:data]
101
-
102
- @list = Wref_map.new
103
- @indexes_list = Wref_map.new
104
- end
105
-
106
- def name
107
- return @data[:name]
108
- end
109
-
110
- def type
111
- return @data[:type]
112
- end
113
-
114
- def maxlength
115
- return @data[:maxlength]
116
- end
117
-
118
- def reload
119
- @data = @db.select("sqlite_master", {"type" => "table", "name" => self.name}, {"orderby" => "name"}).fetch
120
- end
121
-
122
- def rows_count
123
- data = @db.q("SELECT COUNT(*) AS count FROM `#{self.name}`").fetch
124
- return data[:count].to_i
125
- end
126
-
127
- #Drops the table from the database.
128
- def drop
129
- raise "Cant drop native table: '#{self.name}'." if self.native?
130
- @db.query("DROP TABLE `#{self.name}`")
131
- end
132
-
133
- #Returns true if the table is safe to drop.
134
- def native?
135
- return true if self.name.to_s == "sqlite_sequence"
136
- return false
137
- end
138
-
139
- def optimize
140
- raise "stub!"
141
- end
142
-
143
- def rename(newname)
144
- self.clone(newname)
145
- self.drop
146
- end
147
-
148
- def truncate
149
- @db.query("DELETE FROM `#{self.name}` WHERE 1=1")
150
- return nil
151
- end
152
-
153
- def table
154
- return @db.tables[@table_name]
155
- end
156
-
157
- def column(name)
158
- list = self.columns
159
- return list[name] if list[name]
160
- raise Errno::ENOENT.new("Column not found: #{name}.")
161
- end
162
-
163
- def columns
164
- @db.cols
165
- ret = {}
166
-
167
- @db.q("PRAGMA table_info(`#{@db.esc_table(self.name)}`)") do |d_cols|
168
- obj = @list.get!(d_cols[:name])
169
-
170
- if !obj
171
- obj = KnjDB_sqlite3::Columns::Column.new(
172
- :table_name => self.name,
173
- :db => @db,
174
- :data => d_cols
175
- )
176
- @list[d_cols[:name]] = obj
177
- end
178
-
179
- if block_given?
180
- yield(obj)
181
- else
182
- ret[d_cols[:name]] = obj
183
- end
184
- end
185
-
186
- if block_given?
187
- return nil
188
- else
189
- return ret
190
- end
191
- end
192
-
193
- def create_columns(col_arr)
194
- col_arr.each do |col_data|
195
- #if col_data.key?("after")
196
- # self.create_column_programmatic(col_data)
197
- #else
198
- @db.query("ALTER TABLE `#{self.name}` ADD COLUMN #{@db.cols.data_sql(col_data)};")
199
- #end
200
- end
201
- end
202
-
203
- def create_column_programmatic(col_data)
204
- temp_name = "temptable_#{Time.now.to_f.to_s.hash}"
205
- cloned_tabled = self.clone(temp_name)
206
- cols_cur = self.columns
207
- @db.query("DROP TABLE `#{self.name}`")
208
-
209
- sql = "CREATE TABLE `#{self.name}` ("
210
- first = true
211
- cols_cur.each do |name, col|
212
- sql << ", " if !first
213
- first = false if first
214
- sql << @db.cols.data_sql(col.data)
215
-
216
- if col_data["after"] and col_data["after"] == name
217
- sql << ", #{@db.cols.data_sql(col_data)}"
218
- end
219
- end
220
- sql << ");"
221
- @db.query(sql)
222
-
223
- sql = "INSERT INTO `#{self.name}` SELECT "
224
- first = true
225
- cols_cur.each do |name, col|
226
- sql << ", " if !first
227
- first = false if first
228
-
229
- sql << "`#{name}`"
230
-
231
- if col_data["after"] and col_data["after"] == name
232
- sql << ", ''"
233
- end
234
- end
235
- sql << " FROM `#{temp_name}`"
236
- @db.query(sql)
237
- @db.query("DROP TABLE `#{temp_name}`")
238
- end
239
-
240
- def clone(newname)
241
- raise "Invalid name." if newname.to_s.strip.length <= 0
242
- cols_cur = self.columns
243
-
244
- sql = "CREATE TABLE `#{newname}` ("
245
- first = true
246
- cols_cur.each do |name, col|
247
- sql << ", " if !first
248
- first = false if first
249
- sql << @db.cols.data_sql(col.data)
250
- end
251
-
252
- sql << ");"
253
- @db.query(sql)
254
-
255
- sql = "INSERT INTO `#{newname}` SELECT * FROM `#{self.name}`"
256
- @db.query(sql)
257
- return @db.tables[newname]
258
- end
259
-
260
- def copy(args = {})
261
- temp_name = "temptable_#{Time.now.to_f.to_s.hash}"
262
- cloned_tabled = self.clone(temp_name)
263
- cols_cur = self.columns
264
- @db.query("DROP TABLE `#{self.name}`")
265
-
266
- sql = "CREATE TABLE `#{self.name}` ("
267
- first = true
268
- cols_cur.each do |name, col|
269
- next if args["drops"] and args["drops"].index(name) != nil
270
-
271
- sql << ", " if !first
272
- first = false if first
273
-
274
- if args.key?("alter_columns") and args["alter_columns"][name.to_s]
275
- sql << @db.cols.data_sql(args["alter_columns"][name.to_s])
276
- else
277
- sql << @db.cols.data_sql(col.data)
278
- end
279
-
280
- if args["new"]
281
- args["new"].each do |col_data|
282
- if col_data["after"] and col_data["after"] == name
283
- sql << ", #{@db.cols.data_sql(col_data)}"
284
- end
285
- end
286
- end
287
- end
288
- sql << ");"
289
- @db.query(sql)
290
-
291
- sql = "INSERT INTO `#{self.name}` SELECT "
292
- first = true
293
- cols_cur.each do |name, col|
294
- next if args["drops"] and args["drops"].index(name) != nil
295
-
296
- sql << ", " if !first
297
- first = false if first
298
-
299
- sql << "`#{name}`"
300
-
301
- if args["news"]
302
- args["news"].each do |col_data|
303
- if col_data["after"] and col_data["after"] == name
304
- sql << ", ''"
305
- end
306
- end
307
- end
308
- end
309
-
310
- sql << " FROM `#{temp_name}`"
311
- @db.query(sql)
312
- @db.query("DROP TABLE `#{temp_name}`")
313
- end
314
-
315
- def index(name)
316
- name = name.to_s
317
-
318
- begin
319
- return @indexes_list[name]
320
- rescue Wref::Recycled
321
- if @db.opts[:index_append_table_name]
322
- tryname = "#{self.name}__#{name}"
323
-
324
- begin
325
- return @indexes_list[tryname]
326
- rescue Wref::Recycled
327
- #ignore.
328
- end
329
- else
330
- #ignore
331
- end
332
- end
333
-
334
- self.indexes do |index|
335
- return index if index.name.to_s == name
336
- end
337
-
338
- raise Errno::ENOENT.new("Index not found: #{name}.")
339
- end
340
-
341
- def indexes
342
- @db.indexes
343
- ret = {} unless block_given?
344
-
345
- @db.q("PRAGMA index_list(`#{@db.esc_table(self.name)}`)") do |d_indexes|
346
- next if d_indexes[:Key_name] == "PRIMARY"
347
-
348
- obj = @indexes_list.get!(d_indexes[:name])
349
-
350
- if !obj
351
- if @db.opts[:index_append_table_name]
352
- match_name = d_indexes[:name].match(/__(.+)$/)
353
-
354
- if match_name
355
- name = match_name[1]
356
- else
357
- name = d_indexes[:name]
358
- end
359
- else
360
- name = d_indexes[:name]
361
- end
362
-
363
- obj = KnjDB_sqlite3::Indexes::Index.new(
364
- :table_name => self.name,
365
- :db => @db,
366
- :data => d_indexes
367
- )
368
- obj.columns << name
369
- @indexes_list[d_indexes[:name]] = obj
370
- end
371
-
372
- if block_given?
373
- yield(obj)
374
- else
375
- ret[d_indexes[:name]] = obj
376
- end
377
- end
378
-
379
- if block_given?
380
- return nil
381
- else
382
- return ret
383
- end
384
- end
385
-
386
- def create_indexes(index_arr, args = nil)
387
- if args and args[:return_sql]
388
- ret = []
389
- end
390
-
391
- index_arr.each do |index_data|
392
- if index_data.is_a?(String)
393
- index_data = {"name" => index_data, "columns" => [index_data]}
394
- end
395
-
396
- raise "No name was given." if !index_data.key?("name") or index_data["name"].strip.length <= 0
397
- raise "No columns was given on index #{index_data["name"]}." if index_data["columns"].empty?
398
-
399
- name = index_data["name"]
400
- name = "#{self.name}__#{name}" if @db.opts[:index_append_table_name]
401
-
402
- sql = "CREATE INDEX '#{@db.esc_col(name)}' ON `#{@db.esc_table(self.name)}` ("
403
-
404
- first = true
405
- index_data["columns"].each do |col_name|
406
- sql << ", " if !first
407
- first = false if first
408
-
409
- sql << "`#{@db.esc_col(col_name)}`"
410
- end
411
-
412
- sql << ")"
413
-
414
- if args and args[:return_sql]
415
- ret << sql
416
- else
417
- @db.query(sql)
418
- end
419
- end
420
-
421
- if args and args[:return_sql]
422
- return ret
423
- else
424
- return nil
425
- end
426
- end
427
-
428
- def data
429
- ret = {
430
- "name" => name,
431
- "columns" => [],
432
- "indexes" => []
433
- }
434
-
435
- columns.each do |name, column|
436
- ret["columns"] << column.data
437
- end
438
-
439
- indexes.each do |name, index|
440
- ret["indexes"] << index.data if name != "PRIMARY"
441
- end
442
-
443
- return ret
444
- end
445
-
446
- def insert(data)
447
- @db.insert(self.name, data)
448
- end
449
- end
@@ -1,122 +0,0 @@
1
- #This class can be used to make SQL-dumps of databases, tables or however you want it.
2
- class Knj::Db::Dump
3
- #Constructor.
4
- #===Examples
5
- # dump = Knj::Db::Dump.new(:db => db)
6
- def initialize(args)
7
- @args = args
8
- @debug = @args[:debug]
9
- end
10
-
11
- #Method used to update the status.
12
- def update_status
13
- return nil if !@on_status
14
- rows_count = Knj::Locales.number_out(@rows_count, 0)
15
- rows_count_total = Knj::Locales.number_out(@rows_count_total, 0)
16
- percent = (@rows_count.to_f / @rows_count_total.to_f) * 100
17
- percent_text = Knj::Locales.number_out(percent, 1)
18
- @on_status.call(:text => "Dumping table: '#{@table_obj.name}' (#{rows_count}/#{rows_count_total} - #{percent_text}%).")
19
- end
20
-
21
- #Dumps all tables into the given IO.
22
- def dump(io)
23
- print "Going through tables.\n" if @debug
24
- @rows_count = 0
25
-
26
- if @args[:tables]
27
- tables = @args[:tables]
28
- else
29
- tables = @args[:db].tables.list.values
30
- end
31
-
32
- if @on_status
33
- @on_status.call(:text => "Preparing.")
34
-
35
- @rows_count_total = 0
36
- tables.each do |table_obj|
37
- @rows_count_total += table_obj.rows_count
38
- end
39
- end
40
-
41
- tables.each do |table_obj|
42
- table_obj = @args[:db].tables[table_obj] if table_obj.is_a?(String) or table_obj.is_a?(Symbol)
43
- next if table_obj.native?
44
-
45
- #Figure out keys.
46
- @keys = []
47
- table_obj.columns do |col|
48
- @keys << col.name
49
- end
50
-
51
- @table_obj = table_obj
52
- self.update_status
53
- print "Dumping table: '#{table_obj.name}'.\n" if @debug
54
- self.dump_table(io, table_obj)
55
- end
56
- end
57
-
58
- #A block can be executed when a new status occurs.
59
- def on_status(&block)
60
- @on_status = block
61
- end
62
-
63
- #Dumps the given table into the given IO.
64
- def dump_table(io, table_obj)
65
- #Get SQL for creating table and add it to IO.
66
- sqls = @args[:db].tables.create(table_obj.name, table_obj.data, :return_sql => true)
67
- sqls.each do |sql|
68
- io.write("#{sql};\n")
69
- end
70
-
71
-
72
- #Try to find a primary column in the table.
73
- prim_col = nil
74
- table_obj.columns do |col|
75
- if col.primarykey?
76
- prim_col = col
77
- break
78
- end
79
- end
80
-
81
-
82
- #Set up rows and way to fill rows.
83
- rows = []
84
- block_data = proc do |row|
85
- rows << row
86
- @rows_count += 1
87
-
88
- if rows.length >= 1000
89
- self.update_status
90
- self.dump_insert_multi(io, table_obj, rows)
91
- end
92
- end
93
-
94
-
95
- #If a primary column is found then use IDQuery. Otherwise use cloned unbuffered query.
96
- args = {:idquery => prim_col.name.to_sym} if prim_col
97
-
98
-
99
- #Clone the connecting with array-results and execute query.
100
- @args[:db].clone_conn(:result => "array") do |db|
101
- db.select(table_obj.name, nil, args, &block_data)
102
- end
103
-
104
-
105
- #Dump the last rows if any.
106
- self.dump_insert_multi(io, table_obj, rows) if !rows.empty?
107
- end
108
-
109
- #Dumps the given rows from the given table into the given IO.
110
- def dump_insert_multi(io, table_obj, rows)
111
- print "Inserting #{rows.length} into #{table_obj.name}.\n" if @debug
112
- sqls = @args[:db].insert_multi(table_obj.name, rows, :return_sql => true, :keys => @keys)
113
- sqls.each do |sql|
114
- io.write("#{sql};\n")
115
- end
116
-
117
- rows.clear
118
-
119
- #Ensure garbage collection or we might start using A LOT of memory.
120
- GC.start
121
- end
122
- end
@@ -1,109 +0,0 @@
1
- #This class takes a lot of IDs and runs a query against them.
2
- class Knj::Db::Idquery
3
- #An array containing all the IDs that will be looked up.
4
- attr_reader :ids
5
-
6
- #Constructor.
7
- #===Examples
8
- # idq = Knj::Db::Idquery(:db => db, :table => :users)
9
- # idq.ids + [1, 5, 9]
10
- # idq.each do |user|
11
- # print "Name: #{user[:name]}\n"
12
- # end
13
- def initialize(args, &block)
14
- @args = args
15
- @ids = []
16
- @debug = @args[:debug]
17
-
18
- if @args[:query]
19
- @args[:db].q(@args[:query]) do |data|
20
- @args[:col] = data.keys.first if !@args[:col]
21
-
22
- if data.is_a?(Array)
23
- @ids << data.first
24
- else
25
- @ids << data[@args[:col]]
26
- end
27
- end
28
- end
29
-
30
- @args[:col] = :id if !@args[:col]
31
- @args[:size] = 200 if !@args[:size]
32
-
33
- if block
34
- raise "No query was given but a block was." if !@args[:query]
35
- self.each(&block)
36
- end
37
- end
38
-
39
- #Fetches results.
40
- #===Examples
41
- # data = idq.fetch #=> Hash
42
- def fetch
43
- return nil if !@args
44
-
45
- if @res
46
- data = @res.fetch if @res
47
- @res = nil if !data
48
- return data if data
49
- end
50
-
51
- @res = new_res if !@res
52
- if !@res
53
- destroy
54
- return nil
55
- end
56
-
57
- data = @res.fetch
58
- if !data
59
- destroy
60
- return nil
61
- end
62
-
63
- return data
64
- end
65
-
66
- #Yields a block for every result.
67
- #===Examples
68
- # idq.each do |data|
69
- # print "Name: #{data[:name]}\n"
70
- # end
71
- def each
72
- while data = self.fetch
73
- yield(data)
74
- end
75
- end
76
-
77
- private
78
-
79
- #Spawns a new database-result to read from.
80
- def new_res
81
- table_esc = "`#{@args[:db].esc_table(@args[:table])}`"
82
- col_esc = "`#{@args[:db].esc_col(@args[:col])}`"
83
- ids = @ids.shift(@args[:size])
84
-
85
- if ids.empty?
86
- destroy
87
- return nil
88
- end
89
-
90
- ids_sql = Knj::ArrayExt.join(
91
- :arr => ids,
92
- :callback => proc{|val| @args[:db].esc(val)},
93
- :sep => ",",
94
- :surr => "'"
95
- )
96
-
97
- query_str = "SELECT * FROM #{table_esc} WHERE #{table_esc}.#{col_esc} IN (#{ids_sql})"
98
- print "Query: #{query_str}\n" if @debug
99
-
100
- return @args[:db].q(query_str)
101
- end
102
-
103
- #Removes all variables on the object. This is done when no more results are available.
104
- def destroy
105
- @args = nil
106
- @ids = nil
107
- @debug = nil
108
- end
109
- end