Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAleksey Lim <alsroot@sugarlabs.org>2014-01-04 14:08:25 (GMT)
committer Aleksey Lim <alsroot@sugarlabs.org>2014-01-04 14:08:25 (GMT)
commit5955e4a46d48dd6099e56e17b7fa545be46de540 (patch)
tree44ae6e2bf357d7d63886b16d0571ba60155f31be
parentd58594abe1b9b1f3faf041c418c6d1a57b68ccc7 (diff)
Populate Implementation.notes by CHANGELOG content from newly uploaded bundles
-rw-r--r--sugar_network/node/routes.py5
-rw-r--r--sugar_network/toolkit/bundle.py20
-rwxr-xr-xtests/units/node/node.py9
3 files changed, 30 insertions, 4 deletions
diff --git a/sugar_network/node/routes.py b/sugar_network/node/routes.py
index 80f8893..ebb46a8 100644
--- a/sugar_network/node/routes.py
+++ b/sugar_network/node/routes.py
@@ -511,7 +511,12 @@ def load_bundle(volume, request, bundle_path):
unpack_size = 0
with bundle:
+ changelog = join(bundle.rootdir, 'CHANGELOG')
for arcname in bundle.get_names():
+ if changelog and arcname == changelog:
+ with bundle.extractfile(changelog) as f:
+ impl['notes'] = f.read()
+ changelog = None
unpack_size += bundle.getmember(arcname).size
spec = bundle.get_spec()
context_meta = _load_context_metadata(bundle, spec)
diff --git a/sugar_network/toolkit/bundle.py b/sugar_network/toolkit/bundle.py
index 7d484ad..70ecd57 100644
--- a/sugar_network/toolkit/bundle.py
+++ b/sugar_network/toolkit/bundle.py
@@ -66,7 +66,7 @@ class Bundle(object):
return self._do_extract(name, dst_path)
def extractfile(self, name):
- return self._do_extractfile(name)
+ return _File(self._do_extractfile(name))
def extractall(self, dst_root, members=None, prefix=None):
if not prefix:
@@ -85,7 +85,8 @@ class Bundle(object):
if not exists(dirname(dst_path)):
os.makedirs(dirname(dst_path))
with file(dst_path, 'wb') as dst:
- shutil.copyfileobj(self.extractfile(arcname), dst)
+ with self.extractfile(arcname) as src:
+ shutil.copyfileobj(src, dst)
except Exception:
if exists(dst_root):
shutil.rmtree(dst_root)
@@ -164,3 +165,18 @@ class _ZipInfo(object):
@property
def size(self):
return self._info.file_size
+
+
+class _File(object):
+
+ def __init__(self, fileobj):
+ self._fileobj = fileobj
+
+ def __getattr__(self, name):
+ return getattr(self._fileobj, name)
+
+ def __enter__(self):
+ return self
+
+ def __exit__(self, *args):
+ self._fileobj.close()
diff --git a/tests/units/node/node.py b/tests/units/node/node.py
index 5c7cb58..f97df3a 100755
--- a/tests/units/node/node.py
+++ b/tests/units/node/node.py
@@ -713,7 +713,11 @@ class NodeTest(tests.Test):
'stability = developer',
'requires = sugar>=0.88; dep'
])
- bundle1 = self.zips(('topdir/activity/activity.info', activity_info))
+ changelog = "LOG"
+ bundle1 = self.zips(
+ ('topdir/activity/activity.info', activity_info),
+ ('topdir/CHANGELOG', changelog),
+ )
guid1 = json.load(conn.request('POST', ['implementation'], bundle1, params={'cmd': 'submit'}).raw)
impl = volume['implementation'].get(guid1)
@@ -722,6 +726,7 @@ class NodeTest(tests.Test):
self.assertEqual('developer', impl['stability'])
self.assertEqual(['Public Domain'], impl['license'])
self.assertEqual('developer', impl['stability'])
+ self.assertEqual({'en-us': changelog}, impl['notes'])
assert impl['ctime'] > 0
assert impl['mtime'] > 0
self.assertEqual({tests.UID: {'role': 3, 'name': 'f470db873b6a35903aca1f2492188e1c4b9ffc42', 'order': 0}}, impl['author'])
@@ -737,7 +742,7 @@ class NodeTest(tests.Test):
self.assertEqual('application/vnd.olpc-sugar', data['mime_type'])
self.assertEqual(len(bundle1), data['blob_size'])
- self.assertEqual(len(activity_info), data.get('unpack_size'))
+ self.assertEqual(len(activity_info) + len(changelog), data.get('unpack_size'))
self.assertEqual(bundle1, conn.get(['context', 'bundle_id'], cmd='clone', stability='developer'))
activity_info = '\n'.join([