[cura-tools] 0.9-fixes: introduce LMIClass.instances(client_filtering) (87e6ffd)
by phatina@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/cura-tools.git
On branch : 0.9-fixes
>---------------------------------------------------------------
commit 87e6ffd690e111ad669121768c97ae49d331a727
Author: Peter Hatina <phatina(a)redhat.com>
Date: Thu Feb 20 13:54:35 2014 +0100
introduce LMIClass.instances(client_filtering)
LMIInstance filtering will be performed by LMIShell instead of CIMOM.
>---------------------------------------------------------------
cli/lmi/shell/LMIBaseClient.py | 67 +++++++++++++++++++++++++++++++---------
1 files changed, 52 insertions(+), 15 deletions(-)
diff --git a/cli/lmi/shell/LMIBaseClient.py b/cli/lmi/shell/LMIBaseClient.py
index 6a0f677..2fc3f53 100644
--- a/cli/lmi/shell/LMIBaseClient.py
+++ b/cli/lmi/shell/LMIBaseClient.py
@@ -178,7 +178,8 @@ class LMIBaseClient(object):
# NOTE: usage with Key=something, Value=something is deprecated
# NOTE: inst_filter is either None or dict
- def _get_instances(self, class_name, namespace=None, inst_filter=None, **kwargs):
+ def _get_instances(self, class_name, namespace=None, inst_filter=None,
+ client_filtering=False, **kwargs):
"""
Returns a list of :py:class:`CIMInstance` objects.
@@ -187,6 +188,8 @@ class LMIBaseClient(object):
:param dictionary inst_filter: dictionary containing filter values. The key
corresponds to the primary key of the :py:class:`CIMInstanceName`;
value contains the filtering value.
+ :param bool client_filtering: if True, client-side filtering will be performed,
+ otherwise the filtering will be done by a CIMOM. Default value is False.
:param dictionary kwargs: supported keyword arguments (these are **deprecated**)
* **Key** or **key** (*string*) -- filtering key, see above
@@ -216,20 +219,54 @@ class LMIBaseClient(object):
kwargs.pop("Value")
if filter_value:
inst_filter[filter_key] = filter_value
- query = "select * from %s" % class_name
- if inst_filter:
- more = False
- query += " where"
- for (filter_key, filter_value) in inst_filter.iteritems():
- if more:
- query += " and"
- quotes = isinstance(filter_value, basestring)
- query += " %s =" % filter_key
- query += " \"%s\"" % filter_value if quotes else " %s" % filter_value
- more = True
- (inst_list, _, errorstr) = self._exec_query(LMIBaseClient.QUERY_LANG_WQL, query, namespace)
- if not inst_list:
- return LMIReturnValue(rval=None, errorstr=errorstr)
+
+ if not client_filtering:
+ query = "select * from %s" % class_name
+ if inst_filter:
+ more = False
+ query += " where"
+ for (filter_key, filter_value) in inst_filter.iteritems():
+ if more:
+ query += " and"
+ quotes = isinstance(filter_value, basestring)
+ query += " %s =" % filter_key
+ query += " \"%s\"" % filter_value if quotes else " %s" % filter_value
+ more = True
+ (inst_list, _, errorstr) = self._exec_query(
+ LMIBaseClient.QUERY_LANG_WQL,
+ query,
+ namespace)
+ if inst_list is None:
+ return LMIReturnValue(rval=None, errorstr=errorstr)
+ return LMIReturnValue(rval=inst_list)
+
+ # Client-side filtering - this is not a pretty solution, but it needs
+ # to be present due to TOG-Pegasus, which does not raise an exception,
+ # if an error occurs while performing CQL/WQL query.
+ inst_list = None
+ try:
+ inst_list = self._cliconn.EnumerateInstances(
+ class_name,
+ LocalOnly=False,
+ DeepInheritance=True,
+ IncludeQualifiers=False)
+ except pywbem.cim_operations.CIMError, e:
+ lmi_raise_or_dump_exception(e)
+ return LMIReturnValue(rval=None, errorstr=e.args[1])
+ except pywbem.cim_http.AuthError, e:
+ lmi_raise_or_dump_exception(e)
+ return LMIReturnValue(rval=None, errorstr=e.args[0])
+
+ if inst_list and inst_filter:
+ inst_list_filtered = []
+ for inst in inst_list:
+ for (filter_key, filter_value) in inst_filter.iteritems():
+ if not filter_key in inst.properties or \
+ inst.properties[filter_key].value != filter_value:
+ break
+ else:
+ inst_list_filtered.append(inst)
+ inst_list = inst_list_filtered
return LMIReturnValue(rval=inst_list)
def _get_class_names(self, namespace=None, **kwargs):
10 years, 2 months
[cura-tools] master: introduce LMIClass.instances(client_filtering) (2f0d8e5)
by phatina@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master
>---------------------------------------------------------------
commit 2f0d8e5adbd26c50f9c1080b50d5e4c56601fe9d
Author: Peter Hatina <phatina(a)redhat.com>
Date: Thu Feb 20 13:54:35 2014 +0100
introduce LMIClass.instances(client_filtering)
LMIInstance filtering will be performed by LMIShell instead of CIMOM.
>---------------------------------------------------------------
cli/lmi/shell/LMIBaseClient.py | 67 +++++++++++++++++++++++++++++++---------
1 files changed, 52 insertions(+), 15 deletions(-)
diff --git a/cli/lmi/shell/LMIBaseClient.py b/cli/lmi/shell/LMIBaseClient.py
index 7ca9b5d..ac93768 100644
--- a/cli/lmi/shell/LMIBaseClient.py
+++ b/cli/lmi/shell/LMIBaseClient.py
@@ -186,7 +186,8 @@ class LMIBaseClient(object):
# NOTE: usage with Key=something, Value=something is deprecated
# NOTE: inst_filter is either None or dict
- def _get_instances(self, class_name, namespace=None, inst_filter=None, **kwargs):
+ def _get_instances(self, class_name, namespace=None, inst_filter=None,
+ client_filtering=False, **kwargs):
"""
Returns a list of :py:class:`CIMInstance` objects.
@@ -195,6 +196,8 @@ class LMIBaseClient(object):
:param dictionary inst_filter: dictionary containing filter values. The key
corresponds to the primary key of the :py:class:`CIMInstanceName`;
value contains the filtering value.
+ :param bool client_filtering: if True, client-side filtering will be performed,
+ otherwise the filtering will be done by a CIMOM. Default value is False.
:param dictionary kwargs: supported keyword arguments (these are **deprecated**)
* **Key** or **key** (*string*) -- filtering key, see above
@@ -224,20 +227,54 @@ class LMIBaseClient(object):
kwargs.pop("Value")
if filter_value:
inst_filter[filter_key] = filter_value
- query = "select * from %s" % class_name
- if inst_filter:
- more = False
- query += " where"
- for (filter_key, filter_value) in inst_filter.iteritems():
- if more:
- query += " and"
- quotes = isinstance(filter_value, basestring)
- query += " %s =" % filter_key
- query += " \"%s\"" % filter_value if quotes else " %s" % filter_value
- more = True
- (inst_list, _, errorstr) = self._exec_query(LMIBaseClient.QUERY_LANG_WQL, query, namespace)
- if not inst_list:
- return LMIReturnValue(rval=None, errorstr=errorstr)
+
+ if not client_filtering:
+ query = "select * from %s" % class_name
+ if inst_filter:
+ more = False
+ query += " where"
+ for (filter_key, filter_value) in inst_filter.iteritems():
+ if more:
+ query += " and"
+ quotes = isinstance(filter_value, basestring)
+ query += " %s =" % filter_key
+ query += " \"%s\"" % filter_value if quotes else " %s" % filter_value
+ more = True
+ (inst_list, _, errorstr) = self._exec_query(
+ LMIBaseClient.QUERY_LANG_WQL,
+ query,
+ namespace)
+ if inst_list is None:
+ return LMIReturnValue(rval=None, errorstr=errorstr)
+ return LMIReturnValue(rval=inst_list)
+
+ # Client-side filtering - this is not a pretty solution, but it needs
+ # to be present due to TOG-Pegasus, which does not raise an exception,
+ # if an error occurs while performing CQL/WQL query.
+ inst_list = None
+ try:
+ inst_list = self._cliconn.EnumerateInstances(
+ class_name,
+ LocalOnly=False,
+ DeepInheritance=True,
+ IncludeQualifiers=False)
+ except pywbem.cim_operations.CIMError, e:
+ lmi_raise_or_dump_exception(e)
+ return LMIReturnValue(rval=None, errorstr=e.args[1])
+ except pywbem.cim_http.AuthError, e:
+ lmi_raise_or_dump_exception(e)
+ return LMIReturnValue(rval=None, errorstr=e.args[0])
+
+ if inst_list and inst_filter:
+ inst_list_filtered = []
+ for inst in inst_list:
+ for (filter_key, filter_value) in inst_filter.iteritems():
+ if not filter_key in inst.properties or \
+ inst.properties[filter_key].value != filter_value:
+ break
+ else:
+ inst_list_filtered.append(inst)
+ inst_list = inst_list_filtered
return LMIReturnValue(rval=inst_list)
def _get_class_names(self, namespace=None, **kwargs):
10 years, 2 months
[cura-tools] master: fix missing cast in LMIMethod::__call__() (c69dbfe)
by phatina@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master
>---------------------------------------------------------------
commit c69dbfe8877ce66e679fcfdd2eee439c97def1ed
Author: Peter Hatina <phatina(a)redhat.com>
Date: Mon Feb 17 14:56:13 2014 +0100
fix missing cast in LMIMethod::__call__()
>---------------------------------------------------------------
cli/lmi/shell/LMIUtil.py | 4 +---
1 files changed, 1 insertions(+), 3 deletions(-)
diff --git a/cli/lmi/shell/LMIUtil.py b/cli/lmi/shell/LMIUtil.py
index 2eb5575..493cf77 100644
--- a/cli/lmi/shell/LMIUtil.py
+++ b/cli/lmi/shell/LMIUtil.py
@@ -289,8 +289,6 @@ def lmi_transform_to_cim_param(t, value):
return value.wrapped_object.path
elif isinstance(value, LMIObjectFactory().LMIInstanceName):
return value.wrapped_object
- elif isinstance(value, (int, float)):
- return lmi_cast_to_cim(t, value)
elif isinstance(value, (dict, pywbem.NocaseDict)):
return pywbem.NocaseDict({
k: lmi_transform_to_cim_param(t, val)
@@ -299,7 +297,7 @@ def lmi_transform_to_cim_param(t, value):
return map(lambda val: lmi_transform_to_cim_param(t, val), value)
elif isinstance(value, tuple):
return tuple(map(lambda val: lmi_transform_to_cim_param(t, val), value))
- return value
+ return lmi_cast_to_cim(t, value)
def lmi_isinstance(lmi_obj, lmi_class):
"""
10 years, 2 months
[cura-tools] master: make synchro-calls available to all methods, which return a job (d0a8482)
by phatina@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master
>---------------------------------------------------------------
commit d0a8482ba935c510e9e51e6e97bf82cfd04aaa91
Author: Peter Hatina <phatina(a)redhat.com>
Date: Fri Feb 14 10:07:15 2014 +0100
make synchro-calls available to all methods, which return a job
>---------------------------------------------------------------
cli/lmi/shell/LMIClass.py | 11 ++++++++---
1 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/cli/lmi/shell/LMIClass.py b/cli/lmi/shell/LMIClass.py
index f156cf6..f8a0a69 100644
--- a/cli/lmi/shell/LMIClass.py
+++ b/cli/lmi/shell/LMIClass.py
@@ -315,9 +315,14 @@ class LMIClass(LMIWrapperBaseObject):
"""
(class_names, _, _) = self._conn._client._get_class_names(self.namespace)
methods_lst = self._cim_class.methods.keys()
- for method in self._cim_class.methods.keys():
- if "__MethodParameters_" + method in class_names:
- methods_lst.append("Sync" + method)
+ # Iterate through a list of all CIM methods and append any method which
+ # can be called in the synchronous way. One type of such method is the
+ # method, which has its "counterpart" class __MethodParameters_<Method>.
+ # The other one is the method, which defines a Job return paremeter.
+ for (name, method) in self._cim_class.methods.iteritems():
+ if "__MethodParameters_" + name in class_names or \
+ "Job" in method.parameters:
+ methods_lst.append("Sync" + name)
return methods_lst
10 years, 2 months
[cura-tools] master: update copyright years (f6da730)
by phatina@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master
>---------------------------------------------------------------
commit f6da730d943300f616837a2272db0c780c977c5c
Author: Peter Hatina <phatina(a)redhat.com>
Date: Wed Feb 12 15:34:43 2014 +0100
update copyright years
>---------------------------------------------------------------
cli/completion/_lmishell | 2 +-
cli/completion/lmi.bash | 2 +-
cli/completion/lmishell.bash | 2 +-
cli/lmi/__init__.py | 2 +-
cli/lmi/shell/LMIBaseClient.py | 2 +-
cli/lmi/shell/LMIBaseObject.py | 2 +-
cli/lmi/shell/LMIClass.py | 2 +-
cli/lmi/shell/LMICompleter.py | 2 +-
cli/lmi/shell/LMIConnection.py | 2 +-
cli/lmi/shell/LMIConsole.py | 2 +-
cli/lmi/shell/LMIConstantValues.py | 2 +-
cli/lmi/shell/LMIDecorators.py | 2 +-
cli/lmi/shell/LMIExceptions.py | 2 +-
cli/lmi/shell/LMIFormatter.py | 2 +-
cli/lmi/shell/LMIHelper.py | 2 +-
cli/lmi/shell/LMIIndication.py | 2 +-
cli/lmi/shell/LMIIndicationListener.py | 2 +-
cli/lmi/shell/LMIInstance.py | 2 +-
cli/lmi/shell/LMIInstanceName.py | 2 +-
cli/lmi/shell/LMIJob.py | 2 +-
cli/lmi/shell/LMIMethod.py | 2 +-
cli/lmi/shell/LMINamespace.py | 2 +-
cli/lmi/shell/LMIObjectFactory.py | 2 +-
cli/lmi/shell/LMIReturnValue.py | 2 +-
cli/lmi/shell/LMIShellCache.py | 2 +-
cli/lmi/shell/LMIShellClient.py | 2 +-
cli/lmi/shell/LMIShellConfig.py | 2 +-
cli/lmi/shell/LMIShellOptions.py | 2 +-
cli/lmi/shell/LMIShellVersion.py | 3 +--
cli/lmi/shell/LMISubscription.py | 2 +-
cli/lmi/shell/LMIUtil.py | 2 +-
cli/lmi/shell/__init__.py | 2 +-
cli/lmishell | 2 +-
cli/setup.py | 2 +-
34 files changed, 34 insertions(+), 35 deletions(-)
diff --git a/cli/completion/_lmishell b/cli/completion/_lmishell
index d3843b3..28a51e4 100644
--- a/cli/completion/_lmishell
+++ b/cli/completion/_lmishell
@@ -1,6 +1,6 @@
#compdef lmishell
-# Copyright (C) 2013 Red Hat, Inc. All rights reserved.
+# Copyright (C) 2013-2014 Red Hat, Inc. All rights reserved.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
diff --git a/cli/completion/lmi.bash b/cli/completion/lmi.bash
index 0aa174b..c60ab9b 100644
--- a/cli/completion/lmi.bash
+++ b/cli/completion/lmi.bash
@@ -1,5 +1,5 @@
#
-# Copyright (C) 2013 Red Hat, Inc. All rights reserved.
+# Copyright (C) 2013-2014 Red Hat, Inc. All rights reserved.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
diff --git a/cli/completion/lmishell.bash b/cli/completion/lmishell.bash
index 07958f0..9d3ec2a 100644
--- a/cli/completion/lmishell.bash
+++ b/cli/completion/lmishell.bash
@@ -1,5 +1,5 @@
#
-# Copyright (C) 2013 Red Hat, Inc. All rights reserved.
+# Copyright (C) 2013-2014 Red Hat, Inc. All rights reserved.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
diff --git a/cli/lmi/__init__.py b/cli/lmi/__init__.py
index e554343..a02ea71 100644
--- a/cli/lmi/__init__.py
+++ b/cli/lmi/__init__.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
+# Copyright (C) 2012-2014 Peter Hatina <phatina(a)redhat.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
diff --git a/cli/lmi/shell/LMIBaseClient.py b/cli/lmi/shell/LMIBaseClient.py
index a16f9f1..7ca9b5d 100644
--- a/cli/lmi/shell/LMIBaseClient.py
+++ b/cli/lmi/shell/LMIBaseClient.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
+# Copyright (C) 2012-2014 Peter Hatina <phatina(a)redhat.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
diff --git a/cli/lmi/shell/LMIBaseObject.py b/cli/lmi/shell/LMIBaseObject.py
index 1e2df9e..565c89c 100644
--- a/cli/lmi/shell/LMIBaseObject.py
+++ b/cli/lmi/shell/LMIBaseObject.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
+# Copyright (C) 2012-2014 Peter Hatina <phatina(a)redhat.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
diff --git a/cli/lmi/shell/LMIClass.py b/cli/lmi/shell/LMIClass.py
index aa250b1..f156cf6 100644
--- a/cli/lmi/shell/LMIClass.py
+++ b/cli/lmi/shell/LMIClass.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
+# Copyright (C) 2012-2014 Peter Hatina <phatina(a)redhat.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
diff --git a/cli/lmi/shell/LMICompleter.py b/cli/lmi/shell/LMICompleter.py
index 64e0a87..df57388 100644
--- a/cli/lmi/shell/LMICompleter.py
+++ b/cli/lmi/shell/LMICompleter.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
+# Copyright (C) 2012-2014 Peter Hatina <phatina(a)redhat.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
diff --git a/cli/lmi/shell/LMIConnection.py b/cli/lmi/shell/LMIConnection.py
index 5d1040b..b708551 100644
--- a/cli/lmi/shell/LMIConnection.py
+++ b/cli/lmi/shell/LMIConnection.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
+# Copyright (C) 2012-2014 Peter Hatina <phatina(a)redhat.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
diff --git a/cli/lmi/shell/LMIConsole.py b/cli/lmi/shell/LMIConsole.py
index f1c9c4f..cb287a2 100644
--- a/cli/lmi/shell/LMIConsole.py
+++ b/cli/lmi/shell/LMIConsole.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
+# Copyright (C) 2012-2014 Peter Hatina <phatina(a)redhat.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
diff --git a/cli/lmi/shell/LMIConstantValues.py b/cli/lmi/shell/LMIConstantValues.py
index e9927ba..93fe796 100644
--- a/cli/lmi/shell/LMIConstantValues.py
+++ b/cli/lmi/shell/LMIConstantValues.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
+# Copyright (C) 2012-2014 Peter Hatina <phatina(a)redhat.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
diff --git a/cli/lmi/shell/LMIDecorators.py b/cli/lmi/shell/LMIDecorators.py
index e3b2763..eafd387 100644
--- a/cli/lmi/shell/LMIDecorators.py
+++ b/cli/lmi/shell/LMIDecorators.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
+# Copyright (C) 2012-2014 Peter Hatina <phatina(a)redhat.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
diff --git a/cli/lmi/shell/LMIExceptions.py b/cli/lmi/shell/LMIExceptions.py
index a93dc26..2dc0499 100644
--- a/cli/lmi/shell/LMIExceptions.py
+++ b/cli/lmi/shell/LMIExceptions.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
+# Copyright (C) 2012-2014 Peter Hatina <phatina(a)redhat.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
diff --git a/cli/lmi/shell/LMIFormatter.py b/cli/lmi/shell/LMIFormatter.py
index 48babe3..1ed8650 100644
--- a/cli/lmi/shell/LMIFormatter.py
+++ b/cli/lmi/shell/LMIFormatter.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
+# Copyright (C) 2012-2014 Peter Hatina <phatina(a)redhat.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
diff --git a/cli/lmi/shell/LMIHelper.py b/cli/lmi/shell/LMIHelper.py
index b33fffb..1747603 100644
--- a/cli/lmi/shell/LMIHelper.py
+++ b/cli/lmi/shell/LMIHelper.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
+# Copyright (C) 2012-2014 Peter Hatina <phatina(a)redhat.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
diff --git a/cli/lmi/shell/LMIIndication.py b/cli/lmi/shell/LMIIndication.py
index 808d4e8..07da2c3 100644
--- a/cli/lmi/shell/LMIIndication.py
+++ b/cli/lmi/shell/LMIIndication.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
+# Copyright (C) 2012-2014 Peter Hatina <phatina(a)redhat.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
diff --git a/cli/lmi/shell/LMIIndicationListener.py b/cli/lmi/shell/LMIIndicationListener.py
index 5b76f06..cb28c7c 100644
--- a/cli/lmi/shell/LMIIndicationListener.py
+++ b/cli/lmi/shell/LMIIndicationListener.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
+# Copyright (C) 2012-2014 Peter Hatina <phatina(a)redhat.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
diff --git a/cli/lmi/shell/LMIInstance.py b/cli/lmi/shell/LMIInstance.py
index 28c6c36..9597447 100644
--- a/cli/lmi/shell/LMIInstance.py
+++ b/cli/lmi/shell/LMIInstance.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
+# Copyright (C) 2012-2014 Peter Hatina <phatina(a)redhat.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
diff --git a/cli/lmi/shell/LMIInstanceName.py b/cli/lmi/shell/LMIInstanceName.py
index c70a5fd..cdc5cf3 100644
--- a/cli/lmi/shell/LMIInstanceName.py
+++ b/cli/lmi/shell/LMIInstanceName.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
+# Copyright (C) 2012-2014 Peter Hatina <phatina(a)redhat.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
diff --git a/cli/lmi/shell/LMIJob.py b/cli/lmi/shell/LMIJob.py
index db172a1..ef70b17 100644
--- a/cli/lmi/shell/LMIJob.py
+++ b/cli/lmi/shell/LMIJob.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
+# Copyright (C) 2012-2014 Peter Hatina <phatina(a)redhat.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
diff --git a/cli/lmi/shell/LMIMethod.py b/cli/lmi/shell/LMIMethod.py
index 1b8529d..7c32be9 100644
--- a/cli/lmi/shell/LMIMethod.py
+++ b/cli/lmi/shell/LMIMethod.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
+# Copyright (C) 2012-2014 Peter Hatina <phatina(a)redhat.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
diff --git a/cli/lmi/shell/LMINamespace.py b/cli/lmi/shell/LMINamespace.py
index 2f70055..0c53608 100644
--- a/cli/lmi/shell/LMINamespace.py
+++ b/cli/lmi/shell/LMINamespace.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
+# Copyright (C) 2012-2014 Peter Hatina <phatina(a)redhat.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
diff --git a/cli/lmi/shell/LMIObjectFactory.py b/cli/lmi/shell/LMIObjectFactory.py
index e3d355d..d6151a9 100644
--- a/cli/lmi/shell/LMIObjectFactory.py
+++ b/cli/lmi/shell/LMIObjectFactory.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
+# Copyright (C) 2012-2014 Peter Hatina <phatina(a)redhat.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
diff --git a/cli/lmi/shell/LMIReturnValue.py b/cli/lmi/shell/LMIReturnValue.py
index 80afad5..56f0bc7 100644
--- a/cli/lmi/shell/LMIReturnValue.py
+++ b/cli/lmi/shell/LMIReturnValue.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
+# Copyright (C) 2012-2014 Peter Hatina <phatina(a)redhat.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
diff --git a/cli/lmi/shell/LMIShellCache.py b/cli/lmi/shell/LMIShellCache.py
index 68cec67..39da533 100644
--- a/cli/lmi/shell/LMIShellCache.py
+++ b/cli/lmi/shell/LMIShellCache.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
+# Copyright (C) 2012-2014 Peter Hatina <phatina(a)redhat.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
diff --git a/cli/lmi/shell/LMIShellClient.py b/cli/lmi/shell/LMIShellClient.py
index 6c246f0..385e3ac 100644
--- a/cli/lmi/shell/LMIShellClient.py
+++ b/cli/lmi/shell/LMIShellClient.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
+# Copyright (C) 2012-2014 Peter Hatina <phatina(a)redhat.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
diff --git a/cli/lmi/shell/LMIShellConfig.py b/cli/lmi/shell/LMIShellConfig.py
index 05b5638..e134747 100644
--- a/cli/lmi/shell/LMIShellConfig.py
+++ b/cli/lmi/shell/LMIShellConfig.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
+# Copyright (C) 2012-2014 Peter Hatina <phatina(a)redhat.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
diff --git a/cli/lmi/shell/LMIShellOptions.py b/cli/lmi/shell/LMIShellOptions.py
index 8695fec..d7d8377 100644
--- a/cli/lmi/shell/LMIShellOptions.py
+++ b/cli/lmi/shell/LMIShellOptions.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
+# Copyright (C) 2012-2014 Peter Hatina <phatina(a)redhat.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
diff --git a/cli/lmi/shell/LMIShellVersion.py b/cli/lmi/shell/LMIShellVersion.py
index 1c1cb6c..452176c 100644
--- a/cli/lmi/shell/LMIShellVersion.py
+++ b/cli/lmi/shell/LMIShellVersion.py
@@ -1,5 +1,4 @@
-
-# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
+# Copyright (C) 2012-2014 Peter Hatina <phatina(a)redhat.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
diff --git a/cli/lmi/shell/LMISubscription.py b/cli/lmi/shell/LMISubscription.py
index 6fb9e9c..a61dcc2 100644
--- a/cli/lmi/shell/LMISubscription.py
+++ b/cli/lmi/shell/LMISubscription.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
+# Copyright (C) 2012-2014 Peter Hatina <phatina(a)redhat.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
diff --git a/cli/lmi/shell/LMIUtil.py b/cli/lmi/shell/LMIUtil.py
index 15b7448..2eb5575 100644
--- a/cli/lmi/shell/LMIUtil.py
+++ b/cli/lmi/shell/LMIUtil.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
+# Copyright (C) 2012-2014 Peter Hatina <phatina(a)redhat.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
diff --git a/cli/lmi/shell/__init__.py b/cli/lmi/shell/__init__.py
index 378cc24..cbf3479 100644
--- a/cli/lmi/shell/__init__.py
+++ b/cli/lmi/shell/__init__.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
+# Copyright (C) 2012-2014 Peter Hatina <phatina(a)redhat.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
diff --git a/cli/lmishell b/cli/lmishell
index 433d413..7988d53 100755
--- a/cli/lmishell
+++ b/cli/lmishell
@@ -1,5 +1,5 @@
#!/usr/bin/python
-# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
+# Copyright (C) 2012-2014 Peter Hatina <phatina(a)redhat.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
diff --git a/cli/setup.py b/cli/setup.py
index fd6ed8a..4fc2f71 100644
--- a/cli/setup.py
+++ b/cli/setup.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
+# Copyright (C) 2012-2014 Peter Hatina <phatina(a)redhat.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
10 years, 2 months
[cura-tools] master: logging: get the logger with name of a module (71d21c9)
by miminar@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master
>---------------------------------------------------------------
commit 71d21c92700df68c5900b230a62b601b9c367f85
Author: Michal Minar <miminar(a)redhat.com>
Date: Wed Feb 12 12:21:36 2014 +0100
logging: get the logger with name of a module
Allow to configure shell's logging facilities from dependent
applications. Using module's name as a name for a logger is a convetion
greatly simplifying logging's setup.
>---------------------------------------------------------------
cli/lmi/shell/LMIConnection.py | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/cli/lmi/shell/LMIConnection.py b/cli/lmi/shell/LMIConnection.py
index ef83a8a..5d1040b 100644
--- a/cli/lmi/shell/LMIConnection.py
+++ b/cli/lmi/shell/LMIConnection.py
@@ -71,7 +71,7 @@ def __lmi_raw_input(prompt, use_echo=True):
get_input = raw_input
stream = sys.stdout
if not sys.stderr.isatty() and not sys.stdout.isatty():
- logging.getLogger("").warn(
+ logging.getLogger(__name__).warn(
'Both stdout and stderr are detached from terminal, using stdout for prompt')
if not use_echo:
os.system("stty -echo")
@@ -140,7 +140,7 @@ def connect(uri, username="", password="", **kwargs):
if kwargs:
raise TypeError("connect() got an unexpected keyword arguments: %s" % ", ".join(kwargs.keys()))
- logger = logging.getLogger("")
+ logger = logging.getLogger(__name__)
connection = None
# If we are running as root and the scheme has not been explicitly set,
10 years, 2 months
[cura-tools] master: terminate with exit code of last command executed (fcf648f)
by miminar@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master
>---------------------------------------------------------------
commit fcf648f891c27eeb68ebe6bbaf2f600e51f20ae4
Author: Michal Minar <miminar(a)redhat.com>
Date: Sun Jan 19 15:13:32 2014 +0100
terminate with exit code of last command executed
Make sure that return code of triggered command gets propagated to the
application's entry point.
In interactive mode, meta-command shall exit with the return code of the
last command executed. Note that exit is also a command (returning 0 by
default).
Resolves ticket #174
Original commit digest in openlmi-scripts repo:
0580e779fee8bcd21dd00b2374c96902c1b49cf1
>---------------------------------------------------------------
cli/lmi/scripts/_metacommand/__init__.py | 5 ++++-
cli/lmi/scripts/common/command/base.py | 4 +++-
cli/lmi/scripts/common/command/session.py | 2 +-
3 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/cli/lmi/scripts/_metacommand/__init__.py b/cli/lmi/scripts/_metacommand/__init__.py
index e26c1b7..598c0a7 100644
--- a/cli/lmi/scripts/_metacommand/__init__.py
+++ b/cli/lmi/scripts/_metacommand/__init__.py
@@ -204,7 +204,7 @@ class MetaCommand(object):
"""
cmd = TopLevelCommand(self)
try:
- return cmd.run(argv)
+ retval = cmd.run(argv)
except Exception as exc:
trace = True if self.config is None else self.config.trace
if isinstance(exc, errors.LmiError) or not trace:
@@ -212,6 +212,9 @@ class MetaCommand(object):
else:
LOG().exception("fatal")
return 1
+ if isinstance(retval, bool) or not isinstance(retval, (int, long)):
+ return 0 if bool(retval) or retval is None else 1
+ return retval
def main(argv=sys.argv[1:]):
"""
diff --git a/cli/lmi/scripts/common/command/base.py b/cli/lmi/scripts/common/command/base.py
index dcf40bf..62a1aec 100644
--- a/cli/lmi/scripts/common/command/base.py
+++ b/cli/lmi/scripts/common/command/base.py
@@ -219,7 +219,9 @@ class LmiBaseCommand(object):
:param list args: Arguments passed to the command line that were
not yet parsed. It's the contents of ``sys.argv`` (if in
non-interactive mode) from the current command on.
- :returns: Exit code of application.
+ :returns: Exit code of application. This maybe also be a boolean value
+ or ``None``. ``None`` and ``True`` are treated as a success causing
+ exit code to be 0.
:rtype: integer
"""
raise NotImplementedError("run method must be overriden in subclass")
diff --git a/cli/lmi/scripts/common/command/session.py b/cli/lmi/scripts/common/command/session.py
index 1be7fec..b65952a 100644
--- a/cli/lmi/scripts/common/command/session.py
+++ b/cli/lmi/scripts/common/command/session.py
@@ -187,5 +187,5 @@ class LmiSessionCommand(LmiEndPointCommand):
return self.execute(connection, *args, **kwargs)
def run_with_args(self, args, kwargs):
- self.process_session(self.app.session, args, kwargs)
+ return self.process_session(self.app.session, args, kwargs)
10 years, 2 months
[cura-tools] master: exit interactive mode only when LmiTerminate is raised (8c31101)
by miminar@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master
>---------------------------------------------------------------
commit 8c311014fddd2e5c7affb03a90f3b8a5f13ddd11
Author: Michal Minar <miminar(a)redhat.com>
Date: Sun Jan 19 15:14:54 2014 +0100
exit interactive mode only when LmiTerminate is raised
Do not take into account the return value of executed command when
deciding whether to stop the shell. Terminate only when LmiTerminate is
raised.
Original commit digest in openlmi-scripts repo:
97fc31be422e833232679cfb27fbcfd4ae3fde5b
>---------------------------------------------------------------
cli/lmi/scripts/_metacommand/interactive.py | 21 +++++++++++++++++++--
1 files changed, 19 insertions(+), 2 deletions(-)
diff --git a/cli/lmi/scripts/_metacommand/interactive.py b/cli/lmi/scripts/_metacommand/interactive.py
index bc31bf1..1170a94 100644
--- a/cli/lmi/scripts/_metacommand/interactive.py
+++ b/cli/lmi/scripts/_metacommand/interactive.py
@@ -42,6 +42,7 @@ class Interactive(cmd.Cmd):
cmd.Cmd.__init__(self,
stdin=parent_app.stdin, stdout=parent_app.stdout)
self.prompt = prompt
+ self._last_exit_code = 0
@property
def command_manager(self):
@@ -74,7 +75,11 @@ class Interactive(cmd.Cmd):
line_parts = shlex.split(line)
try:
# let's try to run registered subcommand
- return self.run_subcommand(line_parts)
+ retval = self.run_subcommand(line_parts)
+ if isinstance(retval, bool) or not isinstance(retval, (int, long)):
+ retval = 0 if bool(retval) or retval is None else 1
+ self._last_exit_code = retval
+ return retval
except errors.LmiCommandNotFound:
return cmd.Cmd.default(self, line)
except docopt.DocoptExit as err:
@@ -137,7 +142,7 @@ class Interactive(cmd.Cmd):
"""
Exit on End-Of-File.
"""
- return True
+ raise errors.LmiTerminate(self._last_exit_code)
def get_names(self):
"""
@@ -147,3 +152,15 @@ class Interactive(cmd.Cmd):
return [ n for n in cmd.Cmd.get_names(self)
if not n.startswith('do__')]
+ def postcmd(self, stop, _line):
+ """
+ This is called after the ``do_*`` command to postprocess its result and
+ decide whether to stop the shell. We want to stop only when
+ :py:class:`lmi.scripts.common.errors.LmiError` is raised. This
+ exception is catched upwards in call chain.
+
+ :returns: Whether to stop the shell.
+ :rtype: bool
+ """
+ return False
+
10 years, 2 months
[cura-tools] master: support having number as part of command argument (77a4668)
by miminar@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master
>---------------------------------------------------------------
commit 77a4668bd778ab3ee93e738c875d517dae2dad05
Author: Radek Novacek <rnovacek(a)redhat.com>
Date: Sun Jan 19 15:17:00 2014 +0100
support having number as part of command argument
Original commit digest in openlmi-scripts repo:
0330ef79ae83163b743c64480abc95ab5e92e9f8
>---------------------------------------------------------------
cli/lmi/scripts/common/command/endpoint.py | 2 +-
cli/lmi/scripts/common/command/util.py | 6 +++---
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/cli/lmi/scripts/common/command/endpoint.py b/cli/lmi/scripts/common/command/endpoint.py
index ab6471f..4b1b268 100644
--- a/cli/lmi/scripts/common/command/endpoint.py
+++ b/cli/lmi/scripts/common/command/endpoint.py
@@ -40,7 +40,7 @@ def opt_name_sanitize(opt_name):
:returns: Modified option name.
:rtype: string
"""
- return re.sub(r'[^a-zA-Z]+', '_', opt_name).lower()
+ return re.sub(r'[^a-zA-Z0-9]+', '_', opt_name).lower()
def options_dict2kwargs(options):
"""
diff --git a/cli/lmi/scripts/common/command/util.py b/cli/lmi/scripts/common/command/util.py
index 2209475..975fa78 100644
--- a/cli/lmi/scripts/common/command/util.py
+++ b/cli/lmi/scripts/common/command/util.py
@@ -22,14 +22,14 @@ import re
RE_OPT_BRACKET_ARGUMENT = re.compile('^<(?P<name>[^>]+)>$')
#: Regular expression matching argument written in upper case such as
#:``ARG_NAME``.
-RE_OPT_UPPER_ARGUMENT = re.compile('^(?P<name>[A-Z]+(?:[_-][A-Z]+)*)$')
+RE_OPT_UPPER_ARGUMENT = re.compile('^(?P<name>[A-Z0-9]+(?:[_-][A-Z0-9]+)*)$')
#: Regular expression matching showt options. They are one character
#: long, prefixed with single dash.
RE_OPT_SHORT_OPTION = re.compile('^-(?P<name>[a-z])$', re.IGNORECASE)
#: Regular expression matching long options (prefixed with double dash).
-RE_OPT_LONG_OPTION = re.compile('^--(?P<name>[a-z_-]+)$', re.IGNORECASE)
+RE_OPT_LONG_OPTION = re.compile('^--(?P<name>[a-z0-9_-]+)$', re.IGNORECASE)
#: Command name can also be a single or double dash.
-RE_COMMAND_NAME = re.compile(r'^([a-z]+(-[a-z]+)*|--?)$')
+RE_COMMAND_NAME = re.compile(r'^([a-z]+(-[a-z0-9]+)*|--?)$')
def is_abstract_method(clss, method, missing_is_abstract=False):
"""
10 years, 2 months
[cura-tools] master: fixed printing of table items to pipe (571bd27)
by miminar@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master
>---------------------------------------------------------------
commit 571bd276769f1da1881fdeae98ac8959f94a7ef4
Author: Jan Safranek <jsafrane(a)redhat.com>
Date: Sun Jan 19 15:19:30 2014 +0100
fixed printing of table items to pipe
Original commit digest in openlmi-scripts repo:
98a25ab3c7d1f8ed6891203bc41f17e3804a317d
>---------------------------------------------------------------
cli/lmi/scripts/common/formatter/__init__.py | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/cli/lmi/scripts/common/formatter/__init__.py b/cli/lmi/scripts/common/formatter/__init__.py
index 93c5f5e..6c5dcfc 100644
--- a/cli/lmi/scripts/common/formatter/__init__.py
+++ b/cli/lmi/scripts/common/formatter/__init__.py
@@ -112,7 +112,8 @@ class Formatter(object):
``line`` argument.
:param dictionary kwargs: Keyword arguments to ``format()`` function.
"""
- self.out.write(' ' * self.padding + line.format(*args, **kwargs))
+ line = ' ' * self.padding + line.format(*args, **kwargs)
+ self.out.write(line.encode(self.encoding))
self.out.write("\n")
self.line_counter += 1
10 years, 2 months