Addressing Dan's comment on output generator

This commit is contained in:
Salvatore Orlando 2011-09-09 21:20:47 +01:00
parent 6bae7683b8
commit 1028fb81e4

View File

@ -74,7 +74,7 @@ class OutputTemplate(object):
items = item.split('.') items = item.split('.')
if len(items) == 1: if len(items) == 1:
return self.data[item] return self.data[item]
else: elif len(items) == 2:
return self.data[items[0]][items[1]] return self.data[items[0]][items[1]]
def _make_list(self, items, inner_template): def _make_list(self, items, inner_template):
@ -83,7 +83,7 @@ class OutputTemplate(object):
""" """
#make sure list is subscriptable #make sure list is subscriptable
if not hasattr(items, '__getitem__'): if not hasattr(items, '__getitem__'):
return inner_template % items raise Exception("Element is not iterable")
return "\n".join([inner_template % item for item in items]) return "\n".join([inner_template % item for item in items])
@ -131,8 +131,7 @@ class CmdOutputTemplate(OutputTemplate):
"unplug_iface": "Unplugged interface from Logical Port:" + "unplug_iface": "Unplugged interface from Logical Port:" +
"%(port_id)s\n" + "%(port_id)s\n" +
"on Virtual Network: %(network_id)s\n" + "on Virtual Network: %(network_id)s\n" +
"for Tenant: %(tenant_id)s" "for Tenant: %(tenant_id)s"}
}
def __init__(self, cmd, data): def __init__(self, cmd, data):
super(CmdOutputTemplate, self).__init__(self._templates[cmd], data) super(CmdOutputTemplate, self).__init__(self._templates[cmd], data)