Cleanup environemnt setup

This commit is contained in:
Marco Pesenti Gritti 2006-08-12 23:35:52 +02:00
parent d41c761e02
commit bb60b8ad3e
6 changed files with 56 additions and 52 deletions

View File

@ -2,62 +2,27 @@
import sys
import os
import pwd
import random
import tempfile
import pygtk
pygtk.require('2.0')
def add_to_bin_path(path):
if os.environ.has_key('PATH'):
old_path = os.environ['PATH']
os.environ['PATH'] = path + ':' + old_path
else:
os.environ['PATH'] = path
def add_to_python_path(path):
sys.path.insert(0, path)
if os.environ.has_key('PYTHONPATH'):
old_path = os.environ['PYTHONPATH']
os.environ['PYTHONPATH'] = path + ':' + old_path
else:
os.environ['PYTHONPATH'] = path
curdir = os.path.abspath(os.path.dirname(__file__))
basedir = os.path.dirname(curdir)
sourcedir = os.path.dirname(curdir)
if os.path.isfile(os.path.join(basedir, 'sugar/__uninstalled__.py')):
print 'Running sugar from ' + basedir + ' ...'
add_to_bin_path(os.path.join(basedir, 'shell'))
add_to_python_path(basedir)
add_to_python_path(os.path.join(basedir, 'shell'))
add_to_python_path(os.path.join(basedir, 'activities'))
from sugar import env
from sugar import setup
activities_dest = os.path.join(tempfile.gettempdir(), 'sugar')
if not os.path.isdir(activities_dest):
os.mkdir(activities_dest)
else:
# FIXME delete the whole directory
pass
setup.setup_activities(env.get_activities_dir(), activities_dest,
os.path.join(basedir, 'shell/sugar-activity-factory'))
if os.path.isfile(os.path.join(sourcedir, 'sugar/__uninstalled__.py')):
print 'Running sugar from ' + sourcedir + ' ...'
sys.path.insert(0, sourcedir)
else:
print 'Running the installed sugar...'
from sugar import env
add_to_python_path(os.path.join(env.get_data_dir(), 'shell'))
add_to_python_path(os.path.join(env.get_data_dir(), 'activities'))
activities_dest = env.get_activities_dir()
from sugar import env
env.setup()
from ActivityRegistry import ActivityRegistry
registry = ActivityRegistry()
registry.scan_directory(activities_dest)
registry.scan_directory(env.get_activities_dir())
from session.Emulator import Emulator

View File

@ -7,7 +7,6 @@ sugar_PYTHON = \
bots.py \
env.py \
setup.py \
util.py \
LogWriter.py
util.py
EXTRA_DIST = __uninstalled__.py

View File

@ -1,4 +1,8 @@
sugar_source_dir = None
sugar_data_dir = '@prefix@/share/sugar'
sugar_activity_runner = '@prefix@/bin/sugar-activity'
sugar_activities_dir = '@prefix@/share/sugar/activities'
sugar_dbus_config = '@prefix@/share/sugar/dbus-installed.conf'
sugar_python_path = ['@prefix@/share/sugar/shell',
'@prefix@/share/sugar/activities]
sugar_bin_path = []

View File

@ -1,7 +1,16 @@
import os
import tempfile
_source_dir = os.path.dirname(os.path.dirname(__file__))
sugar_source_dir = os.path.dirname(os.path.dirname(__file__))
sugar_data_dir = os.path.join(_source_dir, 'shell/data')
sugar_activities_dir = os.path.join(_source_dir, 'activities')
sugar_dbus_config = os.path.join(_source_dir, 'dbus-uninstalled.conf')
sugar_data_dir = os.path.join(sugar_source_dir, 'shell/data')
sugar_activities_dir = os.path.join(tempfile.gettempdir(), 'sugar')
sugar_dbus_config = os.path.join(sugar_source_dir, 'dbus-uninstalled.conf')
sugar_python_path = []
sugar_python_path.append(sugar_source_dir)
sugar_python_path.append(os.path.join(sugar_source_dir, 'shell'))
sugar_python_path.append(os.path.join(sugar_source_dir, 'activities'))
sugar_bin_path = []
sugar_bin_path.append(os.path.join(sugar_source_dir, 'shell'))

View File

@ -7,6 +7,8 @@ try:
except ImportError:
from sugar.__installed__ import *
import sugar.setup
def add_to_python_path(path):
sys.path.insert(0, path)
if os.environ.has_key('PYTHONPATH'):
@ -14,6 +16,25 @@ def add_to_python_path(path):
else:
os.environ['PYTHONPATH'] = path
def add_to_bin_path(path):
if os.environ.has_key('PATH'):
old_path = os.environ['PATH']
os.environ['PATH'] = path + ':' + old_path
else:
os.environ['PATH'] = path
def setup():
for path in sugar_python_path:
add_to_python_path(path)
for path in sugar_bin_path:
add_to_bin_path(path)
if sugar_source_dir:
source = os.path.join(sugar_source_dir, 'activities')
runner = os.path.join(sugar_source_dir, 'shell/sugar-activity-factory')
sugar.setup.setup_activities(source, get_activities_dir(), runner)
def get_user_dir():
if os.environ.has_key('SUGAR_NICK_NAME'):
nick = get_nick_name()

View File

@ -48,7 +48,13 @@ def setup_activity(source, dest_path, bin):
fileobject.close()
def setup_activities(source_path, dest_path, bin):
"""Scan a directory for activities and install them."""
"""Scan a directory for activities and install them."""
if not os.path.isdir(dest_path):
os.mkdir(dest_path)
else:
# FIXME delete the whole directory
pass
if os.path.isdir(source_path):
for filename in os.listdir(source_path):
activity_dir = os.path.join(source_path, filename)