On June 18, 2013, noon, Stephen Gallagher wrote:
In my opinion, it would be preferable to implement get_property_value() method for standard objects. The "pythonic" way of handling this is just as it currently is: object.property contains the value. Returning the dictionary would be a bad idea, as for complex objects this may result in a huge waste of memory for the common case. If you want a handy dictionary like that, I'd recommend making it a separate function from object.properties() like object.properties_dict() with a note in the pydoc that it may result in significant memory overhead.
To sum up: I suggest adding: .get_property_val(property_name) that can internally use getattr() to retrieve the value, hiding it from the public interface
Optionally, if it is useful in some situations, we can add .properties_dict() which will return a full dictionary of all properties, at the expense of memory.
If you implement both of these, please do *not* implement get_property_val() using properties_dict(), as this would be inefficient.
This sounds reasonable.
- Peter
----------------------------------------------------------- This is an automatically generated e-mail. To reply, visit: http://reviewboard-openlmi.rhcloud.com/r/461/#review552 -----------------------------------------------------------
On June 18, 2013, 1:10 p.m., Peter Hatina wrote:
This is an automatically generated e-mail. To reply, visit: http://reviewboard-openlmi.rhcloud.com/r/461/
(Updated June 18, 2013, 1:10 p.m.)
Review request for OpenLMI Developers.
Repository: openlmi-tools
Description
Honza S.:
In a lmishell script I want to manually loop over all properties and get their values. I can use _LmiInstance.properties() to get list of properties, but there is no way, how to get property values. Either _LmiInstance.properties() should return a dictionary or there should be _LmiInstance.get_property(name) method.
Sample code:
i = c.root.cimv2.LMI_StorageExtent.first_instance() for p in i.properties: print p, i.get_property(p)
There is a way, how to get properties:
i = c.root.cimv2.LMI_StorageExtent.first_instance() for p in i.properties: print p, getattr(i, p) ^^
Or how to get Names property value: i.Names
Dunno, if it is a correct (python) way. Maybe it should be switched to a "dictionary style". I used this attitude just because of methods access.
Diffs
cli-tools/lmi/lmi_client_shell.py 54bd8b263002c5df9f3d7dad414e75cae9bc3c41
Diff: http://reviewboard-openlmi.rhcloud.com/r/461/diff/
Testing
Thanks,
Peter Hatina