Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAleksey Lim <alsroot@sugarlabs.org>2013-06-12 08:02:33 (GMT)
committer Aleksey Lim <alsroot@sugarlabs.org>2013-06-12 08:02:33 (GMT)
commitb59d8f4ac340390636e6f26fbc437abef37f67a3 (patch)
tree2e3fbad5e6dcaa76f3c7b2549e9a968bc236d10c
parent5b002a923711f99b1f235697bb87c0dd91e97abf (diff)
Avoid needless bundle downloads on master node
-rw-r--r--sugar_network/resources/implementation.py27
-rwxr-xr-xtests/units/resources/implementation.py33
2 files changed, 53 insertions, 7 deletions
diff --git a/sugar_network/resources/implementation.py b/sugar_network/resources/implementation.py
index e038377..4abcd02 100644
--- a/sugar_network/resources/implementation.py
+++ b/sugar_network/resources/implementation.py
@@ -16,6 +16,7 @@
# pylint: disable-msg=E1101,E0102,E0202
import os
+from os.path import exists
import xapian
@@ -26,6 +27,10 @@ from sugar_network.toolkit.bundle import Bundle
from sugar_network.toolkit import http, util, enforce
+_ASLO_URL = 'http://download.sugarlabs.org/activities'
+_ASLO_PATH = '/upload/activities'
+
+
def _encode_version(version):
version = util.parse_version(version)
# Convert to [(`version`, `modifier`)]
@@ -107,13 +112,21 @@ class Implementation(Resource):
unpack_size += bundle.getmember(arcname).size
value['unpack_size'] = unpack_size
- if 'blob' in value:
- calc_unpack_size(value['blob'])
- elif 'url' in value:
- with util.NamedTemporaryFile() as f:
- http.download(value['url'], f.name)
- value['blob_size'] = os.stat(f.name).st_size
- calc_unpack_size(f.name)
+ if 'unpack_size' not in value:
+ if 'blob' in value:
+ calc_unpack_size(value['blob'])
+ elif 'url' in value:
+ url = value['url']
+ if url.startswith(_ASLO_URL):
+ local_path = _ASLO_PATH + url[len(_ASLO_URL):]
+ if exists(local_path):
+ calc_unpack_size(local_path)
+ value['blob_size'] = os.stat(local_path).st_size
+ if 'unpack_size' not in value:
+ with util.NamedTemporaryFile() as f:
+ http.download(url, f.name)
+ value['blob_size'] = os.stat(f.name).st_size
+ calc_unpack_size(f.name)
value['mime_type'] = 'application/vnd.olpc-sugar'
return value
diff --git a/tests/units/resources/implementation.py b/tests/units/resources/implementation.py
index b50344d..6ff73cb 100755
--- a/tests/units/resources/implementation.py
+++ b/tests/units/resources/implementation.py
@@ -9,6 +9,7 @@ from __init__ import tests
from sugar_network import db
from sugar_network.db.router import Router, route
+from sugar_network.resources import implementation
from sugar_network.resources.volume import Volume
from sugar_network.resources.implementation import _encode_version, Implementation
from sugar_network.node.commands import NodeCommands
@@ -132,6 +133,38 @@ class ImplementationTest(tests.Test):
self.assertEqual('http://127.0.0.1:9999/bundle', data['url'])
assert 'blob' not in data
+ def test_ActivityASLOUrls(self):
+ implementation._ASLO_PATH = '.'
+ bundle = self.zips(('topdir/probe', 'probe'))
+ with file('bundle', 'w') as f:
+ f.write(bundle)
+ unpack_size = len('probe')
+
+ self.start_online_client()
+ client = IPCClient()
+
+ context = client.post(['context'], {
+ 'type': 'activity',
+ 'title': 'title',
+ 'summary': 'summary',
+ 'description': 'description',
+ })
+ impl = client.post(['implementation'], {
+ 'context': context,
+ 'license': 'GPLv3+',
+ 'version': '1',
+ 'stability': 'stable',
+ 'notes': '',
+ })
+ client.put(['implementation', impl, 'data'], {'url': 'http://download.sugarlabs.org/activities/bundle'})
+
+ data = self.node_volume['implementation'].get(impl).meta('data')
+ self.assertEqual('application/vnd.olpc-sugar', data['mime_type'])
+ self.assertEqual(len(bundle), data['blob_size'])
+ self.assertEqual(unpack_size, data.get('unpack_size'))
+ self.assertEqual('http://download.sugarlabs.org/activities/bundle', data['url'])
+ assert 'blob' not in data
+
def test_WrongAuthor(self):
self.start_online_client()
client = IPCClient()