Move session stuff to his own package

This commit is contained in:
Marco Pesenti Gritti
2006-08-11 11:37:35 +02:00
parent 27456ff723
commit cb47f17b31
8 changed files with 13 additions and 9 deletions
+75
View File
@@ -0,0 +1,75 @@
import logging
import os
import socket
import sys
from session.Process import Process
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))
logging.info('Display %d is already in use. Trying next.' % (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 640x480' % (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 640x480' % (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 __init__(self):
pass
def start(self):
try:
process = XephyrProcess()
process.start()
except:
try:
process = XnestProcess()
process.start()
except:
logging.error('Cannot run the emulator. You need to install \
Xephyr or Xnest.')
sys.exit(0)
+6
View File
@@ -0,0 +1,6 @@
sugardir = $(pkgdatadir)/shell/session
sugar_PYTHON = \
__init__.py \
Emulator.py \
Process.py \
Session.py
+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]
+82
View File
@@ -0,0 +1,82 @@
import os
import gtk
import gobject
import time
import dbus
import dbus.dbus_bindings
from sugar.presence import PresenceService
from Shell import Shell
from session.Process import Process
import sugar.env
class DbusProcess(Process):
def __init__(self):
config = sugar.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()
addr = addr.strip()
dbus_file.close()
os.environ["DBUS_SESSION_BUS_ADDRESS"] = addr
class MatchboxProcess(Process):
def __init__(self):
options = '-use_titlebar no'
kbd_config = os.path.join(sugar.env.get_data_dir(), 'kbdconfig')
options += ' -kbdconfig %s' % kbd_config
command = 'matchbox-window-manager %s' % options
print command
Process.__init__(self, command)
def get_name(self):
return 'Matchbox'
class PresenceServiceProcess(Process):
def __init__(self):
Process.__init__(self, "sugar-presence-service")
def get_name(self):
return "PresenceService"
def start(self):
Process.start(self)
bus = dbus.Bus()
ret = False
# Wait for the presence service to start up
while not ret:
ret = dbus.dbus_bindings.bus_name_has_owner(bus._connection, PresenceService.DBUS_SERVICE)
time.sleep(0.2)
class Session:
"""Takes care of running the shell and all the sugar processes"""
def __init__(self, registry):
self._registry = registry
def start(self):
"""Start the session"""
process = DbusProcess()
process.start()
process = MatchboxProcess()
process.start()
process = PresenceServiceProcess()
process.start()
shell = Shell(self._registry)
shell.start()
try:
gtk.main()
except KeyboardInterrupt:
print 'Ctrl+C pressed, exiting...'
View File