Make part of the session public so that it can used by tests

This commit is contained in:
Marco Pesenti Gritti
2006-09-10 02:35:53 +02:00
parent f4f70d22f1
commit 47cc58b1e6
12 changed files with 59 additions and 49 deletions
+20
View File
@@ -0,0 +1,20 @@
import os
from sugar.session.Process import Process
from sugar import env
class DbusProcess(Process):
def __init__(self):
config = env.get_dbus_config()
cmd = "dbus-daemon --print-address --config-file %s" % config
Process.__init__(self, cmd)
def get_name(self):
return 'Dbus'
def start(self):
Process.start(self, True)
dbus_file = os.fdopen(self._stdout)
addr = dbus_file.readline().strip()
dbus_file.close()
os.environ["DBUS_SESSION_BUS_ADDRESS"] = addr
+70
View File
@@ -0,0 +1,70 @@
import os
import socket
import sys
from sugar.session.Process import Process
import sugar.env
def get_display_number():
"""Find a free display number trying to connect to 6000+ ports"""
retries = 20
display_number = 1
display_is_free = False
while not display_is_free and retries > 0:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
s.connect(('127.0.0.1', 6000 + display_number))
s.close()
display_number += 1
retries -= 1
except:
display_is_free = True
if display_is_free:
return display_number
else:
logging.error('Cannot find a free display.')
sys.exit(0)
class XephyrProcess(Process):
def __init__(self):
self._display = get_display_number()
cmd = 'Xephyr :%d -ac -screen 800x600' % (self._display)
Process.__init__(self, cmd)
def get_name(self):
return 'Xephyr'
def start(self):
Process.start(self)
os.environ['DISPLAY'] = ":%d" % (self._display)
class XnestProcess(Process):
def __init__(self):
self._display = get_display_number()
cmd = 'Xnest :%d -ac -geometry 800x600' % (self._display)
Process.__init__(self, cmd)
def get_name(self):
return 'Xnest'
def start(self):
Process.start(self)
os.environ['DISPLAY'] = ":%d" % (self._display)
class Emulator:
"""The OLPC emulator"""
def start(self):
try:
process = XephyrProcess()
process.start()
except:
try:
process = XnestProcess()
process.start()
except:
print 'Cannot run the emulator. You need to install \
Xephyr or Xnest.'
sys.exit(0)
+7
View File
@@ -0,0 +1,7 @@
sugardir = $(pythondir)/sugar/session
sugar_PYTHON = \
__init__.py \
DbusProcess.py \
Emulator.py \
MatchboxProcess.py \
Process.py
+17
View File
@@ -0,0 +1,17 @@
import os
from sugar.session.Process import Process
from sugar import env
class MatchboxProcess(Process):
def __init__(self):
kbd_config = os.path.join(env.get_data_dir(), 'kbdconfig')
options = '-kbdconfig %s ' % kbd_config
options += '-theme olpc '
command = 'matchbox-window-manager %s ' % options
Process.__init__(self, command)
def get_name(self):
return 'Matchbox'
+19
View File
@@ -0,0 +1,19 @@
import logging
import gobject
class Process:
"""Object representing one of the session processes"""
def __init__(self, command):
self._command = command
def get_name(self):
return self._command
def start(self, standard_output=False):
args = self._command.split()
flags = gobject.SPAWN_SEARCH_PATH
result = gobject.spawn_async(args, flags=flags,
standard_output=standard_output)
self._stdout = result[2]
View File