[ARVADOS] updated: 88f57312fe5e2226f113dc5ecb0a5edce018701d
git at public.curoverse.com
git at public.curoverse.com
Fri Apr 10 16:23:29 EDT 2015
Summary of changes:
sdk/python/arvados/collection.py | 57 ++++++++++++++++++++++++----------------
sdk/python/tests/test_arvfile.py | 7 ++---
2 files changed, 39 insertions(+), 25 deletions(-)
via 88f57312fe5e2226f113dc5ecb0a5edce018701d (commit)
from de7c71aac6a8e93f84d515e42859cce674eab009 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
commit 88f57312fe5e2226f113dc5ecb0a5edce018701d
Author: Peter Amstutz <peter.amstutz at curoverse.com>
Date: Fri Apr 10 16:24:22 2015 -0400
5692: Backed out commit_all() from Collection.manifest_text().
Collection.save() and Collection.save_new() now return unstripped manifest
text.
diff --git a/sdk/python/arvados/collection.py b/sdk/python/arvados/collection.py
index 3641472..497bf7f 100644
--- a/sdk/python/arvados/collection.py
+++ b/sdk/python/arvados/collection.py
@@ -831,8 +831,7 @@ class RichCollectionBase(CollectionBase):
:strip:
If True, remove signing tokens from block locators if present.
- If False (default), block locators are left unchanged. Note: if
- strip is False, this will also flush any open files (committing blocks to Keep).
+ If False (default), block locators are left unchanged.
:normalize:
If True, always export the manifest text in normalized form
@@ -843,9 +842,6 @@ class RichCollectionBase(CollectionBase):
"""
if self.modified() or self._manifest_text is None or normalize:
- if strip is False:
- self._my_block_manager().commit_all()
-
stream = {}
buf = []
sorted_keys = sorted(self.keys())
@@ -1253,7 +1249,8 @@ class Collection(RichCollectionBase):
"""Save collection to an existing collection record.
Commit pending buffer blocks to Keep, merge with remote record (if
- merge=True, the default), and update the collection record.
+ merge=True, the default), and update the collection record. Returns
+ the current manifest text.
Will raise AssertionError if not associated with a collection record on
the API server. If you want to save a manifest to Keep only, see
@@ -1271,6 +1268,8 @@ class Collection(RichCollectionBase):
if not self._has_collection_uuid():
raise AssertionError("Collection manifest_locator must be a collection uuid. Use save_new() for new collections.")
+ self._my_block_manager().commit_all()
+
if merge:
self.update()
@@ -1283,21 +1282,31 @@ class Collection(RichCollectionBase):
self._manifest_text = self._api_response["manifest_text"]
self.set_unmodified()
+ return self._manifest_text
+
@must_be_writable
@synchronized
@retry_method
- def save_new(self, name=None, owner_uuid=None, ensure_unique_name=False, num_retries=None):
+ def save_new(self, name=None,
+ create_collection_record=True,
+ owner_uuid=None,
+ ensure_unique_name=False,
+ num_retries=None):
"""Save collection to a new collection record.
- Commit pending buffer blocks to Keep and create a new collection record
- (if create_collection_record True). After creating a new collection
- record, this Collection object will be associated with the new record
- used by `save()`.
+ Commit pending buffer blocks to Keep and, when create_collection_record
+ is True (default), create a new collection record. After creating a
+ new collection record, this Collection object will be associated with
+ the new record used by `save()`. Returns the current manifest text.
:name:
The collection name.
+ :create_collection_record:
+ If True, create a collection record on the API server.
+ If False, only commit blocks to Keep and return the manifest text.
+
:owner_uuid:
the user, or project uuid that will own this collection.
If None, defaults to the current user.
@@ -1311,23 +1320,27 @@ class Collection(RichCollectionBase):
Retry count on API calls (if None, use the collection default)
"""
+ self._my_block_manager().commit_all()
text = self.manifest_text(strip=False)
- if name is None:
- name = "Collection created %s" % (time.strftime("%Y-%m-%d %H:%M:%S %Z", time.localtime()))
+ if create_collection_record:
+ if name is None:
+ name = "Collection created %s" % (time.strftime("%Y-%m-%d %H:%M:%S %Z", time.localtime()))
- body = {"manifest_text": text,
- "name": name}
- if owner_uuid:
- body["owner_uuid"] = owner_uuid
+ body = {"manifest_text": text,
+ "name": name}
+ if owner_uuid:
+ body["owner_uuid"] = owner_uuid
- self._api_response = self._my_api().collections().create(ensure_unique_name=ensure_unique_name, body=body).execute(num_retries=num_retries)
- text = self._api_response["manifest_text"]
+ self._api_response = self._my_api().collections().create(ensure_unique_name=ensure_unique_name, body=body).execute(num_retries=num_retries)
+ text = self._api_response["manifest_text"]
- self._manifest_locator = self._api_response["uuid"]
+ self._manifest_locator = self._api_response["uuid"]
- self._manifest_text = text
- self.set_unmodified()
+ self._manifest_text = text
+ self.set_unmodified()
+
+ return text
@synchronized
def subscribe(self, callback):
diff --git a/sdk/python/tests/test_arvfile.py b/sdk/python/tests/test_arvfile.py
index a8da557..08b5ad3 100644
--- a/sdk/python/tests/test_arvfile.py
+++ b/sdk/python/tests/test_arvfile.py
@@ -149,14 +149,15 @@ class ArvadosFileWriterTestCase(unittest.TestCase):
self.assertEqual(writer.size(), 0)
self.assertEqual(". d41d8cd98f00b204e9800998ecf8427e+0 0:0:count.txt\n", c.manifest_text())
- def test_get_manifest_text_commits(self):
+ def test_save_manifest_text(self):
keep = ArvadosFileWriterTestCase.MockKeep({})
with Collection(keep_client=keep) as c:
writer = c.open("count.txt", "w")
writer.write("0123456789")
- self.assertEqual('. 781e5e245d69b566979b86e28d23f2c7+10 0:10:count.txt\n', c.manifest_text(strip=True))
+ self.assertEqual('. 781e5e245d69b566979b86e28d23f2c7+10 0:10:count.txt\n', c.manifest_text())
self.assertNotIn('781e5e245d69b566979b86e28d23f2c7+10', keep.blocks)
- self.assertEqual('. 781e5e245d69b566979b86e28d23f2c7+10 0:10:count.txt\n', c.manifest_text(strip=False))
+
+ self.assertEqual('. 781e5e245d69b566979b86e28d23f2c7+10 0:10:count.txt\n', c.save_new(create_collection_record=False))
self.assertIn('781e5e245d69b566979b86e28d23f2c7+10', keep.blocks)
def test_write_in_middle(self):
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list