Several fixes, generate the service, add a test bundle

master
Marco Pesenti Gritti 18 years ago
parent 31c07be19e
commit 92f37d31da

@ -13,24 +13,32 @@ class Bundle:
cp = ConfigParser()
cp.read([info_path])
if cp.has_option('Activity', 'service_name'):
self._service_name = cp.get('Activity', 'service_name')
section = 'Activity'
if cp.has_option(section, 'service_name'):
self._service_name = cp.get(section, 'service_name')
else:
self._valid = False
logging.error('%s must specify a service name' % info_path)
if cp.has_option('Activity', 'name'):
self._service_name = cp.get('Activity', 'name')
if cp.has_option(section, 'name'):
self._name = cp.get(section, 'name')
else:
self._valid = False
logging.error('%s must specify a name' % info_path)
if cp.has_option('Activity', 'show_launcher'):
if cp.get('Activity', 'show_launcher') == 'yes':
if cp.has_option(section, 'exec'):
self._exec = cp.get(section, 'exec')
else:
self._valid = False
logging.error('%s must specify an exec' % info_path)
if cp.has_option(section, 'show_launcher'):
if cp.get(section, 'show_launcher') == 'yes':
self._show_launcher = True
if cp.has_option('Activity', 'icon'):
self._icon = cp.get('Activity', 'icon')
if cp.has_option(section, 'icon'):
self._icon = cp.get(section, 'icon')
def is_valid(self):
return self._valid
@ -47,6 +55,10 @@ class Bundle:
"""Get the activity icon name"""
return self._icon
def get_exec(self):
"""Get the command to execute to launch the activity factory"""
return self._exec
def get_show_launcher(self):
"""Get whether there should be a visible launcher for the activity"""
return self._show_launcher

@ -1,13 +1,41 @@
import os
from ConfigParser import ConfigParser
from sugar.activity.bundle import Bundle
class _ServiceParser(ConfigParser):
def optionxform(self, option):
return option
class _ServiceManager(object):
def __init__(self):
self._path = '/tmp/sugar-services'
if not os.path.isdir(self._path):
os.mkdir(self._path)
def add(self, bundle):
name = bundle.get_service_name()
service_cp = _ServiceParser()
section = 'D-BUS Service'
service_cp.add_section(section)
service_cp.set(section, 'Name', name)
service_cp.set(section, 'Exec', bundle.get_exec())
dest = os.path.join(self._path, name + '.service')
fileobject = open(dest, 'w')
service_cp.write(fileobject)
fileobject.close()
class BundleRegistry:
"""Service that tracks the available activity bundles"""
def __init__(self):
self._bundles = {}
self._search_path = []
self._service_manager = _ServiceManager()
def get_bundle(self, service_name):
"""Returns an bundle given his service name"""
@ -33,8 +61,9 @@ class BundleRegistry:
self._add_bundle(bundle_dir)
def _add_bundle(self, bundle_dir):
info_path = os.path.join(bundle_dir, 'activity.info')
info_path = os.path.join(bundle_dir, 'activity', 'activity.info')
if os.path.isfile(info_path):
bundle = Bundle(info_path)
if bundle.is_valid():
self._bundles[bundle.get_service_name()] = bundle
self._service_manager.add(bundle)

@ -0,0 +1,5 @@
[Activity]
name = Test
service_name = org.laptop.Test
icon = activity-sketch
exec = bu
Loading…
Cancel
Save