diff options
author | Aleksey Lim <alsroot@sugarlabs.org> | 2013-05-05 07:47:30 (GMT) |
---|---|---|
committer | Aleksey Lim <alsroot@sugarlabs.org> | 2013-05-05 07:48:30 (GMT) |
commit | 9d513e249375c89beba588eef259d19235f98b2e (patch) | |
tree | 16beef91452fc41bf1b3870d880882a8825b9bf7 | |
parent | 2ca1d2d6fbc729bf1b871e71dffc67ede50ec7d0 (diff) |
Cache solutions for nodeps clone commands
That makes possible launching activities in offline without
asking packageskit for package dependencies.
-rw-r--r-- | sugar_network/client/commands.py | 10 | ||||
-rw-r--r-- | sugar_network/client/injector.py | 33 | ||||
-rw-r--r-- | sugar_network/client/spec.py | 2 | ||||
-rwxr-xr-x | tests/units/client/injector.py | 4 |
4 files changed, 32 insertions, 17 deletions
diff --git a/sugar_network/client/commands.py b/sugar_network/client/commands.py index 8fe21d1..6dde83d 100644 --- a/sugar_network/client/commands.py +++ b/sugar_network/client/commands.py @@ -459,13 +459,9 @@ class ClientCommands(db.CommandsProcessor, Commands, journal.Commands): self._checkin_context(guid, {'clone': 1}) if request.get('nodeps'): - impls = self._node_call(method='GET', document='implementation', - context=guid, stability=request.get('stability'), - requires=request.get('requires'), - order_by='-version', limit=1, - reply=['guid', 'spec'])['result'] - enforce(impls, http.NotFound, 'No implementations') - pipe = injector.clone_impl(guid, **impls[0]) + pipe = injector.clone_impl(guid, + stability=request.get('stability'), + requires=request.get('requires')) else: pipe = injector.clone(guid) diff --git a/sugar_network/client/injector.py b/sugar_network/client/injector.py index d341aa2..b7bb82f 100644 --- a/sugar_network/client/injector.py +++ b/sugar_network/client/injector.py @@ -21,7 +21,7 @@ from os.path import join, exists, basename, dirname from sugar_network import client from sugar_network.client import journal, cache -from sugar_network.toolkit import pipe, lsb_release, util +from sugar_network.toolkit import http, pipe, lsb_release, util, enforce _PMS_PATHS = { @@ -75,10 +75,10 @@ def clone(guid): context=guid, session={'context': guid}) -def clone_impl(context, guid, spec): +def clone_impl(context, **params): return pipe.fork(_clone_impl, - log_path=client.profile_path('logs', context), guid=guid, - spec=spec, session={'context': context}) + log_path=client.profile_path('logs', context), context=context, + params=params, session={'context': context}) def invalidate_solutions(mtime): @@ -150,10 +150,16 @@ def _clone(context): _set_cached_solution(context, solution) -def _clone_impl(guid, spec): - spec = spec['*-*'] - - src_path = cache.get(guid) +def _clone_impl(context, params): + conn = client.IPCClient() + impls = conn.get(['implementation'], context=context, order_by='-version', + limit=1, reply=['guid', 'version', 'stability', 'spec'], + **params)['result'] + enforce(impls, http.NotFound, 'No implementations') + + impl = impls[0] + spec = impl['spec']['*-*'] + src_path = cache.get(impl['guid']) if 'extract' in spec: src_path = join(src_path, spec['extract']) dst_path = util.unique_filename( @@ -162,6 +168,17 @@ def _clone_impl(guid, spec): _logger.info('Clone implementation to %r', dst_path) util.cptree(src_path, dst_path) + _set_cached_solution(context, [{ + 'id': dst_path, + 'context': context, + 'version': impl['version'], + 'name': 'TODO', + 'stability': impl['stability'], + 'spec': join(dst_path, 'activity', 'activity.info'), + 'path': dst_path, + 'command': spec['commands']['activity']['exec'].split(), + }]) + def _solve(context): pipe.trace('Start solving %s feed', context) diff --git a/sugar_network/client/spec.py b/sugar_network/client/spec.py index ab20a48..95f6334 100644 --- a/sugar_network/client/spec.py +++ b/sugar_network/client/spec.py @@ -117,7 +117,7 @@ class Spec(object): if key in _FIELDS: return self._fields.get(key) section = 'DEFAULT' - return self._config.get(section, key) + return self._get(section, key) def __repr__(self): return '<Spec %s>' % self['implement'] diff --git a/tests/units/client/injector.py b/tests/units/client/injector.py index e0c9096..964f334 100755 --- a/tests/units/client/injector.py +++ b/tests/units/client/injector.py @@ -142,7 +142,7 @@ class InjectorTest(tests.Test): bundle.writestr('topdir/probe', 'probe') bundle.close() - pipe = injector.clone_impl(context, impl, {'*-*': {'extract': 'topdir'}}) + pipe = injector.clone_impl(context) log_path = tests.tmpdir + '/.sugar/default/logs/%s.log' % context self.assertEqual([ {'state': 'fork', 'context': context}, @@ -152,6 +152,8 @@ class InjectorTest(tests.Test): [i for i in pipe]) assert exists('cache/implementation/%s' % impl) assert exists('Activities/topdir/probe') + __, (solution,) = json.load(file('cache/solutions/%s/%s' % (context[:2], context))) + self.assertEqual(tests.tmpdir + '/Activities/topdir', solution['path']) self.assertEqual('probe', file('Activities/topdir/probe').read()) def test_clone_CachedSolutionPointsToClonedPath(self): |