Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAleksey Lim <alsroot@sugarlabs.org>2012-10-02 15:09:47 (GMT)
committer Aleksey Lim <alsroot@sugarlabs.org>2012-10-02 15:09:47 (GMT)
commitf4052d1cf38132aaab56c9228e18fa791aa1be57 (patch)
treed1187723aea8074c44bb164eb00ec9902d22d9b2
parentef69b25a9ba9c34abe0493026162790bbb5ea424 (diff)
Fix launching; calculate feeds instead of storing
-rw-r--r--sugar_network/local/mounts.py7
-rw-r--r--sugar_network/local/mountset.py4
-rw-r--r--sugar_network/resources/context.py83
-rw-r--r--sugar_network/zerosugar/feeds.py52
-rw-r--r--tests/__init__.py8
-rwxr-xr-xtests/units/home_mount.py50
-rwxr-xr-xtests/units/injector.py30
-rwxr-xr-xtests/units/node_mount.py5
8 files changed, 120 insertions, 119 deletions
diff --git a/sugar_network/local/mounts.py b/sugar_network/local/mounts.py
index f19505d..7a2c292 100644
--- a/sugar_network/local/mounts.py
+++ b/sugar_network/local/mounts.py
@@ -215,7 +215,12 @@ class _ProxyCommands(object):
if home.exists(guid):
home.update(guid, patch)
elif [True for prop, value in patch.items() if value]:
- copy = Request(method='GET', document='context', guid=guid)
+ copy = Request(method='GET', document='context', guid=guid,
+ reply=[
+ 'type', 'implement', 'title', 'summary',
+ 'description', 'homepage', 'mime_types',
+ 'dependencies',
+ ])
copy.accept_language = request.accept_language
props = super_call(copy, ad.Response())
props.update(patch)
diff --git a/sugar_network/local/mountset.py b/sugar_network/local/mountset.py
index ac81e5d..9cc7de6 100644
--- a/sugar_network/local/mountset.py
+++ b/sugar_network/local/mountset.py
@@ -114,6 +114,10 @@ class Mountset(dict, ad.CommandsProcessor, Commands, SyncCommands):
content={'keep': True}),
ad.Response())
+ @ad.volume_command(method='POST', cmd='publish')
+ def _publish(self, request):
+ self.publish(request.content)
+
def super_call(self, request, response):
if 'mountpoint' in request:
mountpoint = request.mountpoint = request.pop('mountpoint')
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
diff --git a/sugar_network/zerosugar/feeds.py b/sugar_network/zerosugar/feeds.py
index 8141434..a0f421d 100644
--- a/sugar_network/zerosugar/feeds.py
+++ b/sugar_network/zerosugar/feeds.py
@@ -52,33 +52,31 @@ def read(context):
if distro:
feed.to_resolve = distro.get('binary')
- for version, version_data in feed_content['versions'].items():
- for arch, impl_data in version_data.items():
- impl_id = impl_data['guid']
-
- impl = _Implementation(feed, impl_id, None)
- impl.client = client
- impl.version = parse_version(version)
- impl.released = 0
- impl.arch = arch
- impl.upstream_stability = \
- model.stability_levels[impl_data['stability']]
- impl.requires.extend(_read_requires(impl_data.get('requires')))
-
- if isabs(impl_id):
- impl.local_path = impl_id
- else:
- impl.add_download_source(impl_id,
- impl_data.get('size') or 0, impl_data.get('extract'))
-
- for name, command in impl_data['commands'].items():
- impl.commands[name] = _Command(name, command)
-
- for name, insert, mode in impl_data.get('bindings') or []:
- binding = model.EnvironmentBinding(name, insert, mode=mode)
- impl.bindings.append(binding)
-
- feed.implementations[impl_id] = impl
+ for release in feed_content['versions']:
+ impl_id = release['guid']
+
+ impl = _Implementation(feed, impl_id, None)
+ impl.client = client
+ impl.version = parse_version(release['version'])
+ impl.released = 0
+ impl.arch = release['arch']
+ impl.upstream_stability = model.stability_levels[release['stability']]
+ impl.requires.extend(_read_requires(release.get('requires')))
+
+ if isabs(impl_id):
+ impl.local_path = impl_id
+ else:
+ impl.add_download_source(impl_id,
+ release.get('size') or 0, release.get('extract'))
+
+ for name, command in release['commands'].items():
+ impl.commands[name] = _Command(name, command)
+
+ for name, insert, mode in release.get('bindings') or []:
+ binding = model.EnvironmentBinding(name, insert, mode=mode)
+ impl.bindings.append(binding)
+
+ feed.implementations[impl_id] = impl
return feed
diff --git a/tests/__init__.py b/tests/__init__.py
index a1850af..a638110 100644
--- a/tests/__init__.py
+++ b/tests/__init__.py
@@ -25,6 +25,7 @@ from sugar_network.local.mountset import Mountset
from sugar_network import local, node
from sugar_network.resources.user import User
from sugar_network.resources.context import Context
+from sugar_network.resources.implementation import Implementation
from sugar_network.node.commands import NodeCommands, MasterCommands
from sugar_network.node.router import Router as MasterRouter
from sugar_network.node import stats, obs, auth
@@ -97,6 +98,7 @@ class Test(unittest.TestCase):
'sugar_network.resources.user',
'sugar_network.resources.context',
'sugar_network.resources.report',
+ 'sugar_network.resources.implementation',
]
sugar.nickname = lambda: 'test'
@@ -226,7 +228,7 @@ class Test(unittest.TestCase):
def start_server(self, classes=None, root=True):
if classes is None:
- classes = [User, Context]
+ classes = [User, Context, Implementation]
volume = Volume('local', classes)
self.mounts = Mountset(volume)
self.mounts['~'] = HomeMount(volume)
@@ -264,7 +266,7 @@ class Test(unittest.TestCase):
node.find_limit.value = 1024
ad.index_write_queue.value = 10
- volume = Volume('remote', classes or [User, Context])
+ volume = Volume('remote', classes or [User, Context, Implementation])
cp = NodeCommands(volume)
httpd = coroutine.WSGIServer(('localhost', 8800), Router(cp))
try:
@@ -277,7 +279,7 @@ class Test(unittest.TestCase):
def start_master(self, classes=None):
if classes is None:
- classes = [User, Context]
+ classes = [User, Context, Implementation]
self.touch('master/master')
self.volume = Volume('master', classes)
cp = MasterCommands(self.volume)
diff --git a/tests/units/home_mount.py b/tests/units/home_mount.py
index 3bbaab1..2312154 100755
--- a/tests/units/home_mount.py
+++ b/tests/units/home_mount.py
@@ -222,37 +222,37 @@ class HomeMountTest(tests.Test):
self.mounts.volume['context'], ['Activities'])
coroutine.sleep()
- self.assertEqual({
- '1': {
- '*-*': {
- 'commands': {
- 'activity': {
- 'exec': 'false',
- },
+ self.assertEqual([
+ {
+ 'version': '1',
+ 'arch': '*-*',
+ 'commands': {
+ 'activity': {
+ 'exec': 'false',
},
- 'stability': 'stable',
- 'guid': tests.tmpdir + '/Activities/activity-1',
- 'requires': {},
},
+ 'stability': 'stable',
+ 'guid': tests.tmpdir + '/Activities/activity-1',
+ 'requires': {},
},
- '2': {
- '*-*': {
- 'commands': {
- 'activity': {
- 'exec': 'true',
- },
- },
- 'stability': 'stable',
- 'guid': tests.tmpdir + '/Activities/activity-2',
- 'requires': {
- 'dep1': {},
- 'dep2': {'restrictions': [['1', '2']]},
- 'dep3': {'restrictions': [[None, '2']]},
- 'dep4': {'restrictions': [['3', None]]},
+ {
+ 'version': '2',
+ 'arch': '*-*',
+ 'commands': {
+ 'activity': {
+ 'exec': 'true',
},
},
+ 'stability': 'stable',
+ 'guid': tests.tmpdir + '/Activities/activity-2',
+ 'requires': {
+ 'dep1': {},
+ 'dep2': {'restrictions': [['1', '2']]},
+ 'dep3': {'restrictions': [[None, '2']]},
+ 'dep4': {'restrictions': [['3', None]]},
+ },
},
- },
+ ],
client.get(['context', 'bundle_id', 'versions']))
diff --git a/tests/units/injector.py b/tests/units/injector.py
index 21333da..26fe744 100755
--- a/tests/units/injector.py
+++ b/tests/units/injector.py
@@ -49,10 +49,7 @@ class InjectorTest(tests.Test):
'date': 0,
'stability': 'stable',
'notes': '',
- })
-
- remote.put(['context', context, 'versions'], {
- '1': {
+ 'spec': {
'*-*': {
'commands': {
'activity': {
@@ -60,7 +57,6 @@ class InjectorTest(tests.Test):
},
},
'stability': 'stable',
- 'guid': impl,
'size': 0,
},
},
@@ -113,9 +109,7 @@ class InjectorTest(tests.Test):
'date': 0,
'stability': 'stable',
'notes': '',
- })
- remote.put(['context', context, 'versions'], {
- '1': {
+ 'spec': {
'*-*': {
'commands': {
'activity': {
@@ -123,7 +117,6 @@ class InjectorTest(tests.Test):
},
},
'stability': 'stable',
- 'guid': impl,
'size': 0,
'extract': 'TestActivitry',
},
@@ -164,23 +157,7 @@ class InjectorTest(tests.Test):
'date': 0,
'stability': 'stable',
'notes': '',
- })
-
- remote.put(['context', context, 'versions'], {
- '1': {
- '*-*': {
- 'commands': {
- 'activity': {
- 'exec': 'false',
- },
- },
- 'stability': 'stable',
- 'guid': impl,
- 'size': 0,
- 'extract': 'TestActivitry',
- },
- },
- '2': {
+ 'spec': {
'*-*': {
'commands': {
'activity': {
@@ -188,7 +165,6 @@ class InjectorTest(tests.Test):
},
},
'stability': 'stable',
- 'guid': impl_2,
'size': 0,
'extract': 'TestActivitry',
},
diff --git a/tests/units/node_mount.py b/tests/units/node_mount.py
index 4f0ef0e..cac4c71 100755
--- a/tests/units/node_mount.py
+++ b/tests/units/node_mount.py
@@ -185,9 +185,7 @@ class NodeMountTest(tests.Test):
'date': 0,
'stability': 'stable',
'notes': '',
- })
- remote.put(['context', context, 'versions'], {
- '1': {
+ 'spec': {
'*-*': {
'commands': {
'activity': {
@@ -195,7 +193,6 @@ class NodeMountTest(tests.Test):
},
},
'stability': 'stable',
- 'guid': impl,
'size': 0,
'extract': 'TestActivitry',
},