Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/sugar_network/resources/context.py
diff options
context:
space:
mode:
Diffstat (limited to 'sugar_network/resources/context.py')
-rw-r--r--sugar_network/resources/context.py83
1 files changed, 51 insertions, 32 deletions
diff --git a/sugar_network/resources/context.py b/sugar_network/resources/context.py
index d5f5340..75dc0dc 100644
--- a/sugar_network/resources/context.py
+++ b/sugar_network/resources/context.py
@@ -101,39 +101,13 @@ class Context(Resource):
def position(self, value):
return value
- @ad.active_property(ad.StoredProperty, typecast=dict, default={})
+ @ad.active_property(ad.StoredProperty,
+ permissions=ad.ACCESS_READ, default='')
def versions(self, value):
- if self.request.mountpoint != '~':
- return value
-
- versions = {}
-
- 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)
-
- versions[spec['version']] = {
- '*-*': {
- 'guid': impl_id,
- 'stability': 'stable',
- 'commands': {
- 'activity': {
- 'exec': spec['Activity', 'exec'],
- },
- },
- 'requires': spec.requires,
- },
- }
-
- return versions
+ 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):
@@ -201,3 +175,48 @@ 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