sugar-toolkit-gtk3/sugar/activity/bundle.py

87 lines
2.1 KiB
Python
Raw Normal View History

2006-10-29 18:28:48 +01:00
import logging
import os
2006-10-29 18:28:48 +01:00
from ConfigParser import ConfigParser
class Bundle:
"""Info about an activity bundle. Wraps the activity.info file."""
def __init__(self, path):
2006-10-29 18:28:48 +01:00
self._name = None
self._icon = None
self._service_name = None
2006-11-03 16:18:03 +01:00
self._show_launcher = True
2006-10-29 18:28:48 +01:00
self._valid = True
self._path = path
2006-11-02 11:10:37 +01:00
self._activity_version = 0
info_path = os.path.join(path, 'activity', 'activity.info')
if os.path.isfile(info_path):
self._parse_info(info_path)
else:
self._valid = False
2006-10-29 18:28:48 +01:00
def _parse_info(self, info_path):
2006-10-29 18:28:48 +01:00
cp = ConfigParser()
cp.read([info_path])
section = 'Activity'
if cp.has_option(section, 'service_name'):
self._service_name = cp.get(section, 'service_name')
2006-10-29 18:28:48 +01:00
else:
self._valid = False
logging.error('%s must specify a service name' % self._path)
2006-10-29 18:28:48 +01:00
if cp.has_option(section, 'name'):
self._name = cp.get(section, 'name')
2006-10-29 18:28:48 +01:00
else:
self._valid = False
logging.error('%s must specify a name' % self._path)
2006-10-29 18:28:48 +01:00
if cp.has_option(section, 'exec'):
self._exec = cp.get(section, 'exec')
else:
self._valid = False
logging.error('%s must specify an exec' % self._path)
if cp.has_option(section, 'show_launcher'):
2006-11-03 16:01:46 +01:00
if cp.get(section, 'show_launcher') == 'no':
self._show_launcher = False
2006-10-29 18:28:48 +01:00
if cp.has_option(section, 'icon'):
self._icon = cp.get(section, 'icon')
2006-10-29 18:28:48 +01:00
2006-11-02 11:10:37 +01:00
if cp.has_option(section, 'activity_version'):
self._activity_version = int(cp.get(section, 'activity_version'))
2006-10-29 18:28:48 +01:00
def is_valid(self):
return self._valid
def get_path(self):
"""Get the activity bundle path."""
return self._path
2006-10-29 18:28:48 +01:00
def get_name(self):
"""Get the activity user visible name."""
return self._name
def get_service_name(self):
"""Get the activity service name"""
2006-10-29 19:05:09 +01:00
return self._service_name
2006-10-29 18:28:48 +01:00
def get_icon(self):
"""Get the activity icon name"""
return self._icon
2006-11-02 11:10:37 +01:00
def get_activity_version(self):
"""Get the activity version"""
return self._activity_version
def get_exec(self):
"""Get the command to execute to launch the activity factory"""
return self._exec
2006-10-29 18:28:48 +01:00
def get_show_launcher(self):
"""Get whether there should be a visible launcher for the activity"""
return self._show_launcher