2007-04-11 14:06:27 +02:00
|
|
|
# Copyright (C) 2007, Red Hat, Inc.
|
|
|
|
#
|
|
|
|
# This library is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU Lesser General Public
|
|
|
|
# License as published by the Free Software Foundation; either
|
|
|
|
# version 2 of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This library is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
# Lesser General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Lesser General Public
|
|
|
|
# License along with this library; if not, write to the
|
|
|
|
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
# Boston, MA 02111-1307, USA.
|
|
|
|
|
2007-04-10 04:47:37 +02:00
|
|
|
"""Metadata description of a given application/activity"""
|
2007-04-11 14:06:27 +02:00
|
|
|
|
2006-10-29 18:28:48 +01:00
|
|
|
import logging
|
2007-03-23 17:27:31 +01:00
|
|
|
import locale
|
2006-10-31 12:06:28 +01:00
|
|
|
import os
|
2006-10-29 18:28:48 +01:00
|
|
|
from ConfigParser import ConfigParser
|
|
|
|
|
2007-02-22 15:46:13 +01:00
|
|
|
from sugar import env
|
|
|
|
|
|
|
|
_PYTHON_FACTORY='sugar-activity-factory'
|
|
|
|
|
2006-10-29 18:28:48 +01:00
|
|
|
class Bundle:
|
2007-04-10 04:47:37 +02:00
|
|
|
"""Metadata description of a given application/activity
|
|
|
|
|
|
|
|
The metadata is normally read from an activity.info file,
|
|
|
|
which is an INI-style configuration file read using the
|
|
|
|
standard Python ConfigParser module.
|
|
|
|
|
|
|
|
The format reference for the Bundle definition files is
|
|
|
|
available for further reference:
|
|
|
|
|
|
|
|
http://wiki.laptop.org/go/Activity_bundles
|
|
|
|
"""
|
2006-12-04 20:12:24 +01:00
|
|
|
def __init__(self, path):
|
|
|
|
self._name = None
|
|
|
|
self._icon = None
|
|
|
|
self._service_name = None
|
2007-05-24 17:53:57 +02:00
|
|
|
self._mime_types = None
|
2006-12-04 20:12:24 +01:00
|
|
|
self._show_launcher = True
|
|
|
|
self._valid = True
|
|
|
|
self._path = path
|
|
|
|
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
|
|
|
|
|
2007-03-23 17:27:31 +01:00
|
|
|
linfo_path = self._get_linfo_path()
|
|
|
|
if linfo_path and os.path.isfile(linfo_path):
|
2007-03-23 18:18:42 +01:00
|
|
|
self._parse_linfo(linfo_path)
|
2007-03-23 17:27:31 +01:00
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
def _parse_info(self, info_path):
|
|
|
|
cp = ConfigParser()
|
|
|
|
cp.read([info_path])
|
|
|
|
|
|
|
|
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' % 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' % self._path)
|
|
|
|
|
2007-02-22 15:46:13 +01:00
|
|
|
if cp.has_option(section, 'class'):
|
|
|
|
self._class = cp.get(section, 'class')
|
2007-03-09 16:35:53 +01:00
|
|
|
self._exec = '%s --bundle-path="%s"' % (
|
2007-05-17 13:18:56 +02:00
|
|
|
env.get_bin_path(_PYTHON_FACTORY), self._path)
|
2007-02-22 15:46:13 +01:00
|
|
|
elif cp.has_option(section, 'exec'):
|
|
|
|
self._class = None
|
2007-05-17 13:18:56 +02:00
|
|
|
cmdline = cp.get(section, 'exec')
|
|
|
|
cmdline = os.path.join(self._path, cmdline)
|
|
|
|
cmdline = cmdline.replace('$SUGAR_BUNDLE_PATH', self._path)
|
|
|
|
cmdline = os.path.expandvars(cmdline)
|
|
|
|
self._exec = cmdline
|
2006-12-04 20:12:24 +01:00
|
|
|
else:
|
2007-02-22 15:46:13 +01:00
|
|
|
self._exec = None
|
2006-12-04 20:12:24 +01:00
|
|
|
self._valid = False
|
2007-02-22 15:46:13 +01:00
|
|
|
logging.error('%s must specify exec or class' % self._path)
|
2006-12-04 20:12:24 +01:00
|
|
|
|
2007-05-24 17:53:57 +02:00
|
|
|
if cp.has_option(section, 'mime_types'):
|
|
|
|
mime_list = cp.get(section, 'show_launcher')
|
|
|
|
self._mime_types = mime_list.strip(';')
|
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
if cp.has_option(section, 'show_launcher'):
|
|
|
|
if cp.get(section, 'show_launcher') == 'no':
|
|
|
|
self._show_launcher = False
|
|
|
|
|
|
|
|
if cp.has_option(section, 'icon'):
|
2007-01-12 21:35:53 +01:00
|
|
|
icon = cp.get(section, 'icon')
|
2007-01-31 21:00:13 +01:00
|
|
|
activity_path = os.path.join(self._path, 'activity')
|
|
|
|
self._icon = os.path.join(activity_path, icon + ".svg")
|
2006-12-04 20:12:24 +01:00
|
|
|
|
|
|
|
if cp.has_option(section, 'activity_version'):
|
|
|
|
self._activity_version = int(cp.get(section, 'activity_version'))
|
|
|
|
|
2007-03-23 17:27:31 +01:00
|
|
|
def _parse_linfo(self, linfo_path):
|
|
|
|
cp = ConfigParser()
|
|
|
|
cp.read([linfo_path])
|
|
|
|
|
2007-03-23 18:18:42 +01:00
|
|
|
section = 'Activity'
|
|
|
|
|
|
|
|
if cp.has_option(section, 'name'):
|
2007-03-23 17:27:31 +01:00
|
|
|
self._name = cp.get(section, 'name')
|
|
|
|
|
|
|
|
def _get_linfo_path(self):
|
|
|
|
path = None
|
|
|
|
lang = locale.getdefaultlocale()[0]
|
|
|
|
if lang != None:
|
2007-03-23 17:43:40 +01:00
|
|
|
path = os.path.join(self.get_locale_path(), lang)
|
2007-03-23 18:18:42 +01:00
|
|
|
if not os.path.isdir(path):
|
2007-03-23 17:27:31 +01:00
|
|
|
path = os.path.join(self._path, 'locale', lang[:2])
|
|
|
|
if not os.path.isdir(path):
|
|
|
|
path = None
|
|
|
|
|
|
|
|
if path:
|
|
|
|
return os.path.join(path, 'activity.linfo')
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
def is_valid(self):
|
|
|
|
return self._valid
|
|
|
|
|
2007-03-23 17:43:40 +01:00
|
|
|
def get_locale_path(self):
|
|
|
|
"""Get the locale path inside the activity bundle."""
|
|
|
|
return os.path.join(self._path, 'locale')
|
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
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
|
|
|
|
|
|
|
|
def get_service_name(self):
|
|
|
|
"""Get the activity service name"""
|
|
|
|
return self._service_name
|
|
|
|
|
2007-02-21 17:53:44 +01:00
|
|
|
def get_object_path(self):
|
|
|
|
"""Get the path to the service object"""
|
|
|
|
return '/' + self._service_name.replace('.', '/')
|
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
def get_icon(self):
|
|
|
|
"""Get the activity icon name"""
|
|
|
|
return self._icon
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2007-02-22 15:46:13 +01:00
|
|
|
def get_class(self):
|
|
|
|
"""Get the main Activity class"""
|
2007-03-09 16:35:53 +01:00
|
|
|
return self._class
|
2007-02-22 15:46:13 +01:00
|
|
|
|
2007-05-24 17:53:57 +02:00
|
|
|
def get_mime_types(self):
|
|
|
|
"""Get the MIME types supported by the activity"""
|
|
|
|
return self._mime_types
|
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
def get_show_launcher(self):
|
|
|
|
"""Get whether there should be a visible launcher for the activity"""
|
|
|
|
return self._show_launcher
|