Make conf private, expose the nick name from env
This commit is contained in:
+1
-1
@@ -1,4 +1,4 @@
|
||||
SUBDIRS = activity canvas chat conf p2p presence
|
||||
SUBDIRS = activity canvas chat p2p presence
|
||||
|
||||
sugardir = $(pythondir)/sugar
|
||||
sugar_PYTHON = \
|
||||
|
||||
@@ -7,7 +7,7 @@ import gtk
|
||||
import gobject
|
||||
|
||||
from sugar.presence.PresenceService import PresenceService
|
||||
from sugar.conf import ActivityRegistry
|
||||
from sugar import activity
|
||||
import sugar.util
|
||||
|
||||
ACTIVITY_SERVICE_NAME = "org.laptop.Activity"
|
||||
@@ -20,7 +20,6 @@ def get_service_name(xid):
|
||||
def get_object_path(xid):
|
||||
return ACTIVITY_SERVICE_PATH + "/%s" % xid
|
||||
|
||||
|
||||
class ActivityDbusService(dbus.service.Object):
|
||||
"""Base dbus service object that each Activity uses to export dbus methods.
|
||||
|
||||
@@ -91,7 +90,7 @@ class Activity(gtk.Window):
|
||||
def set_type(self, activity_type):
|
||||
"""Sets the activity type."""
|
||||
self._activity_type = activity_type
|
||||
self._default_type = ActivityRegistry.get_default_type(activity_type)
|
||||
self._default_type = activity.get_default_type(activity_type)
|
||||
|
||||
def get_type(self):
|
||||
"""Gets the activity type."""
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
def get_default_type(activity_type):
|
||||
"""Get the activity default type.
|
||||
|
||||
It's the type of the main network service which tracks presence
|
||||
and provides info about the activity, for example the title."""
|
||||
splitted_id = activity_type.split('.')
|
||||
splitted_id.reverse()
|
||||
return '_' + '_'.join(splitted_id) + '._udp'
|
||||
|
||||
@@ -1,123 +0,0 @@
|
||||
import logging
|
||||
import os
|
||||
from ConfigParser import ConfigParser
|
||||
from ConfigParser import NoOptionError
|
||||
|
||||
from sugar import env
|
||||
|
||||
def get_default_type(activity_type):
|
||||
"""Get the activity default type.
|
||||
|
||||
It's the type of the main network service which tracks presence
|
||||
and provides info about the activity, for example the title."""
|
||||
splitted_id = activity_type.split('.')
|
||||
splitted_id.reverse()
|
||||
return '_' + '_'.join(splitted_id) + '._udp'
|
||||
|
||||
class ActivityModule:
|
||||
"""Info about an activity module. Wraps a .activity file."""
|
||||
|
||||
def __init__(self, name, activity_id, directory):
|
||||
self._name = name
|
||||
self._icon = None
|
||||
self._id = activity_id
|
||||
self._directory = directory
|
||||
self._show_launcher = False
|
||||
|
||||
def get_name(self):
|
||||
"""Get the activity user visible name."""
|
||||
return self._name
|
||||
|
||||
def get_id(self):
|
||||
"""Get the activity identifier"""
|
||||
return self._id
|
||||
|
||||
def get_icon(self):
|
||||
"""Get the activity icon name"""
|
||||
return self._icon
|
||||
|
||||
def set_icon(self, icon):
|
||||
"""Set the activity icon name"""
|
||||
self._icon = icon
|
||||
|
||||
def get_directory(self):
|
||||
"""Get the path to activity directory."""
|
||||
return self._directory
|
||||
|
||||
def get_default_type(self):
|
||||
"""Get the the type of the default activity service."""
|
||||
return get_default_type(self._id)
|
||||
|
||||
def set_default_type(self, default_type):
|
||||
"""Set the the type of the default activity service."""
|
||||
self._default_type = default_type
|
||||
|
||||
def get_show_launcher(self):
|
||||
"""Get whether there should be a visible launcher for the activity"""
|
||||
return self._show_launcher
|
||||
|
||||
def set_show_launcher(self, show_launcher):
|
||||
"""Set whether there should be a visible launcher for the activity"""
|
||||
self._show_launcher = show_launcher
|
||||
|
||||
class _ActivityRegistry:
|
||||
"""Service that tracks the available activities"""
|
||||
|
||||
def __init__(self):
|
||||
self._activities = []
|
||||
self.scan_directory(env.get_activities_dir())
|
||||
|
||||
def get_activity(self, activity_id):
|
||||
"""Returns an activity given his identifier"""
|
||||
for activity in self._activities:
|
||||
if activity.get_id() == activity_id:
|
||||
return activity
|
||||
return None
|
||||
|
||||
def get_activity_from_type(self, default_type):
|
||||
"""Returns an activity given his default type"""
|
||||
for activity in self._activities:
|
||||
if activity.get_default_type() == default_type:
|
||||
return activity
|
||||
return None
|
||||
|
||||
def scan_directory(self, path):
|
||||
"""Scan a directory for activities and add them to the registry."""
|
||||
if os.path.isdir(path):
|
||||
for f in os.listdir(path):
|
||||
if f.endswith(".activity"):
|
||||
self.add(os.path.join(path, f))
|
||||
|
||||
def add(self, path):
|
||||
"""Add an activity to the registry. The path points to a .activity file."""
|
||||
cp = ConfigParser()
|
||||
cp.read([path])
|
||||
|
||||
directory = os.path.dirname(path)
|
||||
|
||||
try:
|
||||
activity_id = cp.get('Activity', 'id')
|
||||
except NoOptionError:
|
||||
logging.error('%s miss the required id option' % (path))
|
||||
return False
|
||||
|
||||
try:
|
||||
name = cp.get('Activity', 'name')
|
||||
except NoOptionError:
|
||||
logging.error('%s miss the required name option' % (path))
|
||||
return False
|
||||
|
||||
module = ActivityModule(name, activity_id, directory)
|
||||
self._activities.append(module)
|
||||
|
||||
if cp.has_option('Activity', 'show_launcher'):
|
||||
module.set_show_launcher(True)
|
||||
|
||||
if cp.has_option('Activity', 'icon'):
|
||||
module.set_icon(cp.get('Activity', 'icon'))
|
||||
|
||||
return True
|
||||
|
||||
def list_activities(self):
|
||||
"""Enumerate the registered activities as an ActivityModule list."""
|
||||
return self._activities
|
||||
@@ -1,5 +0,0 @@
|
||||
sugardir = $(pythondir)/sugar/conf
|
||||
sugar_PYTHON = \
|
||||
__init__.py \
|
||||
ActivityRegistry.py \
|
||||
Profile.py
|
||||
@@ -1,61 +0,0 @@
|
||||
import os
|
||||
from ConfigParser import ConfigParser
|
||||
|
||||
from sugar.canvas.IconColor import IconColor
|
||||
from sugar import env
|
||||
|
||||
class Profile:
|
||||
def __init__(self,):
|
||||
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:
|
||||
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.get_fill_color())
|
||||
|
||||
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 +0,0 @@
|
||||
from sugar.conf.ActivityRegistry import _ActivityRegistry
|
||||
from sugar.conf.Profile import Profile
|
||||
|
||||
__registry = _ActivityRegistry()
|
||||
__profile = Profile()
|
||||
|
||||
def get_activity_registry():
|
||||
return __registry
|
||||
|
||||
def get_profile():
|
||||
return __profile
|
||||
+7
-1
@@ -9,7 +9,13 @@ except ImportError:
|
||||
|
||||
import sugar.setup
|
||||
|
||||
def setup():
|
||||
def setup_user(profile):
|
||||
os.environ['SUGAR_NICK_NAME'] = profile.get_nick_name()
|
||||
|
||||
def get_nick_name():
|
||||
return os.environ['SUGAR_NICK_NAME']
|
||||
|
||||
def setup_system():
|
||||
for path in sugar_python_path:
|
||||
sys.path.insert(0, path)
|
||||
if os.environ.has_key('PYTHONPATH'):
|
||||
|
||||
Reference in New Issue
Block a user