Initial bundle registry code
This commit is contained in:
parent
ff2bee3d9b
commit
87274fd89f
@ -16,3 +16,10 @@ def get_default_type(activity_type):
|
|||||||
splitted_id = activity_type.split('.')
|
splitted_id = activity_type.split('.')
|
||||||
splitted_id.reverse()
|
splitted_id.reverse()
|
||||||
return '_' + '_'.join(splitted_id) + '._udp'
|
return '_' + '_'.join(splitted_id) + '._udp'
|
||||||
|
|
||||||
|
from sugar.activity.bundleregistry import BundleRegistry
|
||||||
|
|
||||||
|
_bundle_registry = BundleRegistry()
|
||||||
|
|
||||||
|
def get_bundle_registry():
|
||||||
|
return _bundle_registry
|
||||||
|
52
sugar/activity/bundle.py
Normal file
52
sugar/activity/bundle.py
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
import logging
|
||||||
|
from ConfigParser import ConfigParser
|
||||||
|
|
||||||
|
class Bundle:
|
||||||
|
"""Info about an activity bundle. Wraps the activity.info file."""
|
||||||
|
def __init__(self, info_path):
|
||||||
|
self._name = None
|
||||||
|
self._icon = None
|
||||||
|
self._service_name = None
|
||||||
|
self._show_launcher = False
|
||||||
|
self._valid = True
|
||||||
|
|
||||||
|
cp = ConfigParser()
|
||||||
|
cp.read([info_path])
|
||||||
|
|
||||||
|
if cp.has_option('Activity', 'service_name'):
|
||||||
|
self._service_name = cp.get('Activity', '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')
|
||||||
|
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':
|
||||||
|
self._show_launcher = True
|
||||||
|
|
||||||
|
if cp.has_option('Activity', 'icon'):
|
||||||
|
self._icon = cp.get('Activity', 'icon')
|
||||||
|
|
||||||
|
def is_valid(self):
|
||||||
|
return self._valid
|
||||||
|
|
||||||
|
def get_name(self):
|
||||||
|
"""Get the activity user visible name."""
|
||||||
|
return self._name
|
||||||
|
|
||||||
|
def get_service_name(self):
|
||||||
|
"""Get the activity service name"""
|
||||||
|
return self._id
|
||||||
|
|
||||||
|
def get_icon(self):
|
||||||
|
"""Get the activity icon name"""
|
||||||
|
return self._icon
|
||||||
|
|
||||||
|
def get_show_launcher(self):
|
||||||
|
"""Get whether there should be a visible launcher for the activity"""
|
||||||
|
return self._show_launcher
|
32
sugar/activity/bundleregistry.py
Normal file
32
sugar/activity/bundleregistry.py
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
from sugar.activity.bundle import Bundle
|
||||||
|
|
||||||
|
class BundleRegistry:
|
||||||
|
"""Service that tracks the available activity bundles"""
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self._bundles = {}
|
||||||
|
self._search_path = []
|
||||||
|
|
||||||
|
def get_bundle(self, service_name):
|
||||||
|
"""Returns an bundle given his service name"""
|
||||||
|
if self._bundles.has_key(service_name):
|
||||||
|
return self._bundles[service_name]
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
|
def append_search_path(self, path):
|
||||||
|
"""Append a directory to the bundles search path"""
|
||||||
|
self._search_path.append(path)
|
||||||
|
self._scan_directory(path)
|
||||||
|
|
||||||
|
def __iter__(self):
|
||||||
|
return self._bundles.values()
|
||||||
|
|
||||||
|
def _scan_directory(self, path):
|
||||||
|
for bundle_dir in os.listdir(path):
|
||||||
|
if os.path.isdir(bundle_dir):
|
||||||
|
info_path = os.path.join(bundle_dir, activity_info)
|
||||||
|
if os.path.isfile(info_path):
|
||||||
|
bundle = Bundle(info_path)
|
||||||
|
if bundle.is_valid():
|
||||||
|
self._bundles.append(bundle)
|
Loading…
Reference in New Issue
Block a user