Merge "Improve list --versions
output"
This commit is contained in:
@@ -534,7 +534,7 @@ def st_list(parser, args, output_manager, return_parser=False):
|
|||||||
container = stats.get("container", None)
|
container = stats.get("container", None)
|
||||||
for item in stats["listing"]:
|
for item in stats["listing"]:
|
||||||
item_name = item.get('name')
|
item_name = item.get('name')
|
||||||
if not options['long'] and not human:
|
if not options['long'] and not human and not options['versions']:
|
||||||
output_manager.print_msg(item.get('name', item.get('subdir')))
|
output_manager.print_msg(item.get('name', item.get('subdir')))
|
||||||
else:
|
else:
|
||||||
if not container: # listing containers
|
if not container: # listing containers
|
||||||
@@ -566,9 +566,16 @@ def st_list(parser, args, output_manager, return_parser=False):
|
|||||||
date = xtime = ''
|
date = xtime = ''
|
||||||
item_name = subdir
|
item_name = subdir
|
||||||
if not options['totals']:
|
if not options['totals']:
|
||||||
output_manager.print_msg(
|
if options['versions']:
|
||||||
"%s %10s %8s %24s %s",
|
output_manager.print_msg(
|
||||||
byte_str, date, xtime, content_type, item_name)
|
"%s %10s %8s %16s %24s %s",
|
||||||
|
byte_str, date, xtime,
|
||||||
|
item.get('version_id', 'null'),
|
||||||
|
content_type, item_name)
|
||||||
|
else:
|
||||||
|
output_manager.print_msg(
|
||||||
|
"%s %10s %8s %24s %s",
|
||||||
|
byte_str, date, xtime, content_type, item_name)
|
||||||
total_bytes += item_bytes
|
total_bytes += item_bytes
|
||||||
|
|
||||||
# report totals
|
# report totals
|
||||||
|
@@ -334,8 +334,15 @@ class TestShell(unittest.TestCase):
|
|||||||
def test_list_container_with_versions(self, connection):
|
def test_list_container_with_versions(self, connection):
|
||||||
connection.return_value.get_container.side_effect = [
|
connection.return_value.get_container.side_effect = [
|
||||||
[None, [
|
[None, [
|
||||||
{'name': 'foo', 'version_id': '2'},
|
{'name': 'foo', 'version_id': '2',
|
||||||
{'name': 'foo', 'version_id': '1'},
|
'content_type': 'text/plain',
|
||||||
|
'last_modified': '123T456', 'bytes': 78},
|
||||||
|
{'name': 'foo', 'version_id': '1',
|
||||||
|
'content_type': 'text/rtf',
|
||||||
|
'last_modified': '123T456', 'bytes': 90},
|
||||||
|
{'name': 'bar', 'version_id': 'null',
|
||||||
|
'content_type': 'text/plain',
|
||||||
|
'last_modified': '123T456', 'bytes': 123},
|
||||||
]],
|
]],
|
||||||
[None, []],
|
[None, []],
|
||||||
]
|
]
|
||||||
@@ -346,10 +353,46 @@ class TestShell(unittest.TestCase):
|
|||||||
prefix=None, query_string='versions=true',
|
prefix=None, query_string='versions=true',
|
||||||
version_marker=''),
|
version_marker=''),
|
||||||
mock.call('container', delimiter=None, headers={},
|
mock.call('container', delimiter=None, headers={},
|
||||||
marker='foo', prefix=None,
|
marker='bar', prefix=None,
|
||||||
query_string='versions=true', version_marker='1')]
|
query_string='versions=true',
|
||||||
|
version_marker='null')]
|
||||||
connection.return_value.get_container.assert_has_calls(calls)
|
connection.return_value.get_container.assert_has_calls(calls)
|
||||||
self.assertEqual(output.out, 'foo\nfoo\n')
|
self.assertEqual([line.split() for line in output.out.split('\n')], [
|
||||||
|
['78', '123', '456', '2', 'text/plain', 'foo'],
|
||||||
|
['90', '123', '456', '1', 'text/rtf', 'foo'],
|
||||||
|
['123', '123', '456', 'null', 'text/plain', 'bar'],
|
||||||
|
[],
|
||||||
|
])
|
||||||
|
|
||||||
|
@mock.patch('swiftclient.service.Connection')
|
||||||
|
def test_list_container_with_versions_old_swift(self, connection):
|
||||||
|
# Versions of swift that don't support object-versioning won't
|
||||||
|
# include verison_id keys in listings. We want to present that
|
||||||
|
# as though the container is unversioned.
|
||||||
|
connection.return_value.get_container.side_effect = [
|
||||||
|
[None, [
|
||||||
|
{'name': 'foo', 'content_type': 'text/plain',
|
||||||
|
'last_modified': '123T456', 'bytes': 78},
|
||||||
|
{'name': 'bar', 'content_type': 'text/plain',
|
||||||
|
'last_modified': '123T456', 'bytes': 123},
|
||||||
|
]],
|
||||||
|
[None, []],
|
||||||
|
]
|
||||||
|
argv = ["", "list", "container", "--versions"]
|
||||||
|
with CaptureOutput(suppress_systemexit=True) as output:
|
||||||
|
swiftclient.shell.main(argv)
|
||||||
|
calls = [mock.call('container', delimiter=None, headers={}, marker='',
|
||||||
|
prefix=None, query_string='versions=true',
|
||||||
|
version_marker=''),
|
||||||
|
mock.call('container', delimiter=None, headers={},
|
||||||
|
marker='bar', prefix=None,
|
||||||
|
query_string='versions=true', version_marker='')]
|
||||||
|
connection.return_value.get_container.assert_has_calls(calls)
|
||||||
|
self.assertEqual([line.split() for line in output.out.split('\n')], [
|
||||||
|
['78', '123', '456', 'null', 'text/plain', 'foo'],
|
||||||
|
['123', '123', '456', 'null', 'text/plain', 'bar'],
|
||||||
|
[],
|
||||||
|
])
|
||||||
|
|
||||||
def test_list_account_with_versions(self):
|
def test_list_account_with_versions(self):
|
||||||
argv = ["", "list", "--versions"]
|
argv = ["", "list", "--versions"]
|
||||||
|
Reference in New Issue
Block a user