diff options
Diffstat (limited to 'sugar_network/client')
-rw-r--r-- | sugar_network/client/cache.py | 2 | ||||
-rw-r--r-- | sugar_network/client/implementations.py | 26 | ||||
-rw-r--r-- | sugar_network/client/journal.py | 11 |
3 files changed, 22 insertions, 17 deletions
diff --git a/sugar_network/client/cache.py b/sugar_network/client/cache.py index 554dde4..07daa16 100644 --- a/sugar_network/client/cache.py +++ b/sugar_network/client/cache.py @@ -138,7 +138,7 @@ class Cache(object): stat = os.statvfs(client.local_root.value) if stat.f_blocks == 0: - # TODO Sonds like a tmpfs or so + # TODO Sounds like a tmpfs or so return 0 limit = sys.maxint diff --git a/sugar_network/client/implementations.py b/sugar_network/client/implementations.py index f78df33..ca9e89c 100644 --- a/sugar_network/client/implementations.py +++ b/sugar_network/client/implementations.py @@ -24,6 +24,7 @@ import random import shutil import hashlib import logging +from copy import deepcopy from os.path import join, exists, basename, dirname, relpath from sugar_network import client, toolkit @@ -227,7 +228,7 @@ class Routes(object): def cache_impl(sel): guid = sel['guid'] data = sel['data'] - data_path = sel['path'] = impls.path(guid, 'data') + sel['path'] = impls.path(guid, 'data') size = data.get('unpack_size') or data['blob_size'] blob = None @@ -240,33 +241,36 @@ class Routes(object): if blob is None: blob = self._call(method='GET', path=['implementation', guid, 'data']) - try: - if not exists(dirname(data_path)): - os.makedirs(dirname(data_path)) + + blob_dir = dirname(sel['path']) + if not exists(blob_dir): + os.makedirs(blob_dir) + + with toolkit.mkdtemp(dir=blob_dir) as blob_dir: if 'activity' in context['type']: self._cache.ensure(size, data['blob_size']) with toolkit.TemporaryFile() as tmp_file: shutil.copyfileobj(blob, tmp_file) tmp_file.seek(0) with Bundle(tmp_file, 'application/zip') as bundle: - bundle.extractall(data_path, prefix=bundle.rootdir) + bundle.extractall(blob_dir, prefix=bundle.rootdir) for exec_dir in ('bin', 'activity'): - bin_path = join(data_path, exec_dir) + bin_path = join(blob_dir, exec_dir) if not exists(bin_path): continue for filename in os.listdir(bin_path): os.chmod(join(bin_path, filename), 0755) + blob = blob_dir else: self._cache.ensure(size) - with file(data_path, 'wb') as f: + with file(join(blob_dir, 'data'), 'wb') as f: shutil.copyfileobj(blob, f) - impl = sel.copy() + blob = f.name + impl = deepcopy(sel) impl['mtime'] = impl['ctime'] + impl['data']['blob'] = blob impls.create(impl) return cache_call(guid, size) - except Exception: - shutil.rmtree(data_path, ignore_errors=True) - raise result = [] for sel in request.session['solution']: diff --git a/sugar_network/client/journal.py b/sugar_network/client/journal.py index 646bced..ee2a2f3 100644 --- a/sugar_network/client/journal.py +++ b/sugar_network/client/journal.py @@ -90,7 +90,7 @@ class Routes(object): # Do not break SN like API guid = item['guid'] = item.pop('uid') if has_preview: - item['preview'] = _preview_url(guid) + item['preview'] = _preview(guid) return {'result': result, 'total': int(total)} @@ -100,7 +100,7 @@ class Routes(object): return {'guid': guid, 'title': get(guid, 'title'), 'description': get(guid, 'description'), - 'preview': _preview_url(guid), + 'preview': _preview(guid), } @route('GET', ['journal', None, 'preview']) @@ -193,6 +193,7 @@ def _prop_path(guid, prop): return _ds_path(guid, 'metadata', prop) -def _preview_url(guid): - return 'http://127.0.0.1:%s/journal/%s/preview' % \ - (client.ipc_port.value, guid) +def _preview(guid): + return {'url': 'http://127.0.0.1:%s/journal/%s/preview' % + (client.ipc_port.value, guid), + } |