[ARVADOS] updated: 9ca7acc39ed2e1e2100869e17be3e5cff7c835b6
Git user
git at public.curoverse.com
Mon Jun 19 15:10:42 EDT 2017
Summary of changes:
sdk/python/arvados/commands/put.py | 21 ++++++++++++++-------
sdk/python/tests/test_arv_put.py | 18 +++++++++++++++++-
2 files changed, 31 insertions(+), 8 deletions(-)
via 9ca7acc39ed2e1e2100869e17be3e5cff7c835b6 (commit)
from cf9874c59fa5a73d395743aaf71555b441161e3e (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 9ca7acc39ed2e1e2100869e17be3e5cff7c835b6
Author: Lucas Di Pentima <lucas at curoverse.com>
Date: Mon Jun 19 16:08:02 2017 -0300
11788: Added conditional behaviour when using, or not, a trailing slash on directory references.
Added test to cover all cases & updated help message.
Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <lucas at curoverse.com>
diff --git a/sdk/python/arvados/commands/put.py b/sdk/python/arvados/commands/put.py
index 73842c9..e591656 100644
--- a/sdk/python/arvados/commands/put.py
+++ b/sdk/python/arvados/commands/put.py
@@ -39,7 +39,9 @@ upload_opts.add_argument('--version', action='version',
help='Print version and exit.')
upload_opts.add_argument('paths', metavar='path', type=str, nargs='*',
help="""
-Local file or directory. Default: read from standard input.
+Local file or directory. If path is a directory reference with a trailing
+slash, then just upload the directory's contents; otherwise upload the
+directory itself. Default: read from standard input.
""")
_group = upload_opts.add_mutually_exclusive_group()
@@ -438,12 +440,17 @@ class ArvPutUploadJob(object):
elif os.path.isdir(path):
# Use absolute paths on cache index so CWD doesn't interfere
# with the caching logic.
- prefixdir = path = os.path.abspath(path)
-
- if prefixdir[-1:] == '/':
- prefixdir = prefixdir[:-1]
- prefixdir = os.path.dirname(prefixdir) + '/'
-
+ orig_path = path
+ path = os.path.abspath(path)
+ if orig_path[-1:] == os.sep:
+ # When passing a directory reference with a trailing slash,
+ # its contents should be uploaded directly to the collection's root.
+ prefixdir = path
+ else:
+ # When passing a directory reference with no trailing slash,
+ # upload the directory to the collection's root.
+ prefixdir = os.path.dirname(path)
+ prefixdir += os.sep
for root, dirs, files in os.walk(path, followlinks=self.follow_links):
# Make os.walk()'s dir traversing order deterministic
dirs.sort()
diff --git a/sdk/python/tests/test_arv_put.py b/sdk/python/tests/test_arv_put.py
index 3e9c945..c2eaf12 100644
--- a/sdk/python/tests/test_arv_put.py
+++ b/sdk/python/tests/test_arv_put.py
@@ -841,7 +841,7 @@ class ArvPutIntegrationTest(run_test_server.TestCaseWithServers,
c = arv_put.api_client.collections().get(uuid=updated_col['uuid']).execute()
self.assertRegex(c['manifest_text'], r'^\..* .*:44:file2\n')
- def test_upload_directory_reference_as_subcollection(self):
+ def test_upload_directory_reference_without_trailing_slash(self):
tmpdir1 = self.make_tmpdir()
tmpdir2 = self.make_tmpdir()
with open(os.path.join(tmpdir1, 'foo'), 'w') as f:
@@ -858,6 +858,22 @@ class ArvPutIntegrationTest(run_test_server.TestCaseWithServers,
# OTOH, 'bar' should have been directly uploaded on the root collection
self.assertRegex(c['manifest_text'], r'^\. .*:15:bar\n\./.+ .*:11:foo\n')
+ def test_upload_directory_reference_with_trailing_slash(self):
+ tmpdir1 = self.make_tmpdir()
+ tmpdir2 = self.make_tmpdir()
+ with open(os.path.join(tmpdir1, 'foo'), 'w') as f:
+ f.write('This is foo')
+ with open(os.path.join(tmpdir2, 'bar'), 'w') as f:
+ f.write('This is not foo')
+ # Upload one directory (with trailing slash) and one file
+ col = self.run_and_find_collection("", ['--no-progress',
+ tmpdir1 + os.sep,
+ os.path.join(tmpdir2, 'bar')])
+ self.assertNotEqual(None, col['uuid'])
+ c = arv_put.api_client.collections().get(uuid=col['uuid']).execute()
+ # Check that 'foo' and 'bar' were written at the same level
+ self.assertRegex(c['manifest_text'], r'^\. .*:15:bar .*:11:foo\n')
+
def test_put_collection_with_high_redundancy(self):
# Write empty data: we're not testing CollectionWriter, just
# making sure collections.create tells the API server what our
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list