From 03af8bceea40471a022a8a46c5d8a7121edb8100 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Tue, 23 May 2006 16:02:13 -0400 Subject: [PATCH] Simplify redirecting output to the console --- sugar/browser/browser.py | 5 ++--- sugar/chat/chat.py | 20 +++++++------------- sugar/session/LogWriter.py | 8 ++++++++ sugar/session/session.py | 4 +--- sugar/sugar | 3 ++- 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/sugar/browser/browser.py b/sugar/browser/browser.py index f67f4a46..2ad61318 100755 --- a/sugar/browser/browser.py +++ b/sugar/browser/browser.py @@ -355,9 +355,8 @@ class BrowserShell(dbus.service.Object): self.__browsers.append(browser) browser.activity_connect_to_shell() -if len(sys.argv) > 1 and sys.argv[1] == "--console": - sys.stdout = LogWriter("Web") - sys.stderr = LogWriter("Web") +log_writer = LogWriter("Web") +log_writer.start() gtk.rc_parse(sugar.env.get_data_file('browser.rc')) diff --git a/sugar/chat/chat.py b/sugar/chat/chat.py index 0a165fd2..02b05681 100755 --- a/sugar/chat/chat.py +++ b/sugar/chat/chat.py @@ -696,17 +696,11 @@ class ChatShell(dbus.service.Object): def send_text_message(self, message): self._group_chat.send_text_message(message) +log_writer = LogWriter("Chat") +log_writer.start() -def main(): - if len(sys.argv) > 1 and sys.argv[1] == "--console": - sys.stdout = LogWriter("Chat") - sys.stderr = LogWriter("Chat") - - ChatShell.get_instance().open_group_chat() - try: - gtk.main() - except KeyboardInterrupt: - pass - -if __name__ == "__main__": - main() +ChatShell.get_instance().open_group_chat() +try: + gtk.main() +except KeyboardInterrupt: + pass diff --git a/sugar/session/LogWriter.py b/sugar/session/LogWriter.py index 92cbf652..7c6be751 100644 --- a/sugar/session/LogWriter.py +++ b/sugar/session/LogWriter.py @@ -1,3 +1,6 @@ +import os +import sys + import dbus class LogWriter: @@ -7,6 +10,11 @@ class LogWriter: proxy_obj = bus.get_object('com.redhat.Sugar.Logger', '/com/redhat/Sugar/Logger') self._logger = dbus.Interface(proxy_obj, 'com.redhat.Sugar.Logger') + def start(self): + if os.environ.has_key('SUGAR_USE_CONSOLE'): + sys.stdout = self + sys.stderr = self + def write(self, s): try: self._logger.log(self._application, s) diff --git a/sugar/session/session.py b/sugar/session/session.py index 4d57a208..96ed29e1 100644 --- a/sugar/session/session.py +++ b/sugar/session/session.py @@ -9,7 +9,7 @@ import gtk from sugar.shell import shell from sugar import env -def start(console): +def start(): shell.main() activities = [] @@ -34,8 +34,6 @@ def start(console): for activity in activities: args = [ 'python', '-m', activity ] - if console: - args.append('--console') os.spawnvp(os.P_NOWAIT, 'python', args) try: diff --git a/sugar/sugar b/sugar/sugar index c1c42525..f6340894 100755 --- a/sugar/sugar +++ b/sugar/sugar @@ -68,11 +68,12 @@ else: append_to_python_path(os.path.expanduser('~/.sugar/activities')) if console: + os.environ['SUGAR_USE_CONSOLE'] = 'yes' print 'Redirecting output to the console, press ctrl+d to open it.' from sugar.session import session -session.start(console) +session.start() if dbus_daemon_pid: stop_dbus(dbus_daemon_pid)