• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Ruby GTK3移行後のメインリポジトリ


Commit MetaInfo

Revisiond32eb159f46727745121eca8f1701fc9a10ea70c (tree)
Time2015-05-31 23:11:28
AuthorShyouzou Sugitani <shy@user...>
CommiterShyouzou Sugitani

Log Message

assorted fixes(30)

Change Summary

Incremental Difference

--- a/lib/ninix/logging.rb
+++ b/lib/ninix/logging.rb
@@ -3,30 +3,48 @@ require "logger"
33 module Logging
44
55 class Logging
6- @@logger = Logger.new(STDOUT)
6+ @@logger = []
7+ @@logger << Logger.new(STDOUT)
8+ @@level = Logger::WARN
79
810 def initialize
911 ##@@logger.level = Logger::WARN
1012 end
1113
1214 def self.set_level(level)
13- @@logger.level = level
15+ @@logger.each do |logger|
16+ logger.level = level
17+ end
18+ @@level = level
19+ end
20+
21+ def self.add_logger(logger)
22+ @@logger << logger
23+ logger.level = @@level
1424 end
1525
1626 def self.info(message)
17- @@logger.info(message)
27+ @@logger.each do |logger|
28+ logger.info(message)
29+ end
1830 end
1931
2032 def self.error(message)
21- @@logger.error(message)
33+ @@logger.each do |logger|
34+ logger.error(message)
35+ end
2236 end
2337
2438 def self.warning(message)
25- @@logger.warn(message)
39+ @@logger.each do |logger|
40+ logger.warn(message)
41+ end
2642 end
2743
2844 def self.debug(message)
29- @@logger.debug(message)
45+ @@logger.each do |logger|
46+ logger.debug(message)
47+ end
3048 end
3149 end
3250 end
--- a/lib/ninix_main.rb
+++ b/lib/ninix_main.rb
@@ -36,18 +36,21 @@ require "ninix/logging"
3636
3737 module Ninix_Main
3838
39- def self.handleException(exception_type, value, tb)
40- #logger.error('Uncaught exception',
41- # exc_info=(exception_type, value, tb))
39+ def self.handleException(exception)
40+ message = 'Uncaught exception (' + exception.class.to_s + ")\n" + exception.backtrace.join("\n")
41+ Logging::Logging.error(message)
4242 response_id = 1
4343 dialog = Gtk::MessageDialog.new(
44- nil, 0, Gtk.MessageType.ERROR, Gtk.ButtonsType.NONE,
45- _('A ninix-aya error has been detected.'))
46- dialog.set_title(_('Bug Detected'))
47- dialog.set_position(Gtk.WindowPosition.CENTER)
48- dialog.set_gravity(Gdk.Gravity.CENTER)
49- button = dialog.add_button(_('Show Details'), response_id)
50- dialog.add_button("_Close", Gtk.ResponseType.CLOSE)
44+ nil, 0, Gtk::MessageType::ERROR, Gtk::MessageDialog::ButtonsType::NONE,
45+ # _('A ninix-aya error has been detected.'))
46+ 'A ninix-aya error has been detected.')
47+ # dialog.set_title(_('Bug Detected'))
48+ dialog.set_title('Bug Detected')
49+ dialog.set_window_position(Gtk::Window::Position::CENTER)
50+ dialog.gravity = Gdk::Window::Gravity::CENTER
51+ # button = dialog.add_button(_('Show Details'), response_id)
52+ button = dialog.add_button('Show Details', response_id)
53+ dialog.add_button("_Close", Gtk::ResponseType::CLOSE)
5154 textview = Gtk::TextView.new
5255 textview.set_editable(false)
5356 left, top, scrn_w, scrn_h = Pix.get_workarea()
@@ -57,22 +60,21 @@ module Ninix_Main
5760 textview.show()
5861 sw = Gtk::ScrolledWindow.new
5962 sw.show()
60- sw.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
63+ sw.set_policy(Gtk::PolicyType::AUTOMATIC, Gtk::PolicyType::AUTOMATIC)
6164 sw.add(textview)
6265 frame = Gtk::Frame.new
63- frame.set_shadow_type(Gtk.ShadowType.IN)
66+ frame.set_shadow_type(Gtk::ShadowType::IN)
6467 frame.add(sw)
6568 frame.set_border_width(7)
66- content_area = dialog.get_content_area()
69+ frame.set_size_request(480, 320) # XXX
70+ content_area = dialog.content_area
6771 content_area.add(frame)
68- stringio = io.StringIO()
69- traceback.print_exception(exception_type, value, tb, nil, stringio)
70- textbuffer = textview.get_buffer()
71- textbuffer.set_text(stringio.getvalue())
72+ textbuffer = textview.buffer
73+ textbuffer.set_text(message)
7274 while true
7375 if dialog.run() == response_id
7476 frame.show()
75- button.set_sensitive(0)
77+ button.set_sensitive(false)
7678 else # close button
7779 break
7880 end
@@ -81,12 +83,10 @@ module Ninix_Main
8183 raise SystemExit
8284 end
8385
84-# sys.excepthook = handleException
85-
8686 def self.main(option)
8787 # parse command line arguments
8888 if option[:logfile]
89- #logger.addHandler(logging.FileHandler(args.logfile))
89+ Logging::Logging.add_logger(Logger.new(option[:logfile]))
9090 end
9191 # TCP 7743:伺か(未使用)(IANA Registered Port for SSTP)
9292 # UDP 7743:伺か(未使用)(IANA Registered Port for SSTP)
@@ -132,9 +132,7 @@ module Ninix_Main
132132 raise SystemExit('ninix-aya is already running')
133133 end
134134 # start
135- Logging::Logging.info('loading...')
136135 app = Application.new(f, :sstp_port => sstp_port)
137- Logging::Logging.info('done.')
138136 app.run(abend)
139137 f.truncate(0)
140138 begin
@@ -273,16 +271,21 @@ module Ninix_Main
273271 socket = sstp_server.accept_nonblock
274272 rescue
275273 next
276- #rescue # except socket.error as e:
277- #code, message = e.args
278- #logging.error('socket.error: {0} ({1:d})'.format(message, code))
279- #rescue # except ValueError: # may happen when ninix is terminated
280- #return
281274 end
282- handler = SSTP::SSTPRequestHandler.new(sstp_server, socket)
283- buffer = socket.gets
284- handler.handle(buffer)
285- socket.close
275+ begin
276+ handler = SSTP::SSTPRequestHandler.new(sstp_server, socket)
277+ buffer = socket.gets
278+ handler.handle(buffer)
279+ socket.close
280+ rescue SocketError => e
281+ Logging::Logging.error(
282+ 'socket.error: ' + e.message)
283+ rescue SystemCallError => e
284+ Logging::Logging.error(
285+ 'socket.error: ' + e.message + ' (' + e.errno.to_s + ')')
286+ rescue # may happen when ninix is terminated
287+ return
288+ end
286289 end
287290 end
288291
@@ -303,10 +306,9 @@ module Ninix_Main
303306 for port in @sstp_port
304307 begin
305308 server = SSTP::SSTPServer.new(port)
306- rescue # except socket.error as e:
307- #code, message = e.args
308- #logging.warning(
309- # 'Port {0:d}: {1} (ignored)'.format(port, message))
309+ rescue SystemCallError => e
310+ Logging::Logging.warning(
311+ 'Port ' + port.to_s + ': ' + e.message + ' (ignored)')
310312 next
311313 end
312314 server.set_responsible(self)
@@ -387,6 +389,7 @@ module Ninix_Main
387389 @loaded = false
388390 @confirmed = false
389391 @console = Console.new(self)
392+ Logging::Logging.info('loading...')
390393 # create preference dialog
391394 @prefs = Prefs::PreferenceDialog.new
392395 @prefs.set_responsible(self)
@@ -425,6 +428,7 @@ module Ninix_Main
425428 @nekoninni = Home.search_nekoninni()
426429 @katochan = Home.search_katochan()
427430 @kinoko = Home.search_kinoko()
431+ Logging::Logging.info('done.')
428432 end
429433
430434 def edit_preferences(*arglist)
@@ -945,14 +949,12 @@ module Ninix_Main
945949
946950 def run(abend)
947951 @abend = abend
948-# if os.name == "nt"
949-# # The SIGTERM signal is not generated under Windows NT.
950-# import win32api
951-# win32api.SetConsoleCtrlHandler(self.exit_handler, true)
952-# else
953-# import signal
954-# signal.signal(signal.SIGTERM, self.exit_handler)
955-# end
952+ if RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/
953+ # The SIGTERM signal is not generated under Windows NT.
954+ #win32api.SetConsoleCtrlHandler(exit_handler, true)
955+ else
956+ Signal.trap(:TERM) {|signo| exit_handler(signo) }
957+ end
956958 @timeout_id = GLib::Timeout.add(100) { do_idle_tasks } # 100[ms]
957959 Gtk.main()
958960 end
@@ -1248,10 +1250,10 @@ module Ninix_Main
12481250 def add_balloon(balloon_dir)
12491251 if @balloons.include?(balloon_dir)
12501252 exists = true
1251- #logging.warning('INSTALLED BALLOON CHANGED: {0}'.format(balloon_dir))
1253+ Logging::Logging.warning('INSTALLED BALLOON CHANGED: ' + balloon_dir)
12521254 else
12531255 exists = false
1254- #logging.info('NEW BALLOON INSTALLED: {0}'.format(balloon_dir))
1256+ Logging::Logging.info('NEW BALLOON INSTALLED: ' + balloon_dir)
12551257 end
12561258 balloon_conf = Home.search_balloons(:target => [balloon_dir])
12571259 if not balloon_conf.empty?
@@ -1282,16 +1284,16 @@ module Ninix_Main
12821284 begin
12831285 File.delete(File.join(prefix, filename))
12841286 rescue
1285- #logging.error(
1286- # '*** REMOVE FAILED *** : {0}'.format(filename))
1287+ Logging::Logging.error(
1288+ '*** REMOVE FAILED *** : ' + filename)
12871289 end
12881290 end
12891291 else # dir
12901292 begin
12911293 FileUtils.remove_entry_secure(File.join(prefix, filename))
12921294 rescue
1293- #logging.error(
1294- # '*** REMOVE FAILED *** : {0}'.format(filename))
1295+ Logging::Logging.error(
1296+ '*** REMOVE FAILED *** : ' + filename)
12951297 end
12961298 end
12971299 }
@@ -1351,7 +1353,7 @@ module Ninix_Main
13511353 end
13521354 end
13531355 rescue IOError => e
1354- #logging.error('cannot read {0}'.format(path))
1356+ Logging::Logging.error('cannot read ' + path)
13551357 end
13561358 end
13571359 ai_list = []
@@ -1400,6 +1402,7 @@ module Ninix_Main
14001402
14011403 class Console
14021404 include GetText
1405+ attr_writer :level
14031406
14041407 def initialize(app)
14051408 @app = app
@@ -1407,9 +1410,8 @@ module Ninix_Main
14071410 @dialog.signal_connect('delete_event') do |w, e|
14081411 #return true # XXX
14091412 end
1410- #@log_handler = logging.handlers.BufferingHandler(0)
1411- #@log_handler.shouldFlush = self.shouldFlush
1412- #logging.getLogger().addHandler(self.log_handler)
1413+ @level = Logger::WARN # XXX
1414+ Logging::Logging.add_logger(self)
14131415 @sw = Gtk::ScrolledWindow.new
14141416 @sw.set_policy(Gtk::PolicyType::NEVER, Gtk::PolicyType::ALWAYS)
14151417 @sw.show()
@@ -1427,9 +1429,9 @@ module Ninix_Main
14271429 @tag_debug = @tb.create_tag(nil, 'foreground' => 'yellow')
14281430 @tag_notset = @tb.create_tag(nil, 'foreground' => 'blue')
14291431 # DnD data types
1430- #dnd_targets = [['text/uri-list', 0, 0]]
1431- #@tv.drag_dest_set(Gtk::Drag::DestDefaults::ALL, dnd_targets,
1432- # Gdk::DragContext::Action::COPY)
1432+ dnd_targets = [['text/uri-list', 0, 0]]
1433+ @tv.drag_dest_set(Gtk::Drag::DestDefaults::ALL, dnd_targets,
1434+ Gdk::DragContext::Action::COPY)
14331435 @tv.drag_dest_set_target_list(nil) # important
14341436 @tv.drag_dest_add_uri_targets()
14351437 @tv.signal_connect('drag_data_received') do |widget, context, x, y, data, info, time|
@@ -1465,48 +1467,80 @@ module Ninix_Main
14651467 @opened = false
14661468 end
14671469
1468- def shouldFlush(record)
1469- it = @tb.get_end_iter()
1470- if record.levelno >= 50
1471- tag = @tag_critical
1472- elsif record.levelno >= 40
1473- tag = @tag_error
1474- elsif record.levelno >= 30
1475- tag = @tag_warning
1476- elsif record.levelno >= 20
1477- tag = @tag_info
1478- elsif record.levelno >= 10
1479- tag = @tag_debug
1480- else
1481- tag = @tag_notset
1482- end
1483- @tb.insert_with_tags(
1484- it,
1485- [record.levelname, ':', record.getMessage(), '\n'].join(''),
1486- tag)
1487- it = @tb.get_end_iter()
1470+ def message_with_tag(message, tag)
1471+ it = @tb.end_iter
1472+ @tb.insert(it, [Logger::SEV_LABEL[@level], ':', message, "\n"].join(""), tag)
1473+ it = @tb.end_iter
14881474 # scroll_to_iter may not have the desired effect.
14891475 mark = @tb.create_mark("end", it, false)
14901476 @tv.scroll_to_mark(mark, 0.0, false, 0.5, 0.5)
14911477 end
14921478
1479+ def info(message)
1480+ if @level > Logger::INFO
1481+ return
1482+ end
1483+ tag = @tag_info
1484+ message_with_tag(message, tag)
1485+ end
1486+
1487+ def debug(message)
1488+ if @level > Logger::DEBUG
1489+ return
1490+ end
1491+ tag = @tag_debug
1492+ message_with_tag(message, tag)
1493+ end
1494+
1495+ def fatal(message)
1496+ if @level > Logger::FATAL
1497+ return
1498+ end
1499+ tag = @tag_critical
1500+ message_with_tag(message, tag)
1501+ end
1502+
1503+ def error(message)
1504+ if @level > Logger::ERROR
1505+ return
1506+ end
1507+ tag = @tag_error
1508+ message_with_tag(message, tag)
1509+ end
1510+
1511+ def warn(message)
1512+ if @level > Logger::WARN
1513+ return
1514+ end
1515+ tag = @tag_warning
1516+ message_with_tag(message, tag)
1517+ end
1518+
1519+ def unknown(message)
1520+ if @level > Logger::UNKNOWN
1521+ return
1522+ end
1523+ tag = @tag_notset
1524+ message_with_tag(message, tag)
1525+ end
1526+
14931527 def update
14941528 ghosts, balloons = @app.search_ghosts() # XXX
14951529 if ghosts > 0 and balloons > 0
14961530 @dialog.set_title(_('Console'))
1497- #logging.info('Ghosts: {0:d}'.format(ghosts))
1498- #logging.info('Balloons: {0:d}'.format(balloons))
1531+ Logging::Logging.info('Ghosts: ' + ghosts.to_s)
1532+ Logging::Logging.info('Balloons: ' + balloons.to_s)
14991533 else
15001534 @dialog.set_title(_('Nanntokashitekudasai.'))
15011535 if ghosts > 0
1502- #logging.info('Ghosts: {0:d}'.format(ghosts))
1536+ Logging::Logging.info('Ghosts: ' + ghosts.to_s)
15031537 else
1504- #logging.warning('Ghosts: {0:d}'.format(ghosts))
1538+ Logging::Logging.warning('Ghosts: ' + ghosts.to_s)
15051539 end
15061540 if balloons > 0
1507- #logging.info('Balloons: {0:d}'.format(balloons))
1541+ Logging::Logging.info('Balloons: ' + balloons.to_s)
15081542 else
1509- #logging.warning('Balloons: {0:d}'.format(balloons))
1543+ Logging::Logging.warning('Balloons: ' + balloons.to_s)
15101544 end
15111545 end
15121546 end
@@ -1763,4 +1797,8 @@ opt.on('--debug', 'debug') {|v| option[:debug] = v}
17631797 opt.on('--logfile logfile_name', 'logfile name') {|v| option[:logfile] = v}
17641798 opt.parse!(ARGV)
17651799
1766-Ninix_Main.main(option)
1800+begin
1801+ Ninix_Main.main(option)
1802+rescue => e # should never rescue Exception
1803+ Ninix_Main.handleException(e)
1804+end