Sam Parkinson 8 years ago
commit 61bc42f2c2
No known key found for this signature in database
GPG Key ID: 34E268B2FA2F8B13

@ -1,4 +1,5 @@
# Copyright (C) 2008 Red Hat, Inc.
# Copyright (C) 2016 Sam Parkinson <sam@sam.today>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
@ -15,9 +16,72 @@
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
"""
STABLE.
"""
'''
The bundle builder provides a build system for Sugar activities. Usually, it
is setup by creating a `setup.py` file in the project with the following::
# setup.py
#!/usr/bin/env python
from sugar3.activity import bundlebuilder
bundlebuilder.start()
AppStream Metadata
==================
AppStream is the standard, distro-agnostic way of providing package metadata.
For Sugar activities, the AppStream metadata is automatically exported from
the activity.info file by the bundlebuilder.
Activities must have the following metadata fields under the [Activity] header
(of the `activity.info` file):
* `metadata_license` - license for screenshots and description. AppStream
requests only using one of the following: `CC0-1.0`, `CC-BY-3.0`,
`CC-BY-SA-3.0` or `GFDL-1.3`
* `license` - a `SPDX License Code`__, eg. `GPL-3.0+`
* `name`, `icon`, `bundle_id`, `summary` - same usage as in Sugar
* `description` - a long (multi paragraph) description of your application.
This must be written in a subset of HTML. Only the p, ol, ul and li tags
are supported.
Other good metadata items to have are:
* `url` - link to the home page for the activity on the internet
* `repository_url` - link to repository for activity code
* `screenshots` - a space separated list of screenshot URLs. PNG or JPEG files
are supported.
__ http://spdx.org/licenses/
Example `activity.info`
-----------------------
.. code-block:: ini
:emphasize-lines: 10-12,20-21
[Activity]
name = Browse
bundle_id = org.laptop.WebActivity
exec = sugar-activity webactivity.WebActivity
activity_version = 200
icon = activity-web
max_participants = 100
summary = Surf the world!
license = GPL-2.0+
metadata_license = CC0-1.0
description:
<p>Surf the world! Here you can do research, watch educational videos, take online courses, find books, connect with friends and more. Browse is powered by the WebKit2 rendering engine with the Faster Than Light javascript interpreter - allowing you to view the full beauty of the web.</p>
<p>To help in researching, Browse offers many features:</p>
<ul>
<li>Bookmark (save) good pages you find - never loose good resources or forget to add them to your bibliography</li>
<li>Bookmark pages with collaborators in real time - great for researching as a group or teachers showing pages to their class</li>
<li>Comment on your bookmarked pages - a great tool for making curated collections</li>
</ul>
url = https://github.com/sugarlabs/browse-activity
screenshots = https://people.sugarlabs.org/sam/activity-ss/browse-1-1.png https://people.sugarlabs.org/sam/activity-ss/browse-1-2.png
'''
import argparse
import operator
@ -34,6 +98,8 @@ import logging
from glob import glob
from fnmatch import fnmatch
from ConfigParser import ConfigParser
import xml.etree.cElementTree as ET
from HTMLParser import HTMLParser
from sugar3 import env
from sugar3.bundle.activitybundle import ActivityBundle
@ -82,6 +148,7 @@ class Config(object):
self.xo_name = None
self.tar_name = None
self.summary = None
self.description = None
self.update()
@ -92,6 +159,7 @@ class Config(object):
self.activity_name = bundle.get_name()
self.bundle_id = bundle.get_bundle_id()
self.summary = bundle.get_summary()
self.description = bundle.get_description()
self.bundle_name = reduce(operator.add, self.activity_name.split())
self.bundle_root_dir = self.bundle_name + '.activity'
self.tar_root_dir = '%s-%s' % (self.bundle_name, self.version)
@ -205,7 +273,7 @@ class Packager(object):
if not ignore:
sub_path = os.path.join(root, line)
if os.path.isdir(sub_path) \
and os.path.isdir(os.path.join(sub_path, '.git')):
and os.path.exists(os.path.join(sub_path, '.git')):
sub_list = self.get_files_in_git(sub_path)
for f in sub_list:
files.append(os.path.join(line, f))
@ -304,6 +372,7 @@ class Installer(Packager):
if install_desktop_file:
self._install_desktop_file(prefix, activity_path)
self._generate_appdata(prefix, activity_path)
def _install_desktop_file(self, prefix, activity_path):
cp = ConfigParser()
@ -333,7 +402,8 @@ class Installer(Packager):
cp.set(section, 'Terminal', 'false')
cp.set(section, 'Type', 'Application')
cp.set(section, 'Categories', 'Education;')
cp.set(section, 'Icon', self.config.bundle.get_icon())
cp.set(section, 'Icon', os.path.join(
activity_path, 'activity', self.config.bundle.get_icon_filename()))
cp.set(section, 'Exec', self.config.bundle.get_command())
cp.set(section, 'Path', activity_path) # Path == CWD for running
@ -344,6 +414,63 @@ class Installer(Packager):
with open(path, 'w') as f:
cp.write(f)
def _generate_appdata(self, prefix, activity_path):
info = ConfigParser()
info.read(os.path.join(activity_path, 'activity', 'activity.info'))
required_fields = ['metadata_license', 'license', 'name', 'icon',
'description']
for name in required_fields:
if not info.has_option('Activity', name):
print('[WARNING] Activity needs more metadata for AppStream '
'file')
print(' Without an AppStream file, the activity will NOT '
'show in software stores!')
print(' Please `pydoc sugar3.activity.bundlebuilder` for'
'more info')
return
# See https://www.freedesktop.org/software/appstream/docs/
root = ET.Element('component', type='desktop')
ET.SubElement(root, 'project_group').text = 'Sugar'
ET.SubElement(root, 'translation', type='gettext').text = \
self.config.bundle_id
ET.SubElement(root, 'id').text = \
self.config.bundle_id + '.activity.desktop'
desc = ET.fromstring('<description>{}</description>'.format(
info.get('Activity', 'description')))
root.append(desc)
copy_pairs = [('metadata_license', 'metadata_license'),
('license', 'project_license'),
('summary', 'summary'),
('name', 'name')]
for key, ename in copy_pairs:
ET.SubElement(root, ename).text = info.get('Activity', key)
if info.has_option('Activity', 'screenshots'):
screenshots = info.get('Activity', 'screenshots').split()
ss_root = ET.SubElement(root, 'screenshots')
for i, screenshot in enumerate(screenshots):
e = ET.SubElement(ss_root, 'screenshot')
if i == 0:
e.set('type', 'default')
ET.SubElement(e, 'image').text = screenshot
if info.has_option('Activity', 'url'):
ET.SubElement(root, 'url', type='homepage').text = \
info.get('Activity', 'url')
if info.has_option('Activity', 'repository_url'):
ET.SubElement(root, 'url', type='bugtracker').text = \
info.get('Activity', 'repository_url')
path = os.path.join(prefix, 'share', 'metainfo',
self.config.bundle_id + '.appdata.xml')
if not os.path.isdir(os.path.dirname(path)):
os.makedirs(os.path.dirname(path))
tree = ET.ElementTree(root)
tree.write(path, encoding='UTF-8')
def cmd_check(config, options):
"""Run tests for the activity"""
@ -436,6 +563,10 @@ def cmd_install(config, options):
installer.install(options.prefix, options.install_mime)
def _po_escape(string):
return re.sub('([\\\\"])', '\\\\\\1', string)
def cmd_genpot(config, options):
"""Generate the gettext pot file"""
@ -459,16 +590,29 @@ def cmd_genpot(config, options):
# to the end of the .pot file afterwards, because that might
# create a duplicate msgid.)
pot_file = os.path.join('po', '%s.pot' % config.bundle_name)
escaped_name = re.sub('([\\\\"])', '\\\\\\1', config.activity_name)
escaped_name = _po_escape(config.activity_name)
f = open(pot_file, 'w')
f.write('#: activity/activity.info:2\n')
f.write('msgid "%s"\n' % escaped_name)
f.write('msgstr ""\n')
if config.summary is not None:
escaped_summary = re.sub('([\\\\"])', '\\\\\\1', config.summary)
escaped_summary = _po_escape(config.summary)
f.write('#: activity/activity.info:3\n')
f.write('msgid "%s"\n' % escaped_summary)
f.write('msgstr ""\n')
if config.description is not None:
parser = HTMLParser()
strings = []
parser.handle_data = strings.append
parser.feed(config.description)
for s in strings:
s = s.strip()
if s:
f.write('#: activity/activity.info:4\n')
f.write('msgid "%s"\n' % _po_escape(s))
f.write('msgstr ""\n')
f.close()
args = ['xgettext', '--join-existing', '--language=Python',

@ -111,6 +111,7 @@ class ActivityBundle(Bundle):
self._tags = None
self._activity_version = '0'
self._summary = None
self._description = None
self._single_instance = False
self._max_participants = 0
@ -194,6 +195,8 @@ class ActivityBundle(Bundle):
if cp.has_option(section, 'summary'):
self._summary = cp.get(section, 'summary')
if cp.has_option(section, 'description'):
self._description = cp.get(section, 'description')
if cp.has_option(section, 'single_instance'):
if cp.get(section, 'single_instance') == 'yes':
@ -286,6 +289,10 @@ class ActivityBundle(Bundle):
os.close(temp_file)
return temp_file_path
def get_icon_filename(self):
'''Get the icon file name'''
return self._icon + '.svg'
def get_activity_version(self):
"""Get the activity version"""
return self._activity_version
@ -306,6 +313,14 @@ class ActivityBundle(Bundle):
"""Get the summary that describe the activity"""
return self._summary
def get_description(self):
"""
Get the description for the activity. The description is a
pace of multi paragraph text about the activity. It is written
in a HTML subset using only the p, ul, li and ol tags.
"""
return self._description
def get_single_instance(self):
"""Get whether there should be a single instance for the activity"""
return self._single_instance

Loading…
Cancel
Save