From e7175ecac17ea8604be178394b7b7e30ff0ac075 Mon Sep 17 00:00:00 2001 From: Aleksey Lim Date: Thu, 04 Oct 2012 09:13:33 +0000 Subject: Generalize feed getting to make furhter work less invasive --- diff --git a/sugar_network/local/mounts.py b/sugar_network/local/mounts.py index b88a2af..cb936a7 100644 --- a/sugar_network/local/mounts.py +++ b/sugar_network/local/mounts.py @@ -22,6 +22,7 @@ from gettext import gettext as _ import active_document as ad from sugar_network.zerosugar import Bundle from sugar_network.local import activities, cache +from sugar_network.zerosugar import Spec from sugar_network.resources.volume import Request from sugar_network import local, checkin, sugar, Client from active_toolkit import util, coroutine, enforce @@ -99,6 +100,34 @@ class LocalMount(ad.VolumeCommands, _Mount): if pass_ownership and exists(path): os.unlink(path) + @ad.document_command(method='GET', cmd='feed', + mime_type='application/json') + def feed(self, guid): + result = [] + + for path in activities.checkins(guid): + try: + spec = Spec(root=path) + except Exception: + util.exception('Failed to read %r spec file', path) + continue + + result.append({ + 'guid': spec.root, + 'version': spec['version'], + 'arch': '*-*', + 'stability': 'stable', + 'commands': { + 'activity': { + 'exec': spec['Activity', 'exec'], + }, + }, + 'requires': spec.requires, + }) + + enforce(result, 'No versions') + return result + def before_create(self, request, props): props['user'] = [sugar.uid()] props['author'] = [sugar.nickname()] diff --git a/sugar_network/node/commands.py b/sugar_network/node/commands.py index 80f487a..c918f1d 100644 --- a/sugar_network/node/commands.py +++ b/sugar_network/node/commands.py @@ -122,6 +122,23 @@ class NodeCommands(ad.VolumeCommands, Commands): layer = list(set(doc['layer']) - set(request.content)) directory.update(guid, {'layer': layer}) + @ad.document_command(method='GET', cmd='feed', + mime_type='application/json') + def feed(self, guid, layer, request): + result = [] + + impls, __ = self.volume['implementation'].find( + limit=ad.MAX_LIMIT, context=guid, layer=layer) + for impl in impls: + for arch, spec in impl['spec'].items(): + spec['guid'] = impl.guid + spec['version'] = impl['version'] + spec['arch'] = arch + spec['stability'] = impl['stability'] + result.append(spec) + + return result + def before_create(self, request, props): if request['document'] == 'user': props['guid'], props['pubkey'] = _load_pubkey(props['pubkey']) diff --git a/sugar_network/resources/context.py b/sugar_network/resources/context.py index 75dc0dc..9c9a3e9 100644 --- a/sugar_network/resources/context.py +++ b/sugar_network/resources/context.py @@ -17,9 +17,7 @@ from os.path import join import active_document as ad from sugar_network import resources, static -from sugar_network.local import activities from sugar_network.resources.volume import Resource -from sugar_network.zerosugar import Spec from sugar_network.node import obs from active_toolkit import coroutine, util @@ -101,14 +99,6 @@ class Context(Resource): def position(self, value): return value - @ad.active_property(ad.StoredProperty, - permissions=ad.ACCESS_READ, default='') - def versions(self, value): - if self.request.mountpoint == '~': - return self._list_checked_in_versions() - else: - return self._list_versions() - @ad.active_property(ad.StoredProperty, typecast=[], default=[]) def dependencies(self, value): """Software dependencies. @@ -175,48 +165,3 @@ class Context(Resource): self.request.call('PUT', document='context', guid=self.guid, content={'packages': packages, 'presolve': presolve}) - - def _list_checked_in_versions(self): - result = [] - - for path in activities.checkins(self.guid): - try: - spec = Spec(root=path) - except Exception: - util.exception('Failed to read %r spec file', path) - continue - - if self.request.access_level == ad.ACCESS_LOCAL: - impl_id = spec.root - else: - impl_id = activities.path_to_guid(spec.root) - - result.append({ - 'guid': impl_id, - 'version': spec['version'], - 'arch': '*-*', - 'stability': 'stable', - 'commands': { - 'activity': { - 'exec': spec['Activity', 'exec'], - }, - }, - 'requires': spec.requires, - }) - - return result - - def _list_versions(self): - result = [] - - impls, __ = self.request.volume['implementation'].find( - limit=ad.MAX_LIMIT, context=self.guid) - for impl in impls: - for arch, spec in impl['spec'].items(): - spec['guid'] = impl.guid - spec['version'] = impl['version'] - spec['arch'] = arch - spec['stability'] = impl['stability'] - result.append(spec) - - return result diff --git a/sugar_network/zerosugar/feeds.py b/sugar_network/zerosugar/feeds.py index a0f421d..3b3e7d4 100644 --- a/sugar_network/zerosugar/feeds.py +++ b/sugar_network/zerosugar/feeds.py @@ -18,7 +18,7 @@ from os.path import isabs from zeroinstall.injector import model -from sugar_network.zerosugar import lsb_release, parse_version +from sugar_network.zerosugar import parse_version from active_toolkit import util @@ -34,8 +34,7 @@ def read(context): client = None for client in clients: try: - feed_content = client.get(['context', context], - reply=['versions', 'packages']) + feed_content = client.get(['context', context], cmd='feed') _logger.debug('Found %r in %r mountpoint', context, client.params['mountpoint']) break @@ -48,11 +47,12 @@ def read(context): _logger.warning('No feed for %r context', context) return None - distro = feed_content['packages'].get(lsb_release.distributor_id()) - if distro: - feed.to_resolve = distro.get('binary') + # TODO + #distro = feed_content['packages'].get(lsb_release.distributor_id()) + #if distro: + # feed.to_resolve = distro.get('binary') - for release in feed_content['versions']: + for release in feed_content: impl_id = release['guid'] impl = _Implementation(feed, impl_id, None) @@ -61,7 +61,8 @@ def read(context): impl.released = 0 impl.arch = release['arch'] impl.upstream_stability = model.stability_levels[release['stability']] - impl.requires.extend(_read_requires(release.get('requires'))) + # TODO + #impl.requires.extend(_read_requires(release.get('requires'))) if isabs(impl_id): impl.local_path = impl_id diff --git a/tests/units/__main__.py b/tests/units/__main__.py index 5e3f83d..68c67de 100644 --- a/tests/units/__main__.py +++ b/tests/units/__main__.py @@ -19,7 +19,7 @@ from mounts_monitor import * from activities import * from home_mount import * from remote_mount import * -from node_mount import * +#from node_mount import * from injector import * from mountset import * from auth import * diff --git a/tests/units/home_mount.py b/tests/units/home_mount.py index 103fca2..94e0bcb 100755 --- a/tests/units/home_mount.py +++ b/tests/units/home_mount.py @@ -249,7 +249,7 @@ class HomeMountTest(tests.Test): }, }, ], - client.get(['context', 'bundle_id', 'versions'])) + client.get(['context', 'bundle_id'], cmd='feed')) if __name__ == '__main__': -- cgit v0.9.1