From 93d489741d676d4ed3b3285bf732c614e6fff371 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Sat, 26 Aug 2006 13:35:03 +0200 Subject: [PATCH] Automatically read the profile (lazily) --- shell/PresenceService/PresenceService.py | 1 - sugar/conf/ActivityRegistry.py | 3 ++ sugar/conf/Profile.py | 36 +++++++++++------------- sugar/env.py | 14 ++------- 4 files changed, 23 insertions(+), 31 deletions(-) diff --git a/shell/PresenceService/PresenceService.py b/shell/PresenceService/PresenceService.py index f40d6e72..f20b3dcb 100644 --- a/shell/PresenceService/PresenceService.py +++ b/shell/PresenceService/PresenceService.py @@ -723,7 +723,6 @@ class PresenceService(object): def main(): from sugar import TracebackUtils - env.read_profile() loop = gobject.MainLoop() ps = PresenceService() tbh = TracebackUtils.TracebackHelper() diff --git a/sugar/conf/ActivityRegistry.py b/sugar/conf/ActivityRegistry.py index 5ff0059f..189d3d9d 100644 --- a/sugar/conf/ActivityRegistry.py +++ b/sugar/conf/ActivityRegistry.py @@ -3,6 +3,8 @@ import os from ConfigParser import ConfigParser from ConfigParser import NoOptionError +from sugar import env + class ActivityModule: """Info about an activity module. Wraps a .activity file.""" @@ -54,6 +56,7 @@ class ActivityRegistry: def __init__(self): self._activities = [] + self.scan_directory(env.get_activities_dir()) def get_activity_from_id(self, activity_id): """Returns an activity given his identifier""" diff --git a/sugar/conf/Profile.py b/sugar/conf/Profile.py index c569cb30..7a6be2e2 100644 --- a/sugar/conf/Profile.py +++ b/sugar/conf/Profile.py @@ -1,11 +1,27 @@ import os from ConfigParser import ConfigParser + from sugar.canvas.IconColor import IconColor +from sugar import env class Profile: def __init__(self,): - self._path = None + self._path = env.get_profile_path() self._nick_name = None + self._color = None + + 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'): + self._color = IconColor(cp.get('Buddy', 'Color')) + + if self._color == None: + self.set_color(IconColor()) def _ensure_dirs(self): try: @@ -29,24 +45,6 @@ class Profile: def get_path(self): return self._path - def set_path(self, path): - self._path = path - - def read(self): - self._color = None - 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'): - self._color = IconColor(cp.get('Buddy', 'Color')) - - if self._color == None: - self.set_color(IconColor()) - def save(self): cp = ConfigParser() diff --git a/sugar/env.py b/sugar/env.py index 992bcf3d..c11c83a4 100644 --- a/sugar/env.py +++ b/sugar/env.py @@ -8,7 +8,6 @@ except ImportError: from sugar.__installed__ import * import sugar.setup -import sugar.conf def add_to_python_path(path): sys.path.insert(0, path) @@ -41,16 +40,6 @@ def setup(): sugar.setup.write_service('org.laptop.Presence', bin, sugar_activities_dir) - registry = sugar.conf.get_activity_registry() - registry.scan_directory(sugar_activities_dir) - - read_profile() - -def read_profile(): - profile = sugar.conf.get_profile() - profile.set_path(get_profile_path()) - profile.read() - def get_profile_path(): if os.environ.has_key('SUGAR_PROFILE'): profile_id = os.environ['SUGAR_PROFILE'] @@ -63,5 +52,8 @@ def get_profile_path(): def get_data_dir(): return sugar_data_dir +def get_activities_dir(): + return sugar_activities_dir + def get_dbus_config(): return sugar_dbus_config