-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Storage] Fix storage table outputs and help text. #1402
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
src/command_modules/azure-cli-storage/azure/cli/command_modules/storage/_format.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
# -------------------------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# -------------------------------------------------------------------------------------------- | ||
|
||
# pylint:disable=line-too-long | ||
|
||
from collections import OrderedDict | ||
|
||
def build_table_output(result, projection): | ||
|
||
if not isinstance(result, list): | ||
result = [result] | ||
|
||
final_list = [] | ||
|
||
for item in result: | ||
def _value_from_path(path): | ||
obj = item # pylint: disable=cell-var-from-loop | ||
try: | ||
for part in path.split('.'): | ||
obj = obj.get(part, None) | ||
except AttributeError: | ||
obj = None | ||
return obj or ' ' | ||
|
||
item_dict = OrderedDict() | ||
for element in projection: | ||
item_dict[element[0]] = _value_from_path(element[1]) | ||
final_list.append(item_dict) | ||
return final_list | ||
|
||
def transform_container_list(result): | ||
return build_table_output(result, [ | ||
('Name', 'name'), | ||
('Lease Status', 'properties.leaseStatus'), | ||
('Last Modified', 'properties.lastModified') | ||
]) | ||
|
||
def transform_container_show(result): | ||
return build_table_output(result, [ | ||
('Name', 'name'), | ||
('Lease Status', 'properties.lease.status'), | ||
('Last Modified', 'properties.lastModified') | ||
]) | ||
|
||
def transform_blob_output(result): | ||
return build_table_output(result, [ | ||
('Name', 'name'), | ||
('Blob Type', 'properties.blobType'), | ||
('Length', 'properties.contentLength'), | ||
('Content Type', 'properties.contentSettings.contentType'), | ||
('Last Modified', 'properties.lastModified') | ||
]) | ||
|
||
def transform_share_list(result): | ||
return build_table_output(result, [ | ||
('Name', 'name'), | ||
('Quota', 'properties.quota'), | ||
('Last Modified', 'properties.lastModified') | ||
]) | ||
|
||
def transform_file_output(result): | ||
""" Transform to convert SDK file/dir list output to something that | ||
more clearly distinguishes between files and directories. """ | ||
new_result = [] | ||
|
||
for item in result.get('items', [result]): | ||
new_entry = OrderedDict() | ||
item_name = item['name'] | ||
try: | ||
_ = item['properties']['contentLength'] | ||
is_dir = False | ||
except KeyError: | ||
item_name = '{}/'.format(item_name) | ||
is_dir = True | ||
new_entry['Name'] = item_name | ||
new_entry['Content Length'] = ' ' if is_dir else item['properties']['contentLength'] | ||
new_entry['Type'] = 'dir' if is_dir else 'file' | ||
new_entry['Last Modified'] = item['properties']['lastModified'] or ' ' | ||
new_result.append(new_entry) | ||
return sorted(new_result, key=lambda k: k['Name']) | ||
|
||
def transform_entity_show(result): | ||
timestamp = result.pop('Timestamp') | ||
result.pop('etag') | ||
|
||
# Reassemble the output | ||
new_result = OrderedDict() | ||
new_result['Partition'] = result.pop('PartitionKey') | ||
new_result['Row'] = result.pop('RowKey') | ||
for key in sorted(result.keys()): | ||
new_result[key] = result[key] | ||
new_result['Timestamp'] = timestamp | ||
return new_result | ||
|
||
def transform_message_show(result): | ||
ordered_result = [] | ||
for item in result: | ||
new_result = OrderedDict() | ||
new_result['MessageId'] = item.pop('id') | ||
new_result['Content'] = item.pop('content') | ||
new_result['InsertionTime'] = item.pop('insertionTime') | ||
new_result['ExpirationTime'] = item.pop('expirationTime') | ||
for key in sorted(item.keys()): | ||
new_result[key] = item[key] | ||
ordered_result.append(new_result) | ||
return ordered_result | ||
|
||
def transform_boolean_for_table(result): | ||
for key in result: | ||
result[key] = str(result[key]) | ||
return result |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will
item['properties']['lastModified']
always exist?Or is this check to see if
item['properties']['lastModified']
is False, empty etc.?Otherwise, you may get a KeyError.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If lastModified is null, then what happens is the table just leaves that column off. The
or ' '
ensures that it at least has a space so you will get a blank "cell". Otherwise your table dynamic when it really isn't.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay that works