Refactor startup. In progress, give me a couple hours.
For now start sugar with "sugar-emulator shell/sugar-shell"master
parent
a3be4492b2
commit
bc0ee6d34c
@ -1,76 +0,0 @@
|
||||
# Copyright (C) 2006, Red Hat, Inc.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
import os
|
||||
from ConfigParser import ConfigParser
|
||||
|
||||
from sugar.graphics import iconcolor
|
||||
from sugar import env
|
||||
|
||||
class _Profile:
|
||||
def __init__(self,):
|
||||
self._path = env.get_profile_path()
|
||||
self._nick_name = None
|
||||
self._color = iconcolor.IconColor()
|
||||
|
||||
self._ensure_dirs()
|
||||
|
||||
cp = ConfigParser()
|
||||
parsed = cp.read([self._get_config_path()])
|
||||
|
||||
if cp.has_option('Buddy', 'NickName'):
|
||||
self._nick_name = cp.get('Buddy', 'NickName')
|
||||
if cp.has_option('Buddy', 'Color'):
|
||||
color = cp.get('Buddy', 'Color')
|
||||
if iconcolor.is_valid(color):
|
||||
self._color = iconcolor.IconColor(color)
|
||||
|
||||
def _ensure_dirs(self):
|
||||
try:
|
||||
os.makedirs(self._path)
|
||||
except OSError, exc:
|
||||
if exc[0] != 17: # file exists
|
||||
print "Could not create user directory."
|
||||
|
||||
def get_color(self):
|
||||
return self._color
|
||||
|
||||
def set_color(self, color):
|
||||
self._color = color
|
||||
|
||||
def get_nick_name(self):
|
||||
return self._nick_name
|
||||
|
||||
def set_nick_name(self, nick_name):
|
||||
self._nick_name = nick_name
|
||||
|
||||
def get_path(self):
|
||||
return self._path
|
||||
|
||||
def save(self):
|
||||
cp = ConfigParser()
|
||||
|
||||
section = 'Buddy'
|
||||
cp.add_section(section)
|
||||
cp.set(section, 'NickName', self._nick_name)
|
||||
cp.set(section, 'Color', self._color.to_string())
|
||||
|
||||
fileobject = open(self._get_config_path(), 'w')
|
||||
cp.write(fileobject)
|
||||
fileobject.close()
|
||||
|
||||
def _get_config_path(self):
|
||||
return os.path.join(self._path, 'config')
|
@ -1,11 +1,6 @@
|
||||
from conf.ActivityRegistry import _ActivityRegistry
|
||||
from conf.Profile import _Profile
|
||||
|
||||
__registry = _ActivityRegistry()
|
||||
__profile = _Profile()
|
||||
_activity_registry = _ActivityRegistry()
|
||||
|
||||
def get_activity_registry():
|
||||
return __registry
|
||||
|
||||
def get_profile():
|
||||
return __profile
|
||||
return _activity_registry
|
||||
|
@ -0,0 +1,43 @@
|
||||
# Copyright (C) 2006, Red Hat, Inc.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
import os
|
||||
from ConfigParser import ConfigParser
|
||||
|
||||
from sugar import env
|
||||
from sugar.graphics.iconcolor import IconColor
|
||||
|
||||
def get_nick_name():
|
||||
return _nick_name
|
||||
|
||||
def get_color():
|
||||
return _color
|
||||
|
||||
cp = ConfigParser()
|
||||
config_path = os.path.join(env.get_profile_path(), 'config')
|
||||
parsed = cp.read([config_path])
|
||||
|
||||
if cp.has_option('Buddy', 'NickName'):
|
||||
_nick_name = cp.get('Buddy', 'NickName')
|
||||
else:
|
||||
_nick_name = None
|
||||
|
||||
if cp.has_option('Buddy', 'Color'):
|
||||
_color = IconColor(cp.get('Buddy', 'Color'))
|
||||
else:
|
||||
_color = None
|
||||
|
||||
del cp
|
@ -1,37 +0,0 @@
|
||||
# Copyright (C) 2006, Red Hat, Inc.
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This library is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public
|
||||
# License along with this library; if not, write to the
|
||||
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
# Boston, MA 02111-1307, USA.
|
||||
|
||||
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
|
@ -1,87 +0,0 @@
|
||||
# Copyright (C) 2006, Red Hat, Inc.
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This library is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public
|
||||
# License along with this library; if not, write to the
|
||||
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
# Boston, MA 02111-1307, USA.
|
||||
|
||||
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)
|
@ -1,9 +0,0 @@
|
||||
sugardir = $(pythondir)/sugar/session
|
||||
sugar_PYTHON = \
|
||||
__init__.py \
|
||||
DbusProcess.py \
|
||||
Emulator.py \
|
||||
MatchboxProcess.py \
|
||||
Process.py \
|
||||
TestSession.py \
|
||||
UITestSession.py
|
@ -1,35 +0,0 @@
|
||||
# Copyright (C) 2006, Red Hat, Inc.
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This library is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public
|
||||
# License along with this library; if not, write to the
|
||||
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
# Boston, MA 02111-1307, USA.
|
||||
|
||||
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 += '-use_titlebar no '
|
||||
options += '-theme olpc '
|
||||
|
||||
command = 'matchbox-window-manager %s ' % options
|
||||
Process.__init__(self, command)
|
||||
|
||||
def get_name(self):
|
||||
return 'Matchbox'
|
@ -1,36 +0,0 @@
|
||||
# Copyright (C) 2006, Red Hat, Inc.
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This library is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public
|
||||
# License along with this library; if not, write to the
|
||||
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
# Boston, MA 02111-1307, USA.
|
||||
|
||||
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]
|
@ -1,26 +0,0 @@
|
||||
# Copyright (C) 2006, Red Hat, Inc.
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This library is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public
|
||||
# License along with this library; if not, write to the
|
||||
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
# Boston, MA 02111-1307, USA.
|
||||
|
||||
from sugar.session.DbusProcess import DbusProcess
|
||||
from sugar import env
|
||||
|
||||
class TestSession:
|
||||
def start(self):
|
||||
env.setup_python_path()
|
||||
|
||||
process = DbusProcess()
|
||||
process.start()
|
@ -1,38 +0,0 @@
|
||||
# Copyright (C) 2006, Red Hat, Inc.
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This library is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public
|
||||
# License along with this library; if not, write to the
|
||||
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
# Boston, MA 02111-1307, USA.
|
||||
|
||||
import os
|
||||
|
||||
from sugar.session.DbusProcess import DbusProcess
|
||||
from sugar.session.MatchboxProcess import MatchboxProcess
|
||||
from sugar.session.Emulator import Emulator
|
||||
from sugar import env
|
||||
|
||||
class UITestSession:
|
||||
def start(self):
|
||||
env.setup_python_path()
|
||||
|
||||
if os.environ.has_key('SUGAR_EMULATOR') and \
|
||||
os.environ['SUGAR_EMULATOR'] == 'yes':
|
||||
emulator = Emulator()
|
||||
emulator.start()
|
||||
|
||||
process = MatchboxProcess()
|
||||
process.start()
|
||||
|
||||
process = DbusProcess()
|
||||
process.start()
|
Loading…
Reference in New Issue