Fix print_list label name in troveclient/utils.py

The output of list make nice labels from fields. Fisrt, replace
underscore with space. Then, replace "id" with "ID". Finally,
capitalize each word. This works fine for "*_id"(for exmaple,
"flavor_id" will be replaced to "Flavor ID"), but when a word
has a "id" inside, it will be wrong. For example, "cidr"
will be replaced to "CIDr", actually it should be "Cidr".

This change fix the problem, only "id" after a underscore will be
replaced to "ID".

Change-Id: I8e357c946b21dc6f6c6c79d78a45f23b440a57da
This commit is contained in:
zhanggang
2017-12-12 03:27:08 -05:00
parent 455e334a47
commit aa81cd281d

View File

@@ -157,7 +157,7 @@ def print_list(objs, fields, formatters={}, order_by=None, obj_is_dict=False,
for field in fields:
if field not in labels:
# No underscores (use spaces instead) and uppercase any ID's
label = field.replace("_", " ").replace("id", "ID")
label = field.replace("_", " ").replace(" id", " ID")
# Uppercase anything else that's less than 3 chars
if len(label) < 3:
label = label.upper()