diff options
author | Aleksey Lim <alsroot@sugarlabs.org> | 2013-04-27 13:56:48 (GMT) |
---|---|---|
committer | Aleksey Lim <alsroot@sugarlabs.org> | 2013-04-27 13:57:07 (GMT) |
commit | 91c103c921311bccddedebf9f5d33a40ef17b131 (patch) | |
tree | d99a443074a3b4983cd073bb4c69c43bf86509d0 | |
parent | ea65c6f09e9fc50837a130a8e5ed92de93a7fa53 (diff) |
Support Sugar API compatibility ranges to run activities that don't have up-to-date sugar version ranges
-rw-r--r-- | sugar_network/client/__init__.py | 4 | ||||
-rw-r--r-- | sugar_network/client/solver.py | 10 | ||||
-rwxr-xr-x | tests/units/client/injector.py | 37 |
3 files changed, 38 insertions, 13 deletions
diff --git a/sugar_network/client/__init__.py b/sugar_network/client/__init__.py index 07205c1..e5e75bd 100644 --- a/sugar_network/client/__init__.py +++ b/sugar_network/client/__init__.py @@ -20,6 +20,10 @@ from os.path import join, expanduser, exists from sugar_network.toolkit import Option, util +SUGAR_API_COMPATIBILITY = { + '0.94': frozenset(['0.86', '0.88', '0.90', '0.92', '0.94']), + } + _NICKNAME_GCONF = '/desktop/sugar/user/nick' _COLOR_GCONF = '/desktop/sugar/user/color' _XO_SERIAL_PATH = ['/ofw/mfg-data/SN', '/proc/device-tree/mfg-data/SN'] diff --git a/sugar_network/client/solver.py b/sugar_network/client/solver.py index 27832ea..812bf1e 100644 --- a/sugar_network/client/solver.py +++ b/sugar_network/client/solver.py @@ -17,7 +17,7 @@ import sys import logging from os.path import isabs, join, dirname -from sugar_network.client import packagekit +from sugar_network.client import packagekit, SUGAR_API_COMPATIBILITY from sugar_network.toolkit import util, lsb_release, pipe, exception sys.path.insert(0, join(dirname(__file__), '..', 'lib', 'zeroinstall')) @@ -151,7 +151,8 @@ def _load_feed(conn, context): try: # pylint: disable-msg=F0401 from jarabe import config - feed.implement_sugar(config.version) + for version in SUGAR_API_COMPATIBILITY.get(config.version) or []: + feed.implement_sugar(version) feed.name = context return feed except ImportError: @@ -242,13 +243,14 @@ class _Feed(model.ZeroInstallFeed): self.implementations[impl_id] = impl def implement_sugar(self, sugar_version): - impl = _Implementation(self, self.context, None) + impl_id = 'sugar-%s' % sugar_version + impl = _Implementation(self, impl_id, None) impl.version = util.parse_version(sugar_version) impl.released = 0 impl.arch = '*-*' impl.upstream_stability = model.stability_levels['packaged'] impl.local_path = '/' - self.implementations[self.context] = impl + self.implementations[impl_id] = impl class _Implementation(model.ZeroInstallImplementation): diff --git a/tests/units/client/injector.py b/tests/units/client/injector.py index f53074d..3d2d853 100755 --- a/tests/units/client/injector.py +++ b/tests/units/client/injector.py @@ -792,7 +792,7 @@ class InjectorTest(tests.Test): def test_SolveSugar(self): self.touch(('__init__.py', '')) - self.touch(('jarabe.py', 'class config: version = "777"')) + self.touch(('jarabe.py', 'class config: version = "0.94"')) file_, pathname_, description_ = imp.find_module('jarabe', ['.']) imp.load_module('jarabe', file_, pathname_, description_) @@ -805,6 +805,14 @@ class InjectorTest(tests.Test): 'summary': 'summary', 'description': 'description', }) + conn.post(['context'], { + 'guid': 'sugar', + 'type': 'package', + 'title': 'title', + 'summary': 'summary', + 'description': 'description', + }) + impl = conn.post(['implementation'], { 'context': context, 'license': 'GPLv3+', @@ -823,17 +831,28 @@ class InjectorTest(tests.Test): }, }, }}) - conn.post(['context'], { - 'guid': 'sugar', - 'type': 'package', - 'title': 'title', - 'summary': 'summary', - 'description': 'description', - }) + self.assertEqual([ + {'name': 'title', 'version': '1', 'command': ['echo'], 'context': context, 'id': impl, 'stability': 'stable'}, + {'name': 'sugar', 'version': '0.94', 'context': 'sugar', 'path': '/', 'id': 'sugar-0.94', 'stability': 'packaged'}, + ], + solver.solve(conn, context)) + conn.put(['implementation', impl], { + 'spec': { + '*-*': { + 'commands': { + 'activity': { + 'exec': 'echo', + }, + }, + 'requires': { + 'sugar': {'restrictions': [['0.80', '0.87']]}, + }, + }, + }}) self.assertEqual([ {'name': 'title', 'version': '1', 'command': ['echo'], 'context': context, 'id': impl, 'stability': 'stable'}, - {'name': 'sugar', 'version': '777', 'context': 'sugar', 'path': '/', 'id': 'sugar', 'stability': 'packaged'}, + {'name': 'sugar', 'version': '0.86', 'context': 'sugar', 'path': '/', 'id': 'sugar-0.86', 'stability': 'packaged'}, ], solver.solve(conn, context)) |