Module: Eprint

Included in:
ConfStorage, EventCache, GtkAttributeStorage, Kernel, ManqodCommon, SB
Defined in:
lib/Common/Eprint.rb

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

LEVEL =
{
	"critical"	=>	0,
	"error"		=>	1,
	"warning"		=>	2,
	"normal"		=>	3,
	"info"		=>	4,
	"debug"		=>	5,
	"code"		=>	-1
}
DOMAIN =
{
	"config"			=>	"warning",
	"eval"			=>	"warning",
	"events"			=>	"warning",
	"filter-toggle"	=>	"warning",
	"form"			=>	"warning",
	"info"			=>	"warning",
	"form-combo"		=>	"warning",
	"gtk_button"		=>	"warning",
	"list" 			=>	"warning",
	"sub-list" 			=>	"warning",
	"list-button" 	=>	"warning",
	"list-list" 		=>	"warning",
	"list-filter"		=>	"warning",
	"list-fieldcombo"	=>	"warning",
	"list-filechooser"=>	"warning",
	"main"			=>	"normal",
	"menu"			=>	"warning",
	"relation-builder"		=>	"normal",
	"sql"				=>	"warning",
	"sql-prepare"		=>	"warning",
	"sql-guesstable"	=>	"warning",
	"time"			=>	"warning",
	"touch"			=>	"warning",
	"image"			=>	"warning",
	"printing"		=>	"warning",
	"drb"		=>	"warning"
	
}

Instance Method Summary collapse

Instance Method Details

#ecode(subject, debug_domain = "main") ⇒ Object



125
126
127
# File 'lib/Common/Eprint.rb', line 125

def ecode(subject,debug_domain="main")
	eprint(subject,debug_domain,"code")
end

#edebug(subject, debug_domain = "main", level = "debug", allow_log = false) ⇒ Object



101
102
103
104
105
106
107
108
109
# File 'lib/Common/Eprint.rb', line 101

def edebug(subject,debug_domain="main",level="debug",allow_log=false)
	case level
		when "normal" then enormal(subject,debug_domain)
		when "warning" then ewarn(subject,debug_domain)
		when "info" then einfo(subject,debug_domain)
		when "error" then eerror(subject,debug_domain)
		else eprint(subject,debug_domain,"debug")
	end
end

#eerror(subject, debug_domain = "main") ⇒ Object



119
120
121
# File 'lib/Common/Eprint.rb', line 119

def eerror(subject,debug_domain="main")
	eprint(subject,debug_domain,"error")
end

#einfo(subject, debug_domain = "main") ⇒ Object



111
112
113
# File 'lib/Common/Eprint.rb', line 111

def einfo(subject,debug_domain="main")
	eprint(subject,debug_domain,"info")
end

#enormal(subject, debug_domain = "main") ⇒ Object



122
123
124
# File 'lib/Common/Eprint.rb', line 122

def enormal(subject,debug_domain="main")
	eprint(subject,debug_domain,"normal")
end

#eprint(subject, debug_domain = "main", level = "normal") ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/Common/Eprint.rb', line 46

def eprint(subject,debug_domain="main",level="normal")
	#allow_log should be called only from the tell_exception's log statement to avoid recursivity
	colour=case level
		when "error" then 31
		when "blue" then 34
		when "info" then 32
		when "debug" then 33
		when "warning" then 35
		when "code" then 36
		when "white" then 37
		when "normal" then 39
	end

	t=Time.now.strftime("%H:%M:%S")
	if DOMAIN.has_key?(debug_domain) 
		if LEVEL[level] <= LEVEL[DOMAIN[debug_domain]]
			print "#{t} #{debug_domain}:\e[#{colour}m#{level}\e[0m:\e[1;37m#{self}\e[#{colour}m #{subject}\e[0m\n"
		end
	end
end

#ewarn(subject, debug_domain = "main") ⇒ Object



115
116
117
# File 'lib/Common/Eprint.rb', line 115

def ewarn(subject,debug_domain="main")
	eprint(subject,debug_domain,"warning")
end

#gtk_set_edebugObject



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/Common/Eprint.rb', line 72

def gtk_set_edebug
	dw=Gtk::Dialog.new("Debug",nil,Gtk::Dialog::MODAL,[Gtk::Stock::APPLY,1])
	#dw.realize;dw.window.set_functions(Gdk::Window::WMFunction::ALL | Gdk::Window::WMFunction::CLOSE)
	dw.vbox.pack_start(Gtk::ScrolledWindow.new.add_with_viewport(t=Gtk::Table.new(1,1)).set_size_request(300,600),true,true,0)
	#set up the combo model
	model=Gtk::ListStore.new(String,Integer)
	LEVEL.sort{|a,b|a[1]<=>b[1]}.each{|i|
		iter=model.append
		iter[0]=RUBY_VERSION.index("1.8") ? LEVEL.index(i[1]) : LEVEL.key(i[1])
		iter[1]=LEVEL[iter[0]]
	}
	#set up the debug domain widgets
	i=0
	DOMAIN.sort.each{|key|
		c=Gtk::ComboBox.new.set_model(model)
		c.set_name(key[0])
		c.signal_connect('changed'){|me|
			DOMAIN[me.name]=me.active_iter[0]
			set_conf(0,0,me.name,me.active_iter[0])
		}
		model.each {|model, path, iter| c.set_active(path.indices[0]) if iter[1]==LEVEL[key[1]] }
		t.attach(Gtk::Label.new(key[0]).set_alignment(0,0.5),0,1,i,i+1,Gtk::EXPAND|Gtk::FILL,Gtk::EXPAND|Gtk::FILL,1,1)
		t.attach(c,1,2,i,i+1,Gtk::EXPAND|Gtk::FILL,Gtk::EXPAND|Gtk::FILL,1,1)
		i=i+1
	}
	dw.show_all.run
	dw.destroy
end

#set_edebug(debug_domain, level) ⇒ Object



67
68
69
70
# File 'lib/Common/Eprint.rb', line 67

def set_edebug(debug_domain,level)
	DOMAIN[debug_domain]=level
	self
end

#tell_exception(subject, details = nil, debug_domain = "main", level = "normal", allow_log = true, canretry = false, secondary_text = nil) ⇒ Object Also known as: warn



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/Common/Eprint.rb', line 129

def tell_exception(subject,details=nil,debug_domain="main",level="normal",allow_log=true,canretry=false,secondary_text=nil)
	edebug("#{subject}\n#{secondary_text}\n#{details}",debug_domain,level,allow_log)
	begin
		ret=nil
		dialog=Gtk::MessageDialog.new(nil,Gtk::Dialog::Flags::MODAL,
			case level
				when "error" then Gtk::MessageDialog::ERROR
				when "warning" then Gtk::MessageDialog::WARNING
				when "normal","info" then Gtk::MessageDialog::INFO
				else Gtk::MessageDialog::OTHER
			end,
			if canretry
				Gtk::MessageDialog::ButtonsType::YES_NO
				else
				Gtk::MessageDialog::ButtonsType::CLOSE
			end,
			subject)
		if secondary_text
			dialog.set_secondary_text(secondary_text)
			else
			dialog.set_secondary_text("please report it!") if level == 'error'
		end
		dialog.vbox.pack_start(expander=Gtk::Expander.new("details",true).add(Gtk::ScrolledWindow.new.set_size_request(600,300).set_policy(Gtk::POLICY_AUTOMATIC,Gtk::POLICY_AUTOMATIC).add(Gtk::TextView.new(Gtk::TextBuffer.new.set_text(details))))) unless details.nil?
		dialog.vbox.pack_end(Gtk::Label.new("retry?")) if canretry
		if level == 'error'
			dialog.action_area.pack_start(send=Gtk::Button.new("report").set_image(Gtk::Image.new(Gtk::Stock::HELP,Gtk::IconSize::MENU)))
			send.signal_connect("clicked"){|me,ev|
				begin
					ManqodRPC.instance.manqod_server.report_mail(subject,
						:details =>details.inspect,
						:more_details=>secondary_text.inspect,
						:class_name => self.class.name,
						:self => self.inspect
						)
				rescue => err
					retry if warn("Reporting failed",err.backtrace.join("\n"),"server","error",false,false,err.to_s)
				end
				dialog.action_area.remove(me)
			}
		end
		dialog.show_all
		ret=dialog.run
		dialog.destroy
	ret == Gtk::Dialog::ResponseType::YES
	rescue
	end
end