Michael Pasternak has uploaded a new change for review.

Change subject: cli: datetime.datetime object has no attribute __dict__ #957519
......................................................................

cli: datetime.datetime object has no attribute __dict__ #957519

Change-Id: Ie26fd8e83a87dc1e4d2db2628603e27d3e3fb835
Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=957519
Signed-off-by: Michael pasternak <mpast...@redhat.com>
---
M src/ovirtcli/format/text.py
1 file changed, 15 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine-cli refs/changes/22/14322/1

diff --git a/src/ovirtcli/format/text.py b/src/ovirtcli/format/text.py
index 8fd847e..f3e1f33 100644
--- a/src/ovirtcli/format/text.py
+++ b/src/ovirtcli/format/text.py
@@ -46,6 +46,11 @@
 
     name = 'text'
 
+    # list of complex types that should be treated as
+    # primitives (e.g should be wrapped to string at runtime)
+    complex_type_exceptions = [params.datetime]
+
+
     def _get_fields(self, typ):
         assert typ is not None
         return typ.__dict__.keys()
@@ -89,7 +94,11 @@
                         new_field = field if resource_context is None else 
resource_context.lower() + '.' + field
                         width0 = max(width0, len(new_field))
                 else:
-                    if hasattr(params, type(value).__name__) or 
hasattr(brokers, type(value).__name__):
+                    value_type = type(value)
+                    if (hasattr(params, value_type.__name__) \
+                        and value_type not in 
TextFormatter.complex_type_exceptions) \
+                        or hasattr(brokers, value_type.__name__):
+
                         if resource_context is not None:
                             width0 = max(width0, 
self.__get_max_field_width(resource=value,
                                                                             
fields_exceptions=fields_exceptions,
@@ -165,7 +174,11 @@
 
         for field in fields:
             if field not in fields_exceptions:
-                value = resource.__dict__[field]
+
+                value = getattr(resource, field)
+                if type(value) in TextFormatter.complex_type_exceptions:
+                    value = str(value)
+
                 if isinstance(value, list):
                     value_list = value
                     for item in value_list:


--
To view, visit http://gerrit.ovirt.org/14322
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie26fd8e83a87dc1e4d2db2628603e27d3e3fb835
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine-cli
Gerrit-Branch: master
Gerrit-Owner: Michael Pasternak <mpast...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to