Module: ManqodCommon

Overview

this file is part of manqod manqod is distributed under the CDDL licence the author of manqod is Dobai-Pataky Balint([email protected])

Constant Summary collapse

CRITICAL =
"critical"
ERROR =
"error"
WARNING =
"warning"
NORMAL =
"normal"
INFO =
"info"
DEBUG =
"debug"

Constants included from Eprint

Eprint::DOMAIN, Eprint::LEVEL

Instance Method Summary collapse

Methods included from Eprint

#ecode, #edebug, #eerror, #einfo, #enormal, #eprint, #ewarn, #gtk_set_edebug, #set_edebug, #tell_exception

Instance Method Details

#add_where(sql, where) ⇒ Object



191
192
193
194
195
196
197
198
199
# File 'lib/ManqodCommon.rb', line 191

def add_where(sql,where)
	begin
		ret=ManqodDB.instance.manqod_db.add_where(sql,where)
		tell_exception("Database Error","Duplicate entry","sql","error") if ret == -1
		ret
	rescue =>err
		retry if tell_exception("RunTime error",backtrace_to_debug(err),"server","error",false,true,err.to_s)
	end
end

#adminObject



172
173
174
175
176
177
178
# File 'lib/ManqodCommon.rb', line 172

def admin
	begin
		ManqodDB.instance.manqod_db.admin
	rescue =>err
		retry if warn("RunTime error",backtrace_to_debug(err),"server","error",false,true,err.to_s)
	end
end

#admin_cacheObject



123
124
125
# File 'lib/ManqodCommon.rb', line 123

def admin_cache
	ManqodDB.instance.acache
end

#admin_qrow(sql, with_table = false) ⇒ Object



226
227
228
229
230
231
232
# File 'lib/ManqodCommon.rb', line 226

def admin_qrow(sql,with_table=false)
	begin
		ManqodDB.instance.manqod_db.admin.qrow(sql,with_table)
	rescue =>err
		retry if tell_exception("RunTime error",backtrace_to_debug(err),"server","error",false,true,err.to_s)
	end
end

#admin_rows(sql, with_table = false) ⇒ Object



217
218
219
220
221
222
223
224
# File 'lib/ManqodCommon.rb', line 217

def admin_rows(sql,with_table=false)
#		ecode("#{sql}")
	begin
		ManqodDB.instance.manqod_db.admin.rows(sql,with_table).each{|row| yield row}
	rescue =>err
		retry if tell_exception("RunTime error",backtrace_to_debug(err),"server","error",false,true,err.to_s)
	end
end

#backtrace_to_debug(c) ⇒ Object



16
17
18
19
20
# File 'lib/ManqodCommon.rb', line 16

def backtrace_to_debug(c)
	r="#{c}\n"
	c.backtrace.each{|i| r=r+"\t#{i}\n"}
	r
end

#cacheObject



120
121
122
# File 'lib/ManqodCommon.rb', line 120

def cache
	ManqodDB.instance.cache
end

#changed_ids_of_base(base, ids) ⇒ Object



272
273
274
275
276
277
278
# File 'lib/ManqodCommon.rb', line 272

def changed_ids_of_base(base,ids)
	begin
		ManqodDB.instance.manqod_db.changed_ids_of_base(base,ids,nick)
	rescue =>err
		retry if tell_exception("RunTime error",backtrace_to_debug(err),"server","error",false,true,err.to_s)
	end
end

#clientObject

def prep_sql(isql) ManqodDB.instance.manqod_db.client.escape_string(isql) end



131
132
133
134
135
136
137
# File 'lib/ManqodCommon.rb', line 131

def client
	begin
		ManqodDB.instance.manqod_db.client
	rescue =>err
		retry if tell_exception("RunTime error",backtrace_to_debug(err),"server","error",false,true,err.to_s)
	end
end

#client_fields(sql) ⇒ Object



148
149
150
151
152
153
154
# File 'lib/ManqodCommon.rb', line 148

def client_fields(sql)
	begin
		ManqodDB.instance.manqod_db.client.fields(sql).each{|row| yield row}
	rescue =>err
		retry if tell_exception("RunTime error",backtrace_to_debug(err),"server","error",false,true,err.to_s)
	end
end

#client_image_of_id(image_id = nil, resize = nil) ⇒ Object



263
264
265
266
267
268
269
# File 'lib/ManqodCommon.rb', line 263

def client_image_of_id(image_id=nil,resize=nil)
	begin
		DrbImages.instance.image_of_id(image_id,resize,true)
	rescue =>err
		ewarn(backtrace_to_debug(err))
	end
end

#client_qrow(sql) ⇒ Object



156
157
158
159
160
161
162
# File 'lib/ManqodCommon.rb', line 156

def client_qrow(sql)
	begin
		ManqodDB.instance.manqod_db.client.qrow(sql)
	rescue =>err
		retry if tell_exception("RunTime error",backtrace_to_debug(err),"server","error",false,true,err.to_s)
	end
end

#client_query(sql) ⇒ Object



139
140
141
142
143
144
145
146
# File 'lib/ManqodCommon.rb', line 139

def client_query(sql)
	begin
		einfo("Client query: #{sql}","sql")
		ManqodDB.instance.manqod_db.client.query(sql)
	rescue =>err
		retry if tell_exception("RunTime error",backtrace_to_debug(err),"server","error",false,true,err.to_s)
	end
end

#client_rows(sql) ⇒ Object



164
165
166
167
168
169
170
# File 'lib/ManqodCommon.rb', line 164

def client_rows(sql)
	begin
		ManqodDB.instance.manqod_db.client.rows(sql).each{|row| yield row}
	rescue =>err
		retry if tell_exception("RunTime error",backtrace_to_debug(err),"server","error",false,true,err.to_s)
	end
end

#eeval(command, context = self) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/ManqodCommon.rb', line 61

def eeval(command,context=self)
 	ret=nil
 	begin
		edebug("Running: #{command}","eval","debug")
		if context and b=context.getBinding then
			ret=eval(command, b)
			else
			ret=eval(command)
		end
	rescue SyntaxError, NameError => err
  	tell_exception("Syntax error: #{command}",backtrace_to_debug(err),"eval","error",true,false)
	rescue  => err
#	  edebug("String doesn't run: #{command}\n"+backtrace_to_debug(b),"eval","error")
  	tell_exception("String doesn't run: #{command}",backtrace_to_debug(err),"eval","error",true,false)
 	end
 	ret
end

#escape_string(sql) ⇒ Object



248
249
250
251
252
253
254
# File 'lib/ManqodCommon.rb', line 248

def escape_string(sql)
	begin
		ManqodDB.instance.manqod_db.escape_string(sql)
	rescue =>err
		retry if tell_exception("RunTime error",backtrace_to_debug(err),"server","error",false,true,err.to_s)
	end
end

#getBindingObject



79
80
81
# File 'lib/ManqodCommon.rb', line 79

def getBinding
	binding
end

#guess_base(sql) ⇒ Object



241
242
243
244
245
246
247
# File 'lib/ManqodCommon.rb', line 241

def guess_base(sql)
	begin
		ManqodDB.instance.manqod_db.guess_base(sql)
	rescue =>err
		retry if tell_exception("RunTime error",backtrace_to_debug(err),"server","error",false,true,err.to_s)
	end
end

#guess_table(sql, field) ⇒ Object



234
235
236
237
238
239
240
# File 'lib/ManqodCommon.rb', line 234

def guess_table(sql,field)
	begin
		ManqodDB.instance.manqod_db.guess_table(sql,field)
	rescue =>err
		retry if tell_exception("RunTime error",backtrace_to_debug(err),"server","error",false,true,err.to_s)
	end
end

#image_of_id(image_id = nil, resize = nil) ⇒ Object



256
257
258
259
260
261
262
# File 'lib/ManqodCommon.rb', line 256

def image_of_id(image_id=nil,resize=nil)
	begin
		DrbImages.instance.image_of_id(image_id,resize)
	rescue =>err
		ewarn(backtrace_to_debug(err))
	end
end

#lzero(s, n) ⇒ Object



38
39
40
41
42
43
# File 'lib/ManqodCommon.rb', line 38

def lzero(s,n)
	while s.to_s.length<n
		s="0#{s}"
	end
	s
end

#manqod_dbObject



113
114
115
116
117
118
119
# File 'lib/ManqodCommon.rb', line 113

def manqod_db
	begin
		ManqodDB.instance.manqod_db
	rescue =>err
		retry if tell_exception("RunTime error",backtrace_to_debug(err),"server","error",false,true,err.to_s)
	end
end

#measure(d = "", color = "default") ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/ManqodCommon.rb', line 22

def measure(d="",color="default")
	c=case color
		when "red" then 31
		when "blue" then 34
		when "green" then 32
		when "yellow" then 33
		when "magenta" then 35
		when "cyan" then 36
		when "white" then 37
		when "default" then 39
	end
	before_=Time.now
	yield
	time_diff=Time.now.to_f-before_.to_f;edebug("\e[#{c}m#{self} #{d} measured: "+sprintf("%.2fs",time_diff)+"\e[0m","time","normal")
end

#myexec(filename, filedata) ⇒ Object



89
90
91
# File 'lib/ManqodCommon.rb', line 89

def myexec(filename,filedata)
	Myexec.instance.myexec(filename,filedata)
end

#nickObject



93
94
95
# File 'lib/ManqodCommon.rb', line 93

def nick
	Nick.instance.get_nick
end

#nick_idObject



97
98
99
# File 'lib/ManqodCommon.rb', line 97

def nick_id
	Nick.instance.nick_id
end

#number_format(f, d) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/ManqodCommon.rb', line 45

def number_format(f,d)
	s=f.to_s
	if i=s.index(".")
		p1=s[0 .. i-1]
		p2=(s+"0000")[i .. i+d]
		else
		p1=s
		p2=".0000"
	end
	if d==0
		p1.gsub(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1,")
		else
		p1.gsub(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1,") + p2
	end
end

#qrow(sql, with_table = false) ⇒ Object



201
202
203
204
205
206
207
# File 'lib/ManqodCommon.rb', line 201

def qrow(sql,with_table=false)
	begin
		ManqodDB.instance.manqod_db.qrow(sql,with_table)
	rescue =>err
		retry if tell_exception("RunTime error",backtrace_to_debug(err),"server","error",false,true,err.to_s)
	end
end

#query(sql) ⇒ Object



180
181
182
183
184
185
186
187
188
189
# File 'lib/ManqodCommon.rb', line 180

def query(sql)
	begin
		einfo("query: #{sql}","sql")
		ret=ManqodDB.instance.manqod_db.query(sql)
		tell_exception("Database Error","Duplicate entry","sql","error") if ret == -1
		ret
	rescue =>err
		retry if tell_exception("RunTime error",backtrace_to_debug(err),"server","error",false,true,err.to_s)
	end
end

#reconnect_manqod_dbObject



109
110
111
# File 'lib/ManqodCommon.rb', line 109

def reconnect_manqod_db
		ManqodDB.instance.connect_to_server
end

#rows(sql, with_table = false) ⇒ Object



209
210
211
212
213
214
215
# File 'lib/ManqodCommon.rb', line 209

def rows(sql,with_table=false)
	begin
		i=ManqodDB.instance.manqod_db.rows(sql,with_table).each{|row| yield row}
	rescue =>err
		retry if tell_exception("RunTime error",backtrace_to_debug(err),"server","error",false,true,err.to_s)
	end
end

#run_events(gtkobjectid, event_name) ⇒ Object



83
84
85
86
87
# File 'lib/ManqodCommon.rb', line 83

def run_events(gtkobjectid,event_name)
	edebug("Running events #{event_name} for #{gtkobjectid}","events","debug")
	EventCache.instance.gtkobject_events(gtkobjectid,event_name){|event_command| eeval(event_command,self)}
#		edebug("Running events #{event_name} for #{gtkobjectid} finished.","events","debug")
end

#send_message(*args) ⇒ Object



287
288
289
290
291
292
293
# File 'lib/ManqodCommon.rb', line 287

def send_message(*args)
	begin
		ManqodDB.instance.manqod_db.send_message(*args)
	rescue =>err
		retry if tell_exception("RunTime error",backtrace_to_debug(err),"server","error",false,true,err.to_s)
	end
end

#sendmail(*args) ⇒ Object



280
281
282
283
284
285
286
# File 'lib/ManqodCommon.rb', line 280

def sendmail(*args)
	begin
		ManqodDB.instance.manqod_db.sendmail(*args)
	rescue =>err
		retry if tell_exception("RunTime error",backtrace_to_debug(err),"server","error",false,true,err.to_s)
	end
end

#set_manqod_db_uri(uri) ⇒ Object



105
106
107
# File 'lib/ManqodCommon.rb', line 105

def set_manqod_db_uri(uri)
		ManqodDB.instance.set_manqod_db_uri(uri)
end

#set_nick(new_nick) ⇒ Object



101
102
103
# File 'lib/ManqodCommon.rb', line 101

def set_nick(new_nick)
	Nick.instance.set_nick(new_nick)
end