Repository :
http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master
---------------------------------------------------------------
commit 796b949e8ef39b7e5605f6436c97178866030fdd
Author: Peter Hatina <phatina(a)redhat.com>
Date: Tue Aug 6 10:07:29 2013 +0200
drop display hook
---------------------------------------------------------------
cli/lmi/shell/LMIConnection.py | 20 ++-----------
cli/lmi/shell/LMIConsole.py | 34 ----------------------
cli/lmi/shell/LMIInstance.py | 59 ++++++++-------------------------------
cli/lmi/shell/LMIMethod.py | 53 +++++-----------------------------
cli/lmi/shell/LMIReturnValue.py | 30 +-------------------
cli/lmi/shell/LMIShellClient.py | 12 ++------
6 files changed, 27 insertions(+), 181 deletions(-)
diff --git a/cli/lmi/shell/LMIConnection.py b/cli/lmi/shell/LMIConnection.py
index 43666d0..dec3f6c 100644
--- a/cli/lmi/shell/LMIConnection.py
+++ b/cli/lmi/shell/LMIConnection.py
@@ -231,12 +231,7 @@ class LMIConnection(object):
Destination -- string representing destination uri, where the indications
should
be delivered
"""
- _return_value = lambda rval, errorstr="": LMIReturnValue(
- rval=rval,
- errorstr=errorstr,
- use_display_hook=True,
- hostname=self._client.hostname
- )
+ _return_value = lambda rval, errorstr="": LMIReturnValue(rval=rval,
errorstr=errorstr)
try:
cim_filter_provided = "Filter" in kwargs
if cim_filter_provided:
@@ -324,19 +319,10 @@ class LMIConnection(object):
if not name in self._indications:
errorstr = "No such indication"
lmi_raise_or_dump_exception(LMIIndicationError(errorstr))
- return LMIReturnValue(
- rval=False,
- errorstr=errorstr,
- use_display_hook=True,
- hostname=self._client.hostname
- )
+ return LMIReturnValue(rval=False, errorstr=errorstr)
indication = self._indications.pop(name)
indication.delete()
- return LMIReturnValue(
- rval=True,
- use_display_hook=True,
- hostname=self._client.hostname
- )
+ return LMIReturnValue(rval=True)
def __unsubscribe_all_indications(self):
"""
diff --git a/cli/lmi/shell/LMIConsole.py b/cli/lmi/shell/LMIConsole.py
index 37058da..f81099f 100644
--- a/cli/lmi/shell/LMIConsole.py
+++ b/cli/lmi/shell/LMIConsole.py
@@ -38,39 +38,6 @@ from LMIConnection import connect as connect_internal
from LMIUtil import lmi_set_use_exceptions
from LMIUtil import lmi_get_use_exceptions
-def _lmi_displayhook(o):
- """
- LMIShell display hook, which is used, when run in the interactive mode. Prints out a
- pretty message, when a LMIReturnValue is returned from a function, method call, etc.
- It is important, that the LMIReturnValue object needs to have a property
- "use_display_hook" set.
- """
- if o is None:
- return
- __builtin__._ = None
- if isinstance(o, LMIReturnValue) and o.use_display_hook:
- o.use_display_hook = False
- if (isinstance(o.rval, int) and o.rval in (0, 4096)) or (isinstance(o.rval, bool)
and o.rval == True):
- result_str = "ok"
- else:
- result_str = "fail"
- sys.stdout.write("%s: %s (%s)" % (o.hostname, result_str,
str(o.rval)))
- if o.errorstr:
- sys.stdout.write(": %s" % o.errorstr)
- sys.stdout.write("\n")
- else:
- print o
- __builtin__._ = o
-
-sys.displayhook = _lmi_displayhook
-
-def _use_display_sugar(use=True):
- """
- Helper function, which controls, if to use display "sugar". That means, if
to use LMI
- display hook for LMIReturnValue.
- """
- sys.displayhook = _lmi_displayhook if use else sys.__displayhook__
-
class LMIConsole(code.InteractiveConsole):
"""
Class representing an interactive console.
@@ -152,7 +119,6 @@ class LMIConsole(code.InteractiveConsole):
if isinstance(v, LMIConnection):
locals[k]._client.interactive = True
locals["clear_history"] = self.clear_history
- locals["use_display_sugar"] = _use_display_sugar
locals["connect"] = connect
self.locals = dict(self.locals.items() + locals.items())
self.setup_completer()
diff --git a/cli/lmi/shell/LMIInstance.py b/cli/lmi/shell/LMIInstance.py
index 364f129..e52d0b4 100644
--- a/cli/lmi/shell/LMIInstance.py
+++ b/cli/lmi/shell/LMIInstance.py
@@ -515,20 +515,11 @@ class LMIInstance(LMIBaseObject):
self._lmi_class.print_methods()
@lmi_possibly_deleted( \
- lambda obj: LMIReturnValue( \
- rval=False, \
- errorstr="This instance has been deleted from a CIM broker", \
- use_display_hook=True, \
- hostname=obj._client.hostname), \
- Self=True \
+ LMIReturnValue(rval=False, errorstr="This instance has been deleted from a
CIM broker"), \
)
- @lmi_return_expr_if_fail(lambda obj: obj._cim_instance,
- lambda obj: LMIReturnValue( \
- rval=False, \
- errorstr="Can not refresh the instance", \
- use_display_hook=True, \
- hostname=obj._client.hostname), \
- Self=True \
+ @lmi_return_val_if_fail( \
+ lambda obj: obj._cim_instance,
+ LMIReturnValue(rval=False, errorstr="Can not refresh the instance"), \
)
def refresh(self):
"""
@@ -541,36 +532,16 @@ class LMIInstance(LMIBaseObject):
"""
(new_cim_instance, _, errorstr) = self._client._get_instance(self.path,
LocalOnly=False)
if not new_cim_instance:
- return LMIReturnValue(
- rval=False,
- errorstr=errorstr,
- use_display_hook=True,
- hostname=self._client.hostname
- )
+ return LMIReturnValue(rval=False, errorstr=errorstr)
self._cim_instance = new_cim_instance
- return LMIReturnValue(
- rval=True,
- use_display_hook=True,
- hostname=self._client.hostname
- )
+ return LMIReturnValue(rval=True)
@lmi_possibly_deleted( \
- lambda obj: LMIReturnValue( \
- rval=False, \
- errorstr="This instance has been deleted from a CIM broker",
- use_display_hook=True, \
- hostname=obj._client.hostname
- ), \
- Self=True \
- )
- @lmi_return_expr_if_fail(lambda obj: obj._cim_instance.path, \
- lambda obj: LMIReturnValue( \
- rval=False, \
- errorstr="Can't push this instance", \
- use_display_hook=True, \
- hostname=obj._client.hostname \
- ), \
- Self=True \
+ LMIReturnValue(rval=False, errorstr="This instance has been deleted from a
CIM broker") \
+ )
+ @lmi_return_val_if_fail( \
+ lambda obj: obj._cim_instance.path, \
+ LMIReturnValue(rval=False, errorstr="Can't push this instance"), \
)
def push(self):
"""
@@ -582,13 +553,7 @@ class LMIInstance(LMIBaseObject):
its code and will return LMIReturnValue containing None as a return value.
"""
(rval, rparams, errorstr) = self._client._modify_instance(self._cim_instance)
- return LMIReturnValue(
- rval=rval,
- rparams=rparams,
- errorstr=errorstr,
- use_display_hook=True,
- hostname=self._client.hostname
- )
+ return LMIReturnValue(rval=rval, rparams=rparams, errorstr=errorstr)
@lmi_possibly_deleted(None)
@lmi_return_if_fail(lambda obj: obj._cim_instance.path)
diff --git a/cli/lmi/shell/LMIMethod.py b/cli/lmi/shell/LMIMethod.py
index 7760706..3a05740 100644
--- a/cli/lmi/shell/LMIMethod.py
+++ b/cli/lmi/shell/LMIMethod.py
@@ -132,11 +132,7 @@ class LMIMethod(LMIBaseObject):
if not error_inst:
raise LMISynchroMethodCallError("Could not get Job error
message")
errorstr = error_inst.Message
- return LMIReturnValue(
- rval=rval,
- rparams=rparams,
- errorstr=errorstr
- )
+ return LMIReturnValue(rval=rval, rparams=rparams, errorstr=errorstr)
def __handle_synchro_method_call_indication(self, job_inst):
"""
@@ -362,12 +358,7 @@ class LMIMethod(LMIBaseObject):
# NOTE: maybe we could check for pywbem type and not to exit prematurely
errorstr = "Unknown parameter '%s' supplied for method
'%s'" % (param, self._method.name)
lmi_raise_or_dump_exception(LMIUnknownParameterError(errorstr))
- return LMIReturnValue(
- rval=-1,
- errorstr=errorstr,
- hostname=self._client.hostname,
- use_display_hook=True
- )
+ return LMIReturnValue(rval=-1, errorstr=errorstr)
(rval, call_rparams, call_errorstr) =
self._client._call_method_raw(self._lmi_instance,
self._method.name, **kwargs)
rval = lmi_transform_to_lmi(self._client, rval)
@@ -377,12 +368,7 @@ class LMIMethod(LMIBaseObject):
# NOTE: this is wrong! What should we do?
errorstr = "Could not perform CIM -> LMI object
transformation"
lmi_raise_or_dump_exception(LMIMethodCallError(errorstr))
- return LMIReturnValue(
- rval=rval,
- errorstr=errorstr,
- hostname=self._client.hostname,
- use_display_hook=True
- )
+ return LMIReturnValue(rval=rval, errorstr=errorstr)
# Check if we can perform synchronous method call
job = call_rparams["job"] if "job" in call_rparams else
None
can_perform_sync_call = job.classname in LMIMethod._INDICATION_JOB_CLASSNAMES
if job else False
@@ -397,20 +383,10 @@ class LMIMethod(LMIBaseObject):
handled_by_indication = True
except pywbem.CIMError, e:
lmi_raise_or_dump_exception(e)
- return LMIReturnValue(
- rval=-1,
- errorstr=e.args[1],
- use_display_hook=True,
- hostname=self._client.hostname
- )
+ return LMIReturnValue(rval=-1, errorstr=e.args[1])
except LMISynchroMethodCallError, e:
lmi_raise_or_dump_exception(e)
- return LMIReturnValue(
- rval=-1,
- errorstr=e.message,
- use_display_hook=True,
- hostname=self._client.hostname
- )
+ return LMIReturnValue(rval=-1, errorstr=e.message)
# Fall through, try to handle the synchro call by polling
except LMIHandlerNamePatternError, e:
handled_by_indication = False
@@ -424,27 +400,14 @@ class LMIMethod(LMIBaseObject):
(rval, call_rparams, call_errorstr) =
self.__handle_synchro_method_call_polling(job_inst)
except LMISynchroMethodCallError, e:
lmi_raise_or_dump_exception(e)
- return LMIReturnValue(
- rval=-1,
- errorstr=e.message,
- hostname=self._client.hostname,
- use_display_hook=True
- )
+ return LMIReturnValue(rval=-1, errorstr=e.message)
call_rparams = lmi_transform_to_lmi(self._client, call_rparams)
if not self._lmi_instance.refresh():
# NOTE: this is wrong! What should we do?
errorstr = "Could not update an LMI object after a method call"
lmi_raise_or_dump_exception(LMIMethodCallError(errorstr))
- return LMIReturnValue(
- rval=rval,
- errorstr=errorstr
- )
- return LMIReturnValue(
- hostname=self._client.hostname,
- use_display_hook=True,
- rval=rval,
- rparams=call_rparams,
- errorstr=call_errorstr)
+ return LMIReturnValue(rval=rval, errorstr=errorstr)
+ return LMIReturnValue(rval=rval, rparams=call_rparams, errorstr=call_errorstr)
def __getattr__(self, name):
"""
diff --git a/cli/lmi/shell/LMIReturnValue.py b/cli/lmi/shell/LMIReturnValue.py
index 5ca650c..9b69e3b 100644
--- a/cli/lmi/shell/LMIReturnValue.py
+++ b/cli/lmi/shell/LMIReturnValue.py
@@ -43,29 +43,6 @@ class LMIReturnValue(_RValue):
"""
return self._properties.keys()
- @property
- def use_display_hook(self):
- """
- Property returning a bool flag, if the LMIReturnValue can be used in the
- interactive mode's output hook.
- """
- return self._properties["use_display_hook"]
-
- @use_display_hook.setter
- def use_display_hook(self, value):
- """
- Property setter for display hook.
- """
- self._properties["use_display_hook"] = value
-
- @property
- def hostname(self):
- """
- Property returning a string of the hostname. Used in the interactive mode's
output
- hook.
- """
- return self._properties["hostname"]
-
def __new__(self, **kwargs):
"""
Creates a new instance of LMIReturnValue. At least rval keyword argument must be
@@ -76,17 +53,12 @@ class LMIReturnValue(_RValue):
rval -- return value
rparams -- return parameters
errorstr -- error string
- hostname -- ; default value is "This machine"
- use_display_hook -- ; default value is False
Any other keyword argument will be also stored and is accessible via getattr.
"""
if not "rval" in kwargs:
raise LMIReturnValueError("rval argument missing while instancing
LMIReturnValue object")
- properties = {
- "hostname" : "This Machine",
- "use_display_hook" : False
- }
+ properties = {}
keys_to_pop = []
for (key, value) in kwargs.iteritems():
if key in ("rval", "rparams", "errorstr"):
diff --git a/cli/lmi/shell/LMIShellClient.py b/cli/lmi/shell/LMIShellClient.py
index 6ef012f..ca9a927 100644
--- a/cli/lmi/shell/LMIShellClient.py
+++ b/cli/lmi/shell/LMIShellClient.py
@@ -77,12 +77,9 @@ class LMIShellClient(LMIBaseClient):
if class_list is None:
(class_list, _, errorstr) = LMIBaseClient._get_class_names(self,
namespace, **kwargs)
if not class_list:
- return LMIReturnValue(
- rval=class_list,
- errorstr=errorstr
- )
+ return LMIReturnValue(rval=class_list, errorstr=errorstr)
self._cache.set_classes(class_list)
- return LMIReturnValue(rval = class_list)
+ return LMIReturnValue(rval=class_list)
return LMIBaseClient._get_class_names(self, namespace, **kwargs)
def _get_class(self, class_name, namespace=None, **kwargs):
@@ -121,10 +118,7 @@ class LMIShellClient(LMIBaseClient):
if klass is None:
(klass, _, errorstr) = LMIBaseClient._get_class(self, class_name,
namespace, **kwargs)
if not klass:
- return LMIReturnValue(
- rval=klass,
- errorstr=errorstr
- )
+ return LMIReturnValue(rval=klass, errorstr=errorstr)
self._cache.add_class(klass)
return LMIReturnValue(rval=klass)
return LMIBaseClient._get_class(self, class_name, namespace, **kwargs)