Automatically read the profile (lazily)

This commit is contained in:
Marco Pesenti Gritti 2006-08-26 13:35:03 +02:00
parent a7c552c038
commit 93d489741d
4 changed files with 23 additions and 31 deletions

View File

@ -723,7 +723,6 @@ class PresenceService(object):
def main():
from sugar import TracebackUtils
env.read_profile()
loop = gobject.MainLoop()
ps = PresenceService()
tbh = TracebackUtils.TracebackHelper()

View File

@ -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"""

View File

@ -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()

View File

@ -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