From 2ae62db4cc64445ba235edc87ce7482f38f3fa4c Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Wed, 17 May 2006 00:12:01 -0400 Subject: [PATCH] Enable the console only when running from source path. --- sugar/browser/browser.py | 5 +++-- sugar/chat/chat.py | 7 ++++--- sugar/session/session.py | 9 ++++++--- sugar/sugar | 18 ++++++++++++------ 4 files changed, 25 insertions(+), 14 deletions(-) diff --git a/sugar/browser/browser.py b/sugar/browser/browser.py index f311ba14..fbf9a8fd 100755 --- a/sugar/browser/browser.py +++ b/sugar/browser/browser.py @@ -318,8 +318,9 @@ class BrowserShell(dbus.service.Object): self.__browsers.append(browser) browser.activity_connect_to_shell() -sys.stdout = LogWriter("Web Browser") -sys.stderr = LogWriter("Web Browser") +if len(sys.argv) > 1 and sys.argv[1] == "--console": + sys.stdout = LogWriter("Web Browser") + sys.stderr = LogWriter("Web Browser") BrowserShell.get_instance().open_web_activity() gtk.main() diff --git a/sugar/chat/chat.py b/sugar/chat/chat.py index 0ed0e1ce..e23b3475 100755 --- a/sugar/chat/chat.py +++ b/sugar/chat/chat.py @@ -398,9 +398,10 @@ class ChatShell(dbus.service.Object): @dbus.service.method('com.redhat.Sugar.ChatShell') def send_message(self, message): self._group_chat.send_message(message) - -sys.stdout = LogWriter("Chat") -sys.stderr = LogWriter("Chat") + +if len(sys.argv) > 1 and sys.argv[1] == "--console": + sys.stdout = LogWriter("Chat") + sys.stderr = LogWriter("Chat") ChatShell.get_instance().open_group_chat() gtk.main() diff --git a/sugar/session/session.py b/sugar/session/session.py index c3043af7..9b082b70 100644 --- a/sugar/session/session.py +++ b/sugar/session/session.py @@ -7,12 +7,15 @@ import gtk from sugar.shell import shell -def start(): +def start(console): shell.main() - + print 'aaaa' activities = ['sugar/chat/chat', 'sugar/browser/browser'] for activity in activities: - os.spawnvp(os.P_NOWAIT, 'python', [ 'python', '-m', activity ]) + args = [ 'python', '-m', activity ] + if console: + args.append('--console') + os.spawnvp(os.P_NOWAIT, 'python', args) gtk.main() diff --git a/sugar/sugar b/sugar/sugar index b293f19b..023e3f60 100755 --- a/sugar/sugar +++ b/sugar/sugar @@ -9,18 +9,24 @@ if curdir == '.': basedir = os.path.dirname(os.getcwd()) else: basedir = os.path.dirname(curdir) - + +console = False + if os.path.isfile(os.path.join(curdir, '__uninstalled__.py')): if basedir == '': - print "Running sugar from current directory..." + print 'Running sugar from current directory...' else: - print "Running sugar from " + basedir + " ..." - sys.path.append(basedir) + print 'Running sugar from ' + basedir + ' ...' + sys.path.insert(0, basedir) os.environ['PYTHONPATH'] = basedir + console = True else: - print "Running the installed sugar..." + print 'Running the installed sugar...' + +if console: + print 'Redirecting output to the console, press ctrl+d to open it.' from sugar.session import session -session.start() +session.start(console)