Getting presence service logging to work.

Don't lose debug state when switching tab.
This commit is contained in:
Marco Pesenti Gritti 2006-08-13 02:57:12 +02:00
parent dd7fff79f8
commit 6eb7117c25
4 changed files with 27 additions and 19 deletions

View File

@ -67,6 +67,8 @@ class ConsoleWindow(gtk.Window):
toolbar.insert(self._debug_toggle, -1) toolbar.insert(self._debug_toggle, -1)
self._debug_toggle.show() self._debug_toggle.show()
self._ignore_toggle = False
vbox.pack_start(toolbar, False) vbox.pack_start(toolbar, False)
toolbar.show() toolbar.show()
@ -101,12 +103,16 @@ class ConsoleWindow(gtk.Window):
return console return console
def __debug_toggled_cb(self, button): def __debug_toggled_cb(self, button):
if not self._ignore_toggle:
console = self._nb.get_nth_page(self._nb.get_current_page()) console = self._nb.get_nth_page(self._nb.get_current_page())
console.set_show_debug(button.get_active()) console.set_show_debug(button.get_active())
def __page_changed_cb(self, notebook, page, page_num): def __page_changed_cb(self, notebook, page, page_num):
console = self._nb.get_nth_page(page_num) console = self._nb.get_nth_page(page_num)
self._ignore_toggle = True
self._debug_toggle.set_active(console.get_show_debug()) self._debug_toggle.set_active(console.get_show_debug())
self._ignore_toggle = False
def set_page(self, page_id): def set_page(self, page_id):
page = self._nb.page_num(self._consoles[page_id]) page = self._nb.page_num(self._consoles[page_id])

View File

@ -16,7 +16,7 @@ import sugar.env
class DbusProcess(Process): class DbusProcess(Process):
def __init__(self): def __init__(self):
config = sugar.env.get_dbus_config() config = sugar.env.get_dbus_config()
cmd = "dbus-launch --exit-with-session --config-file %s" % config cmd = "dbus-daemon --print-address --config-file %s" % config
Process.__init__(self, cmd) Process.__init__(self, cmd)
def get_name(self): def get_name(self):
@ -25,8 +25,7 @@ class DbusProcess(Process):
def start(self): def start(self):
Process.start(self, True) Process.start(self, True)
dbus_file = os.fdopen(self._stdout) dbus_file = os.fdopen(self._stdout)
regexp = re.compile('DBUS_SESSION_BUS_ADDRESS=\'(.*)\'\;') addr = dbus_file.readline().strip()
addr = regexp.match(dbus_file.readline()).group(1)
dbus_file.close() dbus_file.close()
os.environ["DBUS_SESSION_BUS_ADDRESS"] = addr os.environ["DBUS_SESSION_BUS_ADDRESS"] = addr
@ -54,14 +53,14 @@ class Session:
process = DbusProcess() process = DbusProcess()
process.start() process.start()
console = ConsoleWindow()
sugar.logger.start('Shell', console)
PresenceService.start() PresenceService.start()
process = MatchboxProcess() process = MatchboxProcess()
process.start() process.start()
console = ConsoleWindow()
sugar.logger.start('Shell', console)
shell = Shell(self._registry) shell = Shell(self._registry)
shell.set_console(console) shell.set_console(console)
shell.start() shell.start()

View File

@ -4,7 +4,7 @@ import logging
from PresenceService import PresenceService from PresenceService import PresenceService
import sugar.logger import sugar.logger
#sugar.logger.start('PresenceService') sugar.logger.start('PresenceService')
logging.info('Starting presence service') logging.info('Starting presence service')

View File

@ -4,6 +4,7 @@ import traceback
from cStringIO import StringIO from cStringIO import StringIO
import dbus import dbus
import dbus.dbus_bindings
import gobject import gobject
__console = None __console = None
@ -16,33 +17,35 @@ class Handler(logging.Handler):
self._console_id = console_id self._console_id = console_id
self._console = console self._console = console
self._records = [] self._records = []
self._console_started = False self._idle_id = 0
bus = dbus.SessionBus() bus = dbus.SessionBus()
self._console_started = dbus.dbus_bindings.bus_name_has_owner(
bus._connection, 'org.laptop.Sugar.Console')
bus.add_signal_receiver(self.__name_owner_changed, bus.add_signal_receiver(self.__name_owner_changed,
dbus_interface = "org.freedesktop.DBus", dbus_interface = "org.freedesktop.DBus",
signal_name = "NameOwnerChanged") signal_name = "NameOwnerChanged")
def __name_owner_changed(self, service_name, old_name, new_name): def __name_owner_changed(self, service_name, old_name, new_name):
if service_name == 'org.laptop.Sugar.Console':
if new_name != None: if new_name != None:
self._console_started = True self._console_started = True
self._idle_id = gobject.idle_add(self._log)
else: else:
self._console_started = False self._console_started = False
def _log(self): def _log(self):
if not self._console_started:
return True
for record in self._records: for record in self._records:
self._console.log(record.levelno, self._console_id, record.msg) self._console.log(record.levelno, self._console_id, record.msg)
self._records = [] self._records = []
self._idle_id = 0
return False return False
def emit(self, record): def emit(self, record):
self._records.append(record) self._records.append(record)
if len(self._records) == 1: if self._console_started and self._idle_id == 0:
gobject.idle_add(self._log) self._idle_id = gobject.idle_add(self._log)
def __exception_handler(typ, exc, tb): def __exception_handler(typ, exc, tb):
trace = StringIO() trace = StringIO()