diff options
| author | Jenkins <jenkins@review.openstack.org> | 2013-07-23 15:25:26 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2013-07-23 15:25:26 +0000 |
| commit | f175d122473f0bf94abc694a30e3388597b35e26 (patch) | |
| tree | b80f6a1a78c8b81b39b79451be18eef4cec5925b /openstackclient/common | |
| parent | 7b47579dad1faf0b48a9402cf018de49361d6f12 (diff) | |
| parent | 818c94875221f606ed56f276c1cbd320a9106754 (diff) | |
| download | python-openstackclient-f175d122473f0bf94abc694a30e3388597b35e26.tar.gz | |
Merge "Clean up properties (metadata) formatting"
Diffstat (limited to 'openstackclient/common')
| -rw-r--r-- | openstackclient/common/utils.py | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/openstackclient/common/utils.py b/openstackclient/common/utils.py index 06542887..2f2f5718 100644 --- a/openstackclient/common/utils.py +++ b/openstackclient/common/utils.py @@ -1,4 +1,4 @@ -# Copyright 2012-2013 OpenStack, LLC. +# Copyright 2012-2013 OpenStack Foundation # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain @@ -73,6 +73,20 @@ def find_resource(manager, name_or_id): raise +def format_dict(data): + """Return a formatted string of key value pairs + + :param data: a dict + :param format: optional formatting hints + :rtype: a string formatted to key='value' + """ + + output = "" + for s in data: + output = output + s + "='" + data[s] + "', " + return output[:-2] + + def get_item_properties(item, fields, mixed_case_fields=[], formatters={}): """Return a tuple containing the item properties. @@ -85,14 +99,14 @@ def get_item_properties(item, fields, mixed_case_fields=[], formatters={}): row = [] for field in fields: + if field in mixed_case_fields: + field_name = field.replace(' ', '_') + else: + field_name = field.lower().replace(' ', '_') + data = getattr(item, field_name, '') if field in formatters: - row.append(formatters[field](item)) + row.append(formatters[field](data)) else: - if field in mixed_case_fields: - field_name = field.replace(' ', '_') - else: - field_name = field.lower().replace(' ', '_') - data = getattr(item, field_name, '') row.append(data) return tuple(row) |
