Ticket #927: sugar-927.patch
File sugar-927.patch, 13.0 KB (added by alsroot, 15 years ago) |
---|
-
bin/sugar-emulator
From d4a15733f438e204a092fc2338b85ef3e5244cc0 Mon Sep 17 00:00:00 2001 From: Aleksey Lim <alsroot@member.fsf.org> Date: Tue, 6 Oct 2009 16:36:45 +0000 Subject: debug logs for the presence service and connection managers not working #927 --- bin/sugar-emulator | 174 ++----------------------------------------- src/jarabe/util/Makefile.am | 5 +- src/jarabe/util/emulator.py | 166 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 176 insertions(+), 169 deletions(-) mode change 100644 => 100755 bin/sugar-emulator create mode 100644 src/jarabe/util/emulator.py diff --git a/bin/sugar-emulator b/bin/sugar-emulator old mode 100644 new mode 100755 index 99856dc..800ca33
a b 1 #!/usr/bin/env python 2 # Copyright (C) 2006-2008, Red Hat, Inc. 3 # 4 # This program is free software; you can redistribute it and/or modify 5 # it under the terms of the GNU General Public License as published by 6 # the Free Software Foundation; either version 2 of the License, or 7 # (at your option) any later version. 8 # 9 # This program is distributed in the hope that it will be useful, 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 # GNU General Public License for more details. 13 # 14 # You should have received a copy of the GNU General Public License 15 # along with this program; if not, write to the Free Software 16 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 1 #!/bin/sh 17 2 18 import os 19 import random 20 import subprocess 21 import time 22 from optparse import OptionParser 3 # Source debug definitions 4 if [ -f ~/.sugar/debug ]; then 5 . ~/.sugar/debug 6 fi 23 7 24 import gtk 25 import gobject 26 27 from sugar import env 28 29 default_dimensions = (800, 600) 30 def _run_xephyr(display, dpi, dimensions, fullscreen): 31 cmd = [ 'Xephyr' ] 32 cmd.append(':%d' % display) 33 cmd.append('-ac') 34 35 screen_size = (gtk.gdk.screen_width(), gtk.gdk.screen_height()) 36 37 if (not dimensions) and (fullscreen is None) and \ 38 (screen_size < default_dimensions) : 39 # no forced settings, screen too small => fit screen 40 fullscreen = True 41 elif (not dimensions) : 42 # screen is big enough or user has en/disabled fullscreen manually 43 # => use default size (will get ignored for fullscreen) 44 dimensions = '%dx%d' % default_dimensions 45 46 if not dpi : 47 dpi = gtk.settings_get_default().get_property('gtk-xft-dpi') / 1024 48 49 if fullscreen : 50 cmd.append('-fullscreen') 51 52 if dimensions : 53 cmd.append('-screen') 54 cmd.append(dimensions) 55 56 if dpi : 57 cmd.append('-dpi') 58 cmd.append('%d' % dpi) 59 60 result = gobject.spawn_async(cmd, flags=gobject.SPAWN_SEARCH_PATH) 61 pid = result[0] 62 63 os.environ['DISPLAY'] = ":%d" % (display) 64 os.environ['SUGAR_EMULATOR_PID'] = str(pid) 65 66 def _check_xephyr(display): 67 result = subprocess.call(['xdpyinfo', '-display', ':%d' % display], 68 stdout=open(os.devnull, "w"), 69 stderr=open(os.devnull, "w")) 70 return result == 0 71 72 def _start_xephyr(dpi, dimensions, fullscreen): 73 # FIXME evil workaround until F10 Xephyr is fixed 74 if os.path.exists('/etc/fedora-release'): 75 if open('/etc/fedora-release').read().startswith('Fedora release 10'): 76 display = random.randint(100, 500) 77 _run_xephyr(display, dpi, dimensions, fullscreen) 78 return display 79 80 for display in range(100, 110): 81 if not _check_xephyr(display): 82 _run_xephyr(display, dpi, dimensions, fullscreen) 83 84 tries = 10 85 while tries > 0: 86 if _check_xephyr(display): 87 return display 88 else: 89 tries -= 1 90 time.sleep(0.1) 91 92 def _start_window_manager(display): 93 cmd = ['metacity'] 94 95 cmd.extend(['--no-force-fullscreen', '-d', ':%d' % display]) 96 97 gobject.spawn_async(cmd, flags=gobject.SPAWN_SEARCH_PATH) 98 99 def _setup_env(): 100 os.environ['SUGAR_EMULATOR'] = 'yes' 101 os.environ['GABBLE_LOGFILE'] = os.path.join( 102 env.get_profile_path(), 'logs', 'telepathy-gabble.log') 103 os.environ['SALUT_LOGFILE'] = os.path.join( 104 env.get_profile_path(), 'logs', 'telepathy-salut.log') 105 os.environ['STREAM_ENGINE_LOGFILE'] = os.path.join( 106 env.get_profile_path(), 'logs', 'telepathy-stream-engine.log') 107 108 path = os.path.join(os.environ.get("HOME"), '.i18n') 109 if os.path.exists(path): 110 fd = open(path, "r") 111 lines = fd.readlines() 112 fd.close() 113 114 language_env_variable = None 115 lang_env_variable = None 116 117 for line in lines: 118 if line.startswith("LANGUAGE="): 119 lang = line[9:].replace('"', '') 120 language_env_variable = lang.strip() 121 elif line.startswith("LANG="): 122 lang_env_variable = line[5:].replace('"', '') 123 124 # There might be cases where .i18n may not contain a LANGUAGE field 125 if language_env_variable is not None: 126 os.environ['LANGUAGE'] = language_env_variable 127 if lang_env_variable is not None: 128 os.environ['LANG'] = lang_env_variable 129 130 def main(): 131 """Script-level operations""" 132 133 parser = OptionParser() 134 parser.add_option('-d', '--dpi', dest='dpi', type="int", 135 help='Emulator dpi') 136 parser.add_option('-s', '--scaling', dest='scaling', 137 help='Sugar scaling in %') 138 parser.add_option('-i', '--dimensions', dest='dimensions', 139 help='Emulator dimensions (ex. 1200x900)') 140 parser.add_option('-f', '--fullscreen', dest='fullscreen', 141 action='store_true', default=None, 142 help='Run emulator in fullscreen mode') 143 parser.add_option('-F', '--no-fullscreen', dest='fullscreen', 144 action='store_false', 145 help='Do not run emulator in fullscreen mode') 146 (options, args) = parser.parse_args() 147 148 _setup_env() 149 150 display = _start_xephyr(options.dpi, options.dimensions, options.fullscreen) 151 152 if options.scaling: 153 os.environ['SUGAR_SCALING'] = options.scaling 154 155 command = ['dbus-launch', 'dbus-launch', '--exit-with-session'] 156 157 if not args: 158 command.extend(['sugar', '-d', ':%d' % display]) 159 else: 160 _start_window_manager(display) 161 162 if args[0].endswith('.py'): 163 command.append('python') 164 165 command.append(args[0]) 166 167 os.execlp(*command) 168 169 main() 8 # Start emulator 9 python -c "import sys; from jarabe.util import emulator; sys.argv[0]='$0'; emulator.main()" "$@" -
src/jarabe/util/Makefile.am
diff --git a/src/jarabe/util/Makefile.am b/src/jarabe/util/Makefile.am index 4046fe8..8bda3d6 100644
a b SUBDIRS = \ 2 2 telepathy 3 3 4 4 sugardir = $(pythondir)/jarabe/util 5 sugar_PYTHON = \ 6 __init__.py 5 sugar_PYTHON = \ 6 __init__.py \ 7 emulator.py -
new file src/jarabe/util/emulator.py
diff --git a/src/jarabe/util/emulator.py b/src/jarabe/util/emulator.py new file mode 100644 index 0000000..d2dacb5
- + 1 # Copyright (C) 2006-2008, Red Hat, Inc. 2 # 3 # This program is free software; you can redistribute it and/or modify 4 # it under the terms of the GNU General Public License as published by 5 # the Free Software Foundation; either version 2 of the License, or 6 # (at your option) any later version. 7 # 8 # This program is distributed in the hope that it will be useful, 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 # GNU General Public License for more details. 12 # 13 # You should have received a copy of the GNU General Public License 14 # along with this program; if not, write to the Free Software 15 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 17 import os 18 import random 19 import subprocess 20 import time 21 from optparse import OptionParser 22 23 import gtk 24 import gobject 25 26 from sugar import env 27 28 default_dimensions = (800, 600) 29 def _run_xephyr(display, dpi, dimensions, fullscreen): 30 cmd = [ 'Xephyr' ] 31 cmd.append(':%d' % display) 32 cmd.append('-ac') 33 34 screen_size = (gtk.gdk.screen_width(), gtk.gdk.screen_height()) 35 36 if (not dimensions) and (fullscreen is None) and \ 37 (screen_size < default_dimensions) : 38 # no forced settings, screen too small => fit screen 39 fullscreen = True 40 elif (not dimensions) : 41 # screen is big enough or user has en/disabled fullscreen manually 42 # => use default size (will get ignored for fullscreen) 43 dimensions = '%dx%d' % default_dimensions 44 45 if not dpi : 46 dpi = gtk.settings_get_default().get_property('gtk-xft-dpi') / 1024 47 48 if fullscreen : 49 cmd.append('-fullscreen') 50 51 if dimensions : 52 cmd.append('-screen') 53 cmd.append(dimensions) 54 55 if dpi : 56 cmd.append('-dpi') 57 cmd.append('%d' % dpi) 58 59 result = gobject.spawn_async(cmd, flags=gobject.SPAWN_SEARCH_PATH) 60 pid = result[0] 61 62 os.environ['DISPLAY'] = ":%d" % (display) 63 os.environ['SUGAR_EMULATOR_PID'] = str(pid) 64 65 def _check_xephyr(display): 66 result = subprocess.call(['xdpyinfo', '-display', ':%d' % display], 67 stdout=open(os.devnull, "w"), 68 stderr=open(os.devnull, "w")) 69 return result == 0 70 71 def _start_xephyr(dpi, dimensions, fullscreen): 72 # FIXME evil workaround until F10 Xephyr is fixed 73 if os.path.exists('/etc/fedora-release'): 74 if open('/etc/fedora-release').read().startswith('Fedora release 10'): 75 display = random.randint(100, 500) 76 _run_xephyr(display, dpi, dimensions, fullscreen) 77 return display 78 79 for display in range(100, 110): 80 if not _check_xephyr(display): 81 _run_xephyr(display, dpi, dimensions, fullscreen) 82 83 tries = 10 84 while tries > 0: 85 if _check_xephyr(display): 86 return display 87 else: 88 tries -= 1 89 time.sleep(0.1) 90 91 def _start_window_manager(display): 92 cmd = ['metacity'] 93 94 cmd.extend(['--no-force-fullscreen', '-d', ':%d' % display]) 95 96 gobject.spawn_async(cmd, flags=gobject.SPAWN_SEARCH_PATH) 97 98 def _setup_env(): 99 os.environ['SUGAR_EMULATOR'] = 'yes' 100 os.environ['GABBLE_LOGFILE'] = os.path.join( 101 env.get_profile_path(), 'logs', 'telepathy-gabble.log') 102 os.environ['SALUT_LOGFILE'] = os.path.join( 103 env.get_profile_path(), 'logs', 'telepathy-salut.log') 104 os.environ['STREAM_ENGINE_LOGFILE'] = os.path.join( 105 env.get_profile_path(), 'logs', 'telepathy-stream-engine.log') 106 107 path = os.path.join(os.environ.get("HOME"), '.i18n') 108 if os.path.exists(path): 109 fd = open(path, "r") 110 lines = fd.readlines() 111 fd.close() 112 113 language_env_variable = None 114 lang_env_variable = None 115 116 for line in lines: 117 if line.startswith("LANGUAGE="): 118 lang = line[9:].replace('"', '') 119 language_env_variable = lang.strip() 120 elif line.startswith("LANG="): 121 lang_env_variable = line[5:].replace('"', '') 122 123 # There might be cases where .i18n may not contain a LANGUAGE field 124 if language_env_variable is not None: 125 os.environ['LANGUAGE'] = language_env_variable 126 if lang_env_variable is not None: 127 os.environ['LANG'] = lang_env_variable 128 129 def main(): 130 """Script-level operations""" 131 132 parser = OptionParser() 133 parser.add_option('-d', '--dpi', dest='dpi', type="int", 134 help='Emulator dpi') 135 parser.add_option('-s', '--scaling', dest='scaling', 136 help='Sugar scaling in %') 137 parser.add_option('-i', '--dimensions', dest='dimensions', 138 help='Emulator dimensions (ex. 1200x900)') 139 parser.add_option('-f', '--fullscreen', dest='fullscreen', 140 action='store_true', default=None, 141 help='Run emulator in fullscreen mode') 142 parser.add_option('-F', '--no-fullscreen', dest='fullscreen', 143 action='store_false', 144 help='Do not run emulator in fullscreen mode') 145 (options, args) = parser.parse_args() 146 147 _setup_env() 148 149 display = _start_xephyr(options.dpi, options.dimensions, options.fullscreen) 150 151 if options.scaling: 152 os.environ['SUGAR_SCALING'] = options.scaling 153 154 command = ['dbus-launch', 'dbus-launch', '--exit-with-session'] 155 156 if not args: 157 command.extend(['sugar', '-d', ':%d' % display]) 158 else: 159 _start_window_manager(display) 160 161 if args[0].endswith('.py'): 162 command.append('python') 163 164 command.append(args[0]) 165 166 os.execlp(*command)