Get running activities to work. Still hacky.
This commit is contained in:
@@ -1,15 +1,25 @@
|
||||
import logging
|
||||
import os
|
||||
|
||||
from ConfigParser import ConfigParser
|
||||
|
||||
class Bundle:
|
||||
"""Info about an activity bundle. Wraps the activity.info file."""
|
||||
def __init__(self, info_path):
|
||||
def __init__(self, path):
|
||||
self._name = None
|
||||
self._icon = None
|
||||
self._service_name = None
|
||||
self._show_launcher = False
|
||||
self._valid = True
|
||||
self._path = path
|
||||
|
||||
info_path = os.path.join(path, 'activity', 'activity.info')
|
||||
if os.path.isfile(info_path):
|
||||
self._parse_info(info_path)
|
||||
else:
|
||||
self._valid = False
|
||||
|
||||
def _parse_info(self, info_path):
|
||||
cp = ConfigParser()
|
||||
cp.read([info_path])
|
||||
|
||||
@@ -19,19 +29,19 @@ class Bundle:
|
||||
self._service_name = cp.get(section, 'service_name')
|
||||
else:
|
||||
self._valid = False
|
||||
logging.error('%s must specify a service name' % info_path)
|
||||
logging.error('%s must specify a service name' % self._path)
|
||||
|
||||
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)
|
||||
logging.error('%s must specify a name' % self._path)
|
||||
|
||||
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)
|
||||
logging.error('%s must specify an exec' % self._path)
|
||||
|
||||
if cp.has_option(section, 'show_launcher'):
|
||||
if cp.get(section, 'show_launcher') == 'yes':
|
||||
@@ -43,6 +53,10 @@ class Bundle:
|
||||
def is_valid(self):
|
||||
return self._valid
|
||||
|
||||
def get_path(self):
|
||||
"""Get the activity bundle path."""
|
||||
return self._path
|
||||
|
||||
def get_name(self):
|
||||
"""Get the activity user visible name."""
|
||||
return self._name
|
||||
@@ -62,3 +76,7 @@ class Bundle:
|
||||
def get_show_launcher(self):
|
||||
"""Get whether there should be a visible launcher for the activity"""
|
||||
return self._show_launcher
|
||||
|
||||
# Compatibility with the old activity registry, remove after BTest-1
|
||||
def get_id(self):
|
||||
return self._service_name
|
||||
|
||||
@@ -2,6 +2,7 @@ import os
|
||||
from ConfigParser import ConfigParser
|
||||
|
||||
from sugar.activity.bundle import Bundle
|
||||
from sugar import env
|
||||
|
||||
class _ServiceParser(ConfigParser):
|
||||
def optionxform(self, option):
|
||||
@@ -21,8 +22,15 @@ class _ServiceManager(object):
|
||||
|
||||
section = 'D-BUS Service'
|
||||
service_cp.add_section(section)
|
||||
service_cp.set(section, 'Name', name)
|
||||
service_cp.set(section, 'Exec', bundle.get_exec())
|
||||
|
||||
# Compatibility with the old activity registry, remove after BTest-1
|
||||
# service_cp.set(section, 'Name', name)
|
||||
service_cp.set(section, 'Name', name + '.Factory')
|
||||
|
||||
# FIXME total hack
|
||||
full_exec = env.get_shell_bin_dir() + '/' + bundle.get_exec()
|
||||
full_exec += ' ' + bundle.get_path()
|
||||
service_cp.set(section, 'Exec', full_exec)
|
||||
|
||||
dest = os.path.join(self._path, name + '.service')
|
||||
fileobject = open(dest, 'w')
|
||||
@@ -60,10 +68,9 @@ class BundleRegistry:
|
||||
bundle_dir.endswith('.activity'):
|
||||
self._add_bundle(bundle_dir)
|
||||
|
||||
def _add_bundle(self, bundle_dir):
|
||||
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)
|
||||
def _add_bundle(self, bundle_path):
|
||||
bundle = Bundle(bundle_path)
|
||||
print bundle
|
||||
if bundle.is_valid():
|
||||
self._bundles[bundle.get_service_name()] = bundle
|
||||
self._service_manager.add(bundle)
|
||||
|
||||
Reference in New Issue
Block a user