diff frontends/src/primitivus/primitivus @ 1010:73a0b7f94674

primitivus: use of new logging system: - default output is \\memory - logs can be seen with :messages command - now useless writeLog method has been removed
author Goffi <goffi@goffi.org>
date Mon, 05 May 2014 20:12:19 +0200
parents 6f1e03068b5f
children 6a16ec17a458
line wrap: on
line diff
--- a/frontends/src/primitivus/primitivus	Mon May 05 18:58:34 2014 +0200
+++ b/frontends/src/primitivus/primitivus	Mon May 05 20:12:19 2014 +0200
@@ -19,6 +19,10 @@
 
 
 from sat.core.i18n import _
+from sat_frontends.primitivus.constants import Const as C
+from sat.core import log as logging
+logging.satConfigure(C.LOG_BACKEND_STANDARD, C)
+log = logging.getLogger(__name__)
 import urwid
 from urwid_satext import sat_widgets
 from urwid_satext.files_management import FileDialog
@@ -32,19 +36,11 @@
 from sat_frontends.primitivus.progress import Progress
 from sat_frontends.primitivus.notify import Notify
 from sat_frontends.tools.misc import InputHistory
-from sat_frontends.primitivus.constants import Const
-from sat_frontends.constants import Const as commonConst
-import logging
-from logging import debug, info, error
+from sat_frontends.constants import Const as commonConst # FIXME
 from sat.tools.jid  import JID
 from os.path import join
 
 
-### logging configuration FIXME: put this elsewhere ###
-logging.basicConfig(level=logging.CRITICAL,  #TODO: configure it to put messages in a log file
-                    format='%(message)s')
-###
-
 class ChatList(QuickChatList):
     """This class manage the list of chat windows"""
 
@@ -119,6 +115,9 @@
         if command == 'quit':
             self.app.onExit()
             raise urwid.ExitMainLoop()
+        elif command == 'messages':
+            wid = sat_widgets.GenericList(logging.memoryGet())
+            self.app.addWindow(wid)
         elif command == 'presence':
             self.app.status_bar.onPresenceClick()
         elif command in ['presence %s' % show for show in commonConst.PRESENCE.keys()]:
@@ -166,7 +165,7 @@
 
         ## main loop setup ##
         self.main_widget = ProfileManager(self)
-        self.loop = urwid.MainLoop(self.main_widget, Const.PALETTE, event_loop=urwid.GLibEventLoop(), input_filter=self.inputFilter, unhandled_input=self.keyHandler)
+        self.loop = urwid.MainLoop(self.main_widget, C.PALETTE, event_loop=urwid.GLibEventLoop(), input_filter=self.inputFilter, unhandled_input=self.keyHandler)
 
         ##misc setup##
         self.chat_wins = ChatList(self)
@@ -187,25 +186,25 @@
         self.editBar.mode = value
 
     def modeHint(self, value):
-        """Change mode if make sens (i.e.: if there is nothing in the editBar"""
+        """Change mode if make sens (i.e.: if there is nothing in the editBar)"""
         if not self.editBar.get_edit_text():
             self.mode = value
 
     def debug(self):
-        """convenient method to reset screen and launch p(u)db"""
+        """convenient method to reset screen and launch (i)p(u)db"""
+        log.info('Entered debug mode')
         try:
             import pudb
             pudb.set_trace()
-        except:
-            import os,pdb
+        except ImportError:
+            import os
             os.system('reset')
-            print 'Entered debug mode'
-            pdb.set_trace()
-
-    def writeLog(self, log, file_name='/tmp/primitivus_log'):
-        """method to write log in a temporary file, useful for debugging"""
-        with open(file_name, 'a') as f:
-            f.write(log+"\n")
+            try:
+                import ipdb
+                ipdb.set_trace()
+            except ImportError:
+                import pdb
+                pdb.set_trace()
 
     def redraw(self):
         """redraw the screen"""
@@ -296,7 +295,7 @@
         menu.addMenu(communication, _("Join room"), self.onJoinRoomRequest, 'meta j')
         #additionals menus
         #FIXME: do this in a more generic way (in quickapp)
-        add_menus = self.bridge.getMenus('', Const.NO_SECURITY_LIMIT)
+        add_menus = self.bridge.getMenus('', C.NO_SECURITY_LIMIT)
         def add_menu_cb(callback_id):
             self.launchAction(callback_id, None, profile_key = self.profile)
         for id_, type_, path, path_i18n  in add_menus:
@@ -417,7 +416,7 @@
                     no_cb=self._dialogCancelCb, no_value = (answer_cb, answer_data))
         else:
             popup = sat_widgets.Alert(unicode(title), unicode(message), ok_cb=answer_cb or self.removePopUp) #FIXME: remove unicode here when DBus Bridge will no return dbus.String anymore
-            error(_('unmanaged dialog type: %s'), type_)
+            log.error(_('unmanaged dialog type: %s'), type_)
         self.showPopUp(popup)
 
     def onNotification(self, notBar):
@@ -432,7 +431,7 @@
                 self.main_widget.footer = pile
         else:
             if not isinstance(self.main_widget.footer, urwid.Pile):
-                error(_("INTERNAL ERROR: Unexpected class for main widget's footer"))
+                log.error(_("INTERNAL ERROR: Unexpected class for main widget's footer"))
                 assert(False)
             if self.notBar.canHide():
                 #No notification left, we can hide the bar
@@ -499,13 +498,13 @@
             return
 
         if not id in self.current_action_ids:
-            debug (_('unknown id, ignoring'))
+            log.debug (_('unknown id, ignoring'))
             return
         if type_ == "SUPPRESS":
             self.current_action_ids.remove(id)
         elif type_ == "XMLUI":
             self.current_action_ids.remove(id)
-            debug (_("XML user interface received"))
+            log.debug (_("XML user interface received"))
             misc = {}
             #FIXME FIXME FIXME: must clean all this crap !
             title = _('Form')
@@ -534,7 +533,7 @@
                 del self.current_action_ids_cb[id]
                 callback(data)
         else:
-            error (_("FIXME FIXME FIXME: type [%s] not implemented") % type_)
+            log.error (_("FIXME FIXME FIXME: type [%s] not implemented") % type_)
             raise NotImplementedError
 
     ##DIALOGS CALLBACKS##
@@ -545,7 +544,7 @@
             self.bridge.joinMUC(room_jid, self.profiles[self.profile]['whoami'].node, {}, self.profile)
         else:
             message = _("'%s' is an invalid JID !") % room_jid
-            error (message)
+            log.error (message)
             self.showPopUp(sat_widgets.Alert(_("Error"), message, ok_cb=self.removePopUp))
 
     #MENU EVENTS#
@@ -561,7 +560,7 @@
 
         def failure(error):
             self.showPopUp(sat_widgets.Alert(_("Error"), _("Can't get parameters"), ok_cb=self.removePopUp))
-        self.bridge.getParamsUI(app=Const.APP_NAME, profile_key=self.profile, callback=success, errback=failure)
+        self.bridge.getParamsUI(app=C.APP_NAME, profile_key=self.profile, callback=success, errback=failure)
 
     def onExitRequest(self, menu):
         QuickApp.onExit(self)
@@ -573,7 +572,7 @@
         self.showPopUp(pop_up_widget)
 
     def onAboutRequest(self, menu):
-        self.showPopUp(sat_widgets.Alert(_("About"), Const.APP_NAME + " v" + self.bridge.getVersion(), ok_cb=self.removePopUp))
+        self.showPopUp(sat_widgets.Alert(_("About"), C.APP_NAME + " v" + self.bridge.getVersion(), ok_cb=self.removePopUp))
 
     #MISC CALLBACKS#