From c288d54ab84f7381b7354f5ea8574b8522c547e6 Mon Sep 17 00:00:00 2001 From: Sam Parkinson Date: Thu, 14 Jul 2016 16:16:25 +1000 Subject: [PATCH 1/5] Bundlebuilder: submodules can have "/.git" as a file When created via "git submodules add", a submodules may have the "/.git" path be a file rather than a directory. The bundlebuilder previously thought that all submodules had "/.git" as a directory. --- src/sugar3/activity/bundlebuilder.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sugar3/activity/bundlebuilder.py b/src/sugar3/activity/bundlebuilder.py index 25819f61..ae70b695 100644 --- a/src/sugar3/activity/bundlebuilder.py +++ b/src/sugar3/activity/bundlebuilder.py @@ -205,7 +205,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)) From 7779c74f447ca165effc649451cefb87c2abf842 Mon Sep 17 00:00:00 2001 From: Sam Parkinson Date: Thu, 14 Jul 2016 16:20:22 +1000 Subject: [PATCH 2/5] Bundlebuilder: Use installed icon path in .desktop file Previously, the bundle builder referenced the icon path in the source directory - which was obviously not installed in the package. --- src/sugar3/activity/bundlebuilder.py | 3 ++- src/sugar3/bundle/activitybundle.py | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/sugar3/activity/bundlebuilder.py b/src/sugar3/activity/bundlebuilder.py index ae70b695..74020586 100644 --- a/src/sugar3/activity/bundlebuilder.py +++ b/src/sugar3/activity/bundlebuilder.py @@ -333,7 +333,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 diff --git a/src/sugar3/bundle/activitybundle.py b/src/sugar3/bundle/activitybundle.py index b7628baa..414489c8 100644 --- a/src/sugar3/bundle/activitybundle.py +++ b/src/sugar3/bundle/activitybundle.py @@ -286,6 +286,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 From 6d337718d1dcd460605a0d6efb57c814c57d5179 Mon Sep 17 00:00:00 2001 From: Sam Parkinson Date: Thu, 14 Jul 2016 21:57:23 +1000 Subject: [PATCH 3/5] Bundlebuilder: Generate AppStream AppData files This commit adds the 1st pass generator for these files. It also adds documentation about the required fields in the "activity.info" file, as AppStream requires more metadata than most activities currently include. --- src/sugar3/activity/bundlebuilder.py | 127 ++++++++++++++++++++++++++- 1 file changed, 124 insertions(+), 3 deletions(-) diff --git a/src/sugar3/activity/bundlebuilder.py b/src/sugar3/activity/bundlebuilder.py index 74020586..0da50acf 100644 --- a/src/sugar3/activity/bundlebuilder.py +++ b/src/sugar3/activity/bundlebuilder.py @@ -1,4 +1,5 @@ # Copyright (C) 2008 Red Hat, Inc. +# Copyright (C) 2016 Sam Parkinson # # 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: +

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.

+

To help in researching, Browse offers many features:

+
    +
  • Bookmark (save) good pages you find - never loose good resources or forget to add them to your bibliography
  • +
  • Bookmark pages with collaborators in real time - great for researching as a group or teachers showing pages to their class
  • +
  • Comment on your bookmarked pages - a great tool for making curated collections
  • +
+ 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,7 @@ import logging from glob import glob from fnmatch import fnmatch from ConfigParser import ConfigParser +import xml.etree.cElementTree as ET from sugar3 import env from sugar3.bundle.activitybundle import ActivityBundle @@ -304,6 +369,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() @@ -345,6 +411,61 @@ 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, 'id').text = \ + self.config.bundle_id + '.activity.desktop' + desc = ET.fromstring('{}'.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='repository').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""" From 9b5ed7e80c5caa6e99aaeee72d96ccc336aba9da Mon Sep 17 00:00:00 2001 From: Sam Parkinson Date: Fri, 15 Jul 2016 09:16:18 +1000 Subject: [PATCH 4/5] Bundlebuilder: Translate AppData files --- src/sugar3/activity/bundlebuilder.py | 26 ++++++++++++++++++++++++-- src/sugar3/bundle/activitybundle.py | 11 +++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/sugar3/activity/bundlebuilder.py b/src/sugar3/activity/bundlebuilder.py index 0da50acf..57a83f5a 100644 --- a/src/sugar3/activity/bundlebuilder.py +++ b/src/sugar3/activity/bundlebuilder.py @@ -99,6 +99,7 @@ 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 @@ -147,6 +148,7 @@ class Config(object): self.xo_name = None self.tar_name = None self.summary = None + self.description = None self.update() @@ -157,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) @@ -430,6 +433,8 @@ class Installer(Packager): # 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('{}'.format( @@ -558,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""" @@ -581,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', diff --git a/src/sugar3/bundle/activitybundle.py b/src/sugar3/bundle/activitybundle.py index 414489c8..cf60b305 100644 --- a/src/sugar3/bundle/activitybundle.py +++ b/src/sugar3/bundle/activitybundle.py @@ -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': @@ -310,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 From 2f9ae6ef51ec0845537eaa3aad6083fda35f7780 Mon Sep 17 00:00:00 2001 From: Sam Parkinson Date: Sat, 16 Jul 2016 07:55:57 +1000 Subject: [PATCH 5/5] Bundlebuilder: relabel repository url as bugtracker Many activities already have the repository url pointing to their GitHub page - which also serves as a bug tracker for many of the projects. The repository url is not part of the spec, but the bug tracker url is. --- src/sugar3/activity/bundlebuilder.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sugar3/activity/bundlebuilder.py b/src/sugar3/activity/bundlebuilder.py index 57a83f5a..313909b9 100644 --- a/src/sugar3/activity/bundlebuilder.py +++ b/src/sugar3/activity/bundlebuilder.py @@ -461,7 +461,7 @@ class Installer(Packager): ET.SubElement(root, 'url', type='homepage').text = \ info.get('Activity', 'url') if info.has_option('Activity', 'repository_url'): - ET.SubElement(root, 'url', type='repository').text = \ + ET.SubElement(root, 'url', type='bugtracker').text = \ info.get('Activity', 'repository_url') path = os.path.join(prefix, 'share', 'metainfo',