primitivus: use of new logging system:
- default output is \\memory
- logs can be seen with :messages command
- now useless writeLog method has been removed
This commit is contained in:
parent
468206e529
commit
39989cc985
4 changed files with 80 additions and 43 deletions
|
|
@ -79,4 +79,6 @@ class Const(constants.Const):
|
|||
"dnd": (u'✖', "show_dnd"),
|
||||
"xa": (u'☄', "show_xa")
|
||||
}
|
||||
LOG_OPT_SECTION = APP_NAME.lower()
|
||||
LOG_OPT_OUTPUT = ('output', constants.Const.LOG_OPT_OUTPUT_SEP + constants.Const.LOG_OPT_OUTPUT_MEMORY)
|
||||
|
||||
|
|
|
|||
|
|
@ -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.xmlui import XMLUI
|
|||
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 @@ class EditBar(sat_widgets.ModalEdit):
|
|||
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 @@ class PrimitivusApp(QuickApp, InputHistory):
|
|||
|
||||
## 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 @@ class PrimitivusApp(QuickApp, InputHistory):
|
|||
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 @@ class PrimitivusApp(QuickApp, InputHistory):
|
|||
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 @@ class PrimitivusApp(QuickApp, InputHistory):
|
|||
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 @@ class PrimitivusApp(QuickApp, InputHistory):
|
|||
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 @@ class PrimitivusApp(QuickApp, InputHistory):
|
|||
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 @@ class PrimitivusApp(QuickApp, InputHistory):
|
|||
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 @@ class PrimitivusApp(QuickApp, InputHistory):
|
|||
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 @@ class PrimitivusApp(QuickApp, InputHistory):
|
|||
|
||||
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 @@ class PrimitivusApp(QuickApp, InputHistory):
|
|||
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#
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
from sat.core.i18n import _
|
||||
import urwid
|
||||
from urwid_satext.sat_widgets import AdvancedEdit,Password,List,InputDialog,ConfirmDialog,Alert,FocusFrame
|
||||
from urwid_satext.sat_widgets import AdvancedEdit,Password,List,InputDialog,ConfirmDialog,Alert
|
||||
from sat.tools.jid import JID
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -21,7 +21,8 @@ from sat.core.i18n import _
|
|||
import urwid
|
||||
import copy
|
||||
from urwid_satext import sat_widgets
|
||||
from logging import debug, info, warning, error
|
||||
from sat.core.log import getLogger
|
||||
log = getLogger(__name__)
|
||||
from xml.dom import minidom
|
||||
from sat_frontends.tools import xmlui
|
||||
|
||||
|
|
@ -74,7 +75,7 @@ class PrimitivusDividerWidget(xmlui.DividerWidget, urwid.Divider):
|
|||
elif style == 'blank':
|
||||
div_char = ' '
|
||||
else:
|
||||
warning(_("Unknown div_char"))
|
||||
log.warning(_("Unknown div_char"))
|
||||
div_char = u'─'
|
||||
|
||||
urwid.Divider.__init__(self, div_char)
|
||||
|
|
|
|||
Loading…
Reference in a new issue