Refactor sugar.env and paths

This commit is contained in:
Marco Pesenti Gritti
2007-03-09 14:57:54 +01:00
parent a380b7f915
commit 57c928916c
18 changed files with 55 additions and 41 deletions
+1 -2
View File
@@ -44,8 +44,7 @@ class Bundle:
if cp.has_option(section, 'class'):
self._class = cp.get(section, 'class')
self._exec = '%s %s --bundle-path="%s"' % (
os.path.join(env.get_shell_bin_dir(), _PYTHON_FACTORY),
self._class, self.get_path())
env.get_bin_path(_PYTHON_FACTORY), self._class, self.get_path())
elif cp.has_option(section, 'exec'):
self._class = None
self._exec = cp.get(section, 'exec')
+2 -2
View File
@@ -93,7 +93,7 @@ def _get_install_dir(prefix):
return os.path.join(prefix, 'share/activities')
def _get_bundle_path():
return os.path.join(env.get_user_activities_dir(), _get_bundle_dir())
return os.path.join(env.get_user_activities_path(), _get_bundle_dir())
def _get_package_name():
bundle = Bundle(_get_source_path())
@@ -120,7 +120,7 @@ setup.py help - print this message \n\
'
def cmd_dev():
bundle_path = os.path.join(env.get_user_activities_dir(), _get_bundle_dir())
bundle_path = os.path.join(env.get_user_activities_path(), _get_bundle_dir())
try:
os.symlink(_get_source_path(), bundle_path)
except OSError:
+15 -3
View File
@@ -1,14 +1,26 @@
import os
from ConfigParser import ConfigParser
import gobject
from sugar.activity.bundle import Bundle
from sugar import env
from sugar import util
# http://standards.freedesktop.org/basedir-spec/basedir-spec-0.6.html
def _get_data_dirs():
if os.environ.has_key('XDG_DATA_DIRS'):
return os.environ['XDG_DATA_DIRS'].split(':')
else:
return [ '/usr/local/share/', '/usr/share/' ]
class _ServiceManager(object):
def __init__(self):
self._path = env.get_user_service_dir()
service_dir = os.path.expanduser('~/.local/share/dbus-1/services')
if not os.path.isdir(service_dir):
os.makedirs(service_dir)
self._path = service_dir
def add(self, bundle):
util.write_service(bundle.get_service_name(),
@@ -74,8 +86,8 @@ def get_registry():
_bundle_registry = BundleRegistry()
for path in env.get_data_dirs():
for path in _get_data_dirs():
bundles_path = os.path.join(path, 'activities')
_bundle_registry.add_search_path(bundles_path)
_bundle_registry.add_search_path(env.get_user_activities_dir())
_bundle_registry.add_search_path(env.get_user_activities_path())
+23 -20
View File
@@ -24,6 +24,17 @@ try:
except ImportError:
from sugar.__installed__ import *
def _get_prefix_path(base, path=None):
if os.environ.has_key('SUGAR_PREFIX'):
prefix = os.environ['SUGAR_PREFIX']
else:
prefix = '/usr'
if path:
return os.path.join(prefix, base, path)
else:
return os.path.join(prefix, base)
def is_emulator():
if os.environ.has_key('SUGAR_EMULATOR'):
if os.environ['SUGAR_EMULATOR'] == 'yes':
@@ -45,28 +56,20 @@ def get_profile_path():
return path
def get_data_dir():
return sugar_data_dir
def get_shell_bin_dir():
return sugar_shell_bin_dir
# http://standards.freedesktop.org/basedir-spec/basedir-spec-0.6.html
def get_data_dirs():
if os.environ.has_key('XDG_DATA_DIRS'):
return os.environ['XDG_DATA_DIRS'].split(':')
else:
return [ '/usr/local/share/', '/usr/share/' ]
def get_user_service_dir():
service_dir = os.path.expanduser('~/.local/share/dbus-1/services')
if not os.path.isdir(service_dir):
os.makedirs(service_dir)
return service_dir
def get_user_activities_dir():
def get_user_activities_path():
path = os.path.expanduser('~/Activities')
if not os.path.isdir(path):
os.mkdir(path)
return path
def get_bin_path(path=None):
return _get_prefix_path('bin', path)
def get_service_path(name):
return _get_prefix_path('share/sugar/services', name)
def get_shell_path(path=None):
return _get_prefix_path('share/sugar/shell', path)
def get_emulator_path(path=None):
return _get_prefix_path('share/sugar/emulator', path)
+1 -1
View File
@@ -326,7 +326,7 @@ class CanvasIcon(hippo.CanvasBox, hippo.CanvasItem):
return height
def do_button_press_event(self, event):
item.emit_activated()
self.emit_activated()
return True
def get_popup(self):