Sign In
Sign Up
Sign In
Sign Up
Manage this list
×
Keyboard Shortcuts
Thread View
j
: Next unread message
k
: Previous unread message
j a
: Jump to all threads
j l
: Jump to MailingList overview
2024
June
May
April
March
February
January
2023
December
November
October
September
August
July
June
May
April
March
February
January
2022
December
November
October
September
August
July
June
May
April
March
February
January
2021
December
November
October
September
August
July
June
May
April
March
February
January
2020
December
November
October
September
August
July
June
May
April
March
February
January
2019
December
November
October
September
August
July
June
May
April
March
February
January
2018
December
November
October
September
August
July
June
May
April
March
February
January
2017
December
November
October
September
August
July
June
May
April
March
February
January
2016
December
November
October
September
August
July
June
May
April
March
February
January
2015
December
November
October
September
August
July
June
May
April
March
February
January
2014
December
November
October
September
August
July
June
May
April
March
February
January
2013
December
November
October
September
August
July
June
May
April
March
February
January
2012
December
November
October
List overview
Download
cura-tools-devel
January 2013
----- 2024 -----
June 2024
May 2024
April 2024
March 2024
February 2024
January 2024
----- 2023 -----
December 2023
November 2023
October 2023
September 2023
August 2023
July 2023
June 2023
May 2023
April 2023
March 2023
February 2023
January 2023
----- 2022 -----
December 2022
November 2022
October 2022
September 2022
August 2022
July 2022
June 2022
May 2022
April 2022
March 2022
February 2022
January 2022
----- 2021 -----
December 2021
November 2021
October 2021
September 2021
August 2021
July 2021
June 2021
May 2021
April 2021
March 2021
February 2021
January 2021
----- 2020 -----
December 2020
November 2020
October 2020
September 2020
August 2020
July 2020
June 2020
May 2020
April 2020
March 2020
February 2020
January 2020
----- 2019 -----
December 2019
November 2019
October 2019
September 2019
August 2019
July 2019
June 2019
May 2019
April 2019
March 2019
February 2019
January 2019
----- 2018 -----
December 2018
November 2018
October 2018
September 2018
August 2018
July 2018
June 2018
May 2018
April 2018
March 2018
February 2018
January 2018
----- 2017 -----
December 2017
November 2017
October 2017
September 2017
August 2017
July 2017
June 2017
May 2017
April 2017
March 2017
February 2017
January 2017
----- 2016 -----
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
January 2016
----- 2015 -----
December 2015
November 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
----- 2014 -----
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014
April 2014
March 2014
February 2014
January 2014
----- 2013 -----
December 2013
November 2013
October 2013
September 2013
August 2013
July 2013
June 2013
May 2013
April 2013
March 2013
February 2013
January 2013
----- 2012 -----
December 2012
November 2012
October 2012
cura-tools-devel@lists.fedorahosted.org
2 participants
18 discussions
Start a n
N
ew thread
[cura-tools] master: fix pager dimensions issue when using interactive iface (71390ef)
by phatina@fedoraproject.org
30 Jan '13
30 Jan '13
Repository :
http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master >--------------------------------------------------------------- commit 71390ef55bd0238cb978477c19ce481596182cc5 Author: Peter Hatina <phatina(a)redhat.com> Date: Wed Jan 30 15:11:07 2013 +0100 fix pager dimensions issue when using interactive iface >--------------------------------------------------------------- cli-tools/lmi/lmi_client_shell.py | 28 +++++++++++++++++++++------- 1 files changed, 21 insertions(+), 7 deletions(-) diff --git a/cli-tools/lmi/lmi_client_shell.py b/cli-tools/lmi/lmi_client_shell.py index 58e183d..b043a5f 100644 --- a/cli-tools/lmi/lmi_client_shell.py +++ b/cli-tools/lmi/lmi_client_shell.py @@ -36,6 +36,9 @@ class LmiUnknownParameterError(Exception): class LmiMethodCallError(Exception): """Raised, when an error occurs within method call""" +class LmiNoPagerError(Exception): + """Raised, when tere is no default pager like less or more""" + class _LmiTextFormatter(object): def __init__(self, text): self._text = text @@ -55,9 +58,8 @@ class _LmiFormatter(object): __metaclass__ = abc.ABCMeta def __init__(self): - self._width = int(os.popen('stty size', 'r').read().split()[1]) - if not self._width: - self._width = 80 + stty_dimensions = os.popen("stty size 2> /dev/null", "r").read().split() + self._width = int(stty_dimensions[1]) if stty_dimensions else 80 @abc.abstractmethod def format(self, indent = 0, sub_indent = 0, width = 80, f = sys.stdout): @@ -80,11 +82,19 @@ class _LmiFormatter(object): @staticmethod def __get_pager(): if "PAGER" in os.environ: - return os.environ["PAGER"] + pager = os.environ["PAGER"].split() + if os.path.exists(pager[0]) and os.access(pager[0], X_OK): + return pager for p in ["less", "more"]: path = _LmiFormatter.__which(p) - if path: - return path + if not path: + continue + elif p == "less": + return [path, "-S"] + return [path] + if LmiBaseClient._get_use_exceptions(): + raise LmiNoPagerError("No default pager found") + return [] def fancy_format(self, interactive): if interactive: @@ -92,7 +102,11 @@ class _LmiFormatter(object): f = os.fdopen(tmpfile[0], "w") self.format(0, 0, self._width, f) f.close() - subprocess.call([_LmiFormatter.__get_pager(), tmpfile[1]]) + subprocess_params = _LmiFormatter.__get_pager() + if not subprocess_params: + return + subprocess_params.append(tmpfile[1]) + subprocess.call(subprocess_params) os.remove(tmpfile[1]) else: self.format(0, 0, self._width)
1
0
0
0
[cura-tools] master: introduce _LmiInstanceMethod::tomof() (2e901db)
by phatina@fedoraproject.org
30 Jan '13
30 Jan '13
Repository :
http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master >--------------------------------------------------------------- commit 2e901db0e2e17fde1cf52da54dc97bfa70eb6913 Author: Peter Hatina <phatina(a)redhat.com> Date: Wed Jan 30 14:09:00 2013 +0100 introduce _LmiInstanceMethod::tomof() >--------------------------------------------------------------- cli-tools/lmi/lmi_client_shell.py | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-) diff --git a/cli-tools/lmi/lmi_client_shell.py b/cli-tools/lmi/lmi_client_shell.py index 03bd667..58e183d 100644 --- a/cli-tools/lmi/lmi_client_shell.py +++ b/cli-tools/lmi/lmi_client_shell.py @@ -523,6 +523,9 @@ class _LmiInstance(BaseObject): rparams = rparams, errorstr = errorstr) + def tomof(self): + _LmiMofFormatter(self._method.tomof()).fancy_format(self._client.interactive) + def __init__(self, client, lmi_class, cim_instance): super(self.__class__, self).__init__() # We use __dict__ to avoid recursion potentially caused by
1
0
0
0
[cura-tools] master: introduce _LmiInstance::tomof() (3504324)
by phatina@fedoraproject.org
30 Jan '13
30 Jan '13
Repository :
http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master >--------------------------------------------------------------- commit 350432469b21e2ea258a6dfebf512956aa175d5b Author: Peter Hatina <phatina(a)redhat.com> Date: Wed Jan 30 13:04:11 2013 +0100 introduce _LmiInstance::tomof() >--------------------------------------------------------------- cli-tools/lmi/lmi_client_shell.py | 94 +++++++++++++++++++++++-------------- 1 files changed, 59 insertions(+), 35 deletions(-) diff --git a/cli-tools/lmi/lmi_client_shell.py b/cli-tools/lmi/lmi_client_shell.py index 38bbc82..03bd667 100644 --- a/cli-tools/lmi/lmi_client_shell.py +++ b/cli-tools/lmi/lmi_client_shell.py @@ -14,6 +14,7 @@ # along with this program; if not, see <
http://www.gnu.org/licenses/
>. import os +import abc import new import sys import pywbem @@ -50,13 +51,57 @@ class _LmiTextFormatter(object): if "separator" in kwargs and kwargs["separator"]: f.write("\n") -class _LmiXmlFormatter(object): - def __init__(self, xml): - self._xml = xml +class _LmiFormatter(object): + __metaclass__ = abc.ABCMeta + + def __init__(self): self._width = int(os.popen('stty size', 'r').read().split()[1]) if not self._width: self._width = 80 + @abc.abstractmethod + def format(self, indent = 0, sub_indent = 0, width = 80, f = sys.stdout): + pass + + @staticmethod + def __which(program): + is_exe = lambda fpath: os.path.isfile(fpath) and os.access(fpath, os.X_OK) + fpath, fname = os.path.split(program) + if fpath: + if is_exe(program): + return program + else: + for path in os.environ["PATH"].split(os.pathsep): + exe_file = os.path.join(path, program) + if is_exe(exe_file): + return exe_file + return None + + @staticmethod + def __get_pager(): + if "PAGER" in os.environ: + return os.environ["PAGER"] + for p in ["less", "more"]: + path = _LmiFormatter.__which(p) + if path: + return path + + def fancy_format(self, interactive): + if interactive: + tmpfile = tempfile.mkstemp() + f = os.fdopen(tmpfile[0], "w") + self.format(0, 0, self._width, f) + f.close() + subprocess.call([_LmiFormatter.__get_pager(), tmpfile[1]]) + os.remove(tmpfile[1]) + else: + self.format(0, 0, self._width) + +class _LmiXmlFormatter(_LmiFormatter): + def __init__(self, xml): + super(self.__class__, self).__init__() + self._xml = xml + def __format_class_property_content(self, node, indent = 0, sub_indent = 0, width = 80, f = sys.stdout): children = node.childNodes children_len = len(children) @@ -166,44 +211,19 @@ class _LmiXmlFormatter(object): elif isinstance(n, pywbem.cim_xml.PROPERTY_REFERENCE): self.__format_instance_property_reference(n, indent + 4, sub_indent, width, f) - @staticmethod - def __which(program): - is_exe = lambda fpath: os.path.isfile(fpath) and os.access(fpath, os.X_OK) - fpath, fname = os.path.split(program) - if fpath: - if is_exe(program): - return program - else: - for path in os.environ["PATH"].split(os.pathsep): - exe_file = os.path.join(path, program) - if is_exe(exe_file): - return exe_file - return None - - def __get_pager(self): - if "PAGER" in os.environ: - return os.environ["PAGER"] - for p in ["less", "more"]: - path = self.__which(p) - if path: - return path - def format(self, indent = 0, sub_indent = 0, width = 80, f = sys.stdout): if isinstance(self._xml, pywbem.cim_xml.CLASS): self.__format_class(self._xml, indent, sub_indent, width, f) elif isinstance(self._xml, pywbem.cim_xml.VALUE_NAMEDINSTANCE): self.__format_instance(self._xml, indent, sub_indent, width, f) - def fancy_format(self, interactive): - if interactive: - tmpfile = tempfile.mkstemp() - f = os.fdopen(tmpfile[0], "w") - self.format(0, 0, self._width, f) - f.close() - subprocess.call([self.__get_pager(), tmpfile[1]]) - os.remove(tmpfile[1]) - else: - self.format(0, 0, self._width) +class _LmiMofFormatter(_LmiFormatter): + def __init__(self, mof): + super(self.__class__, self).__init__() + self._mof = mof + + def format(self, indent = 0, sub_indent = 0, width = 80, f = sys.stdout): + f.write(self._mof) # Base class for classes, that are used for tab-completion. # Used due to deprecated methods since python 2.2. @@ -554,6 +574,10 @@ class _LmiInstance(BaseObject): _LmiXmlFormatter(self._cim_instance.tocimxml()).fancy_format(self._client.interactive) @possibly_deleted + def tomof(self): + _LmiMofFormatter(self._cim_instance.tomof()).fancy_format(self._client.interactive) + + @possibly_deleted def associators(self, AssocClass = None, ResultClass = None, Role = None,\ ResultRole = None, Props = None): result = []
1
0
0
0
[cura-tools] master: introduce use_exceptions() switch (205d130)
by phatina@fedoraproject.org
30 Jan '13
30 Jan '13
Repository :
http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master >--------------------------------------------------------------- commit 205d130c1e0b5bbec9eef538818cd7c9d4e08df7 Author: Peter Hatina <phatina(a)redhat.com> Date: Tue Jan 29 18:00:04 2013 +0100 introduce use_exceptions() switch >--------------------------------------------------------------- cli-tools/lmi/lmi_client_base.py | 32 ++++++++++++++++++++++++++++++++ cli-tools/lmi/lmi_client_shell.py | 26 +++++++++++++++++++++++--- cli-tools/lmishell | 8 +++++++- 3 files changed, 62 insertions(+), 4 deletions(-) diff --git a/cli-tools/lmi/lmi_client_base.py b/cli-tools/lmi/lmi_client_base.py index ac6b66c..a850f77 100644 --- a/cli-tools/lmi/lmi_client_base.py +++ b/cli-tools/lmi/lmi_client_base.py @@ -13,11 +13,18 @@ # You should have received a copy of the GNU General Public License # along with this program; if not, see <
http://www.gnu.org/licenses/
>. +import sys import pywbem import collections _RValue = collections.namedtuple('RValue', ["rval", "rparams", "errorstr"]) +def raise_or_dump_exception(e): + if not LmiBaseClient._get_use_exceptions(): + return + (et, ei, tb) = sys.exc_info() + raise et, ei, tb + class LmiReturnValue(_RValue): def __getattr__(self, name): if not name in self._properties: @@ -56,6 +63,7 @@ class LmiReturnValue(_RValue): class LmiBaseClient(object): QUERY_LANG_CQL = "CQL" QUERY_LANG_WQL = "WQL" + use_exceptions_flag = False def __init__(self, hostname, username = "", password = ""): self._hostname = hostname @@ -71,8 +79,10 @@ class LmiBaseClient(object): try: inst_name_list = self._cliconn.EnumerateInstanceNames(klass, **kwargs) except pywbem.cim_operations.CIMError, e: + raise_or_dump_exception(e) return LmiReturnValue(rval = None, rparams = {}, errorstr = e.args[1]) except pywbem.cim_http.AuthError, e: + raise_or_dump_exception(e) return LmiReturnValue(rval = None, rparams = {}, errorstr = e.args[0]) return LmiReturnValue(rval = inst_name_list, rparams = {}, errorstr = "") @@ -107,6 +117,7 @@ class LmiBaseClient(object): try: inst = self._cliconn.GetInstance(InstanceName=i, LocalOnly = False) except pywbem.cim_operations.CIMError, e: + raise_or_dump_exception(e) # we can get this error for eg. Linux_UnixProcess instances # when, there the process exited earlier than this method if e.args[0] == pywbem.CIM_ERR_NOT_FOUND: @@ -124,6 +135,7 @@ class LmiBaseClient(object): try: self._cliconn.DeleteInstance(inst.path) except pywbem.cim_operations.CIMError, e: + raise_or_dump_exception(e) return LmiReturnValue(rval = False, rparams = {}, errorstr = e.args[1]) return LmiReturnValue(rval = True, rparams = {}, errorstr = "") @@ -131,8 +143,10 @@ class LmiBaseClient(object): try: class_name_list = self._cliconn.EnumerateClassNames(namespace, **kwargs) except pywbem.cim_operations.CIMError, e: + raise_or_dump_exception(e) return LmiReturnValue(rval = None, rparams = {}, errorstr = e.args[1]) except pywbem.cim_http.AuthError, e: + raise_or_dump_exception(e) return LmiReturnValue(rval = None, rparams = {}, errorstr = e.args[0]) return LmiReturnValue(rval = class_name_list, rparams = {}, errorstr = "") @@ -140,8 +154,10 @@ class LmiBaseClient(object): try: class_list = self._cliconn.EnumerateClasses(namespace, **kwargs) except pywbem.cim_operations.CIMError, e: + raise_or_dump_exception(e) return LmiReturnValue(rval = None, rparams = {}, errorstr = e.args[1]) except pywbem.cim_http.AuthError, e: + raise_or_dump_exception(e) return LmiReturnValue(rval = None, rparams = {}, errorstr = e.args[0]) return LmiReturnValue(rval = class_list, rparams = {}, errorstr = "") @@ -149,8 +165,10 @@ class LmiBaseClient(object): try: klass = self._cliconn.GetClass(class_name, namespace, **kwargs) except pywbem.cim_operations.CIMError, e: + raise_or_dump_exception(e) return LmiReturnValue(rval = None, rparams = {}, errorstr = e.args[1]) except pywbem.cim_http.AuthError, e: + raise_or_dump_exception(e) return LmiReturnValue(rval = None, rparams = {}, errorstr = e.args[0]) return LmiReturnValue(rval = klass, rparams = {}, errorstr = "") @@ -158,6 +176,7 @@ class LmiBaseClient(object): try: (rval, rparams) = self._cliconn.InvokeMethod(method, instance.path, **params) except pywbem.cim_operations.CIMError, e: + raise_or_dump_exception(e) return LmiReturnValue(rval = -1, rparams = {}, errorstr = e.args[1] + ": '" + method + "'") return LmiReturnValue(rval = rval, rparams = rparams, errorstr = "") @@ -169,18 +188,21 @@ class LmiBaseClient(object): try: return self._cliconn.Associators(instance.path, **params) except pywbem.cim_operations.CIMError, e: + raise_or_dump_exception(e) return [] def _get_references(self, instance, **params): try: return self._cliconn.References(instance.path, **params) except pywbem.cim_operations.CIMError, e: + raise_or_dump_exception(e) return [] def _modify_instance(self, instance, **params): try: self._cliconn.ModifyInstance(instance, **params) except pywbem.cim_operations.CIMError, e: + raise_or_dump_exception(e) return LmiReturnValue(rval = e.args[0], rparams = {}, errorstr = e.args[1]) return LmiReturnValue(rval = 0, rparams = {}, errorstr = "") @@ -188,6 +210,7 @@ class LmiBaseClient(object): try: self._cliconn.DeleteInstance(instance, **params) except pywbem.cim_operations.CIMError, e: + raise_or_dump_exception(e) return LmiReturnValue(rval = e.args[0], rparams = {}, errorstr = e.args[1]) return LmiReturnValue(rval = 0, rparams = {}, errorstr = "") @@ -195,9 +218,18 @@ class LmiBaseClient(object): try: inst_list = self._cliconn.ExecQuery(query_lang, query, namespace) except pywbem.cim_operations.CIMError, e: + raise_or_dump_exception(e) return LmiReturnValue(rval = None, rparams = {}, errorstr = e.args[1]) return LmiReturnValue(rval = inst_list, rparams = {}, errorstr = "") + @staticmethod + def _set_use_exceptions(use = True): + LmiBaseClient.use_exceptions_flag = use + + @staticmethod + def _get_use_exceptions(): + return LmiBaseClient.use_exceptions_flag + @property def username(self): return self._username diff --git a/cli-tools/lmi/lmi_client_shell.py b/cli-tools/lmi/lmi_client_shell.py index fb33926..eba4da5 100644 --- a/cli-tools/lmi/lmi_client_shell.py +++ b/cli-tools/lmi/lmi_client_shell.py @@ -24,6 +24,17 @@ from xml.dom.minicompat import NodeList from lmi_client_base import LmiBaseClient from lmi_client_base import LmiReturnValue +class LmiDeletedObjectError(Exception): + """Raised, when there is an attempt to access properties + on deleted _LmiInstance object""" + +class LmiUnknownParameterError(Exception): + """Raised, when there is a method call issued and unknown + method parameter is provided""" + +class LmiMethodCallError(Exception): + """Raised, when an error occurs within method call""" + class _LmiTextFormatter(object): def __init__(self, text): self._text = text @@ -385,13 +396,16 @@ def possibly_deleted(fn): def wrapped(self = None, *args, **kwargs): if not self._deleted: return fn(self, *args, **kwargs) + errorstr = "This instance has been deleted from a CIM broker" + if LmiBaseClient._get_use_exceptions(): + raise LmiDeletedObjectError(errorstr) return LmiReturnValue( hostname = self._client.hostname, instance = self, use_display_hook = True, rval = None, rparams = {}, - errorstr = "This instance has been deleted from a CIM broker") + errorstr = errorstr) return wrapped class _LmiInstance(BaseObject): @@ -454,9 +468,11 @@ class _LmiInstance(BaseObject): else: # 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) + if LmiBaseClient._get_use_exceptions(): + raise LmiUnknownParameterError(errorstr) return LmiReturnValue(rval = -1, rparams = {}, - errorstr = "Unknown parameter '%s' supplied for method '%s'" - % (param, self._method.name), hostname = self._client.hostname, + errorstr = errorstr, hostname = self._client.hostname, use_display_hook = True) (rval, rparams, errorstr) = self._client._call_method_raw(self._instance, self._method.name, **kwargs) @@ -468,11 +484,15 @@ class _LmiInstance(BaseObject): rparams = self.__transform_return_values(rparams) if not rparams: # NOTE: this is wrong! What should we do? + if LmiBaseClient._get_use_exceptions(): + raise LmiMethodCallError("Could not perform CIM -> LMI object transformation") return LmiReturnValue(rval = rval, rparams = {}, errorstr = errorstr) (new_inst, _, errorstr) = self._client._get_instance( self._instance.path, LocalOnly = False) if not new_inst: # NOTE: this is wrong! What should we do? + if LmiBaseClient._get_use_exceptions(): + raise LmiMethodCallError("Could not update an LMI object after a method call") return LmiReturnValue(rval = rval, rparams = {}, errorstr = errorstr) self._instance._inst = new_inst return LmiReturnValue( diff --git a/cli-tools/lmishell b/cli-tools/lmishell index 289b459..5093401 100755 --- a/cli-tools/lmishell +++ b/cli-tools/lmishell @@ -21,6 +21,7 @@ import readline import rlcompleter import __builtin__ from lmi.lmi_client_base import LmiReturnValue +from lmi.lmi_client_base import LmiBaseClient from lmi.lmi_client_shell import LmiConnection from lmi.lmi_client_shell import _LmiNamespace from lmi.lmi_client_shell import _LmiNamespaceRoot @@ -170,6 +171,7 @@ class LmiInteractiveShell(code.InteractiveConsole): locals["connect"] = _connect_interactive locals["clear_history"] = self.clear_history locals["use_display_sugar"] = _use_display_sugar + locals["use_exceptions"] = _use_exceptions code.InteractiveConsole.__init__(self, locals) self._completer = _LmiCompleter(self.locals) self._history_path = os.path.expanduser("~/.lmi_shell_history") @@ -263,6 +265,9 @@ def _connect(hostname, username = "", password = "", interactive = False): def _use_display_sugar(use = True): sys.displayhook = _lmi_displayhook if use else sys.__displayhook__ +def _use_exceptions(use = True): + LmiBaseClient._set_use_exceptions(use) + if __name__ == "__main__": options = _LmiShellOptions(sys.argv) if not options.good: @@ -279,7 +284,8 @@ if __name__ == "__main__": else: locals = { "LmiConnection" : LmiConnection, - "connect" : _connect_noninteractive + "connect" : _connect_noninteractive, + "use_exceptions" : _use_exceptions } sys.argv = options.script_args try:
1
0
0
0
[cura-tools] master: some naming changes in lmi_client_shell (e885171)
by phatina@fedoraproject.org
30 Jan '13
30 Jan '13
Repository :
http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master >--------------------------------------------------------------- commit e885171e128201f5a1c292bcf72b467f41c3f92a Author: Peter Hatina <phatina(a)redhat.com> Date: Wed Jan 30 11:45:25 2013 +0100 some naming changes in lmi_client_shell >--------------------------------------------------------------- cli-tools/lmi/lmi_client_shell.py | 90 ++++++++++++++++++------------------ 1 files changed, 45 insertions(+), 45 deletions(-) diff --git a/cli-tools/lmi/lmi_client_shell.py b/cli-tools/lmi/lmi_client_shell.py index eba4da5..38bbc82 100644 --- a/cli-tools/lmi/lmi_client_shell.py +++ b/cli-tools/lmi/lmi_client_shell.py @@ -317,17 +317,17 @@ class _LmiClass(BaseObject): super(self.__class__, self).__init__() self._client = client self._namespace = namespace - self._class = klass + self._cim_class = klass def __repr__(self): return "%s(classname='%s', ...)" % (self.__class__.__name__, self.classname) def doc(self): - _LmiXmlFormatter(self._class.tocimxml()).fancy_format(self._client.interactive) + _LmiXmlFormatter(self._cim_class.tocimxml()).fancy_format(self._client.interactive) def instances(self, **kwargs): (instance_list, _, errorstr) = self._client._get_instances( - self._class.classname, **kwargs) + self._cim_class.classname, **kwargs) if not instance_list: return [] result = [] @@ -342,55 +342,55 @@ class _LmiClass(BaseObject): return instance_list[0] def properties(self): - return self._class.properties.keys() + return self._cim_class.properties.keys() def print_properties(self): - for (name, prop) in self._class.properties.iteritems(): + for (name, prop) in self._cim_class.properties.iteritems(): sys.stdout.write("%s\n" % name) def methods(self): - return self._class.methods.keys() + return self._cim_class.methods.keys() def print_methods(self): - for (name, method) in self._class.methods.iteritems(): + for (name, method) in self._cim_class.methods.iteritems(): sys.stdout.write("%s\n" % name) @property def classname(self): - return self._class.classname + return self._cim_class.classname @property def namespace(self): return self._namespace.name class _LmiInstanceName(BaseObject): - def __init__(self, client, instance_name): + def __init__(self, client, cim_instance_name): self._client = client - self._instance_name = instance_name + self._cim_instance_name = cim_instance_name def __repr__(self): return "%s(...)" % self.__class__.__name__ def to_instance(self): - (cim_inst, _, errorstr) = self._client._get_instance( - self._instance_name, LocalOnly = False) - if not cim_inst: + (cim_instance, _, errorstr) = self._client._get_instance( + self._cim_instance_name, LocalOnly = False) + if not cim_instance: return None - lmi_namespace = _LmiNamespace(self._client, self._instance_name.namespace) + lmi_namespace = _LmiNamespace(self._client, self._cim_instance_name.namespace) (cim_class, _, errorstr) = self._client._get_class( - self._instance_name.classname, - self._instance_name.namespace, + self._cim_instance_name.classname, + self._cim_instance_name.namespace, LocalOnly = False) if not cim_class: return None lmi_class = _LmiClass(self._client, lmi_namespace, cim_class) if not lmi_class: return None - return _LmiInstance(self._client, lmi_class, cim_inst) + return _LmiInstance(self._client, lmi_class, cim_instance) @property def path(self): - return str(self._instance_name) + return str(self._cim_instance_name) def possibly_deleted(fn): def wrapped(self = None, *args, **kwargs): @@ -410,11 +410,11 @@ def possibly_deleted(fn): class _LmiInstance(BaseObject): class _LmiInstanceMethod(BaseObject): - def __init__(self, client, instance, method): + def __init__(self, client, lmi_instance, method): super(self.__class__, self).__init__() self._client = client - self._instance = instance - self._method = instance._class._class.methods[method] + self._lmi_instance = lmi_instance + self._method = lmi_instance._lmi_class._cim_class.methods[method] def __transform_return_values(self, rparams): lmi_rparams = pywbem.NocaseDict() @@ -457,7 +457,7 @@ class _LmiInstance(BaseObject): "uint32" : lambda x: pywbem.Uint32(x), "sint64" : lambda x: pywbem.Sint64(x), "uint64" : lambda x: pywbem.Uint64(x), - "reference": lambda x: x._inst.path if isinstance(x, _LmiInstance) else x + "reference": lambda x: x._cim_instance.path if isinstance(x, _LmiInstance) else x } for (param, value) in kwargs.iteritems(): if param in self._method.parameters: @@ -474,7 +474,7 @@ class _LmiInstance(BaseObject): return LmiReturnValue(rval = -1, rparams = {}, errorstr = errorstr, hostname = self._client.hostname, use_display_hook = True) - (rval, rparams, errorstr) = self._client._call_method_raw(self._instance, + (rval, rparams, errorstr) = self._client._call_method_raw(self._lmi_instance, self._method.name, **kwargs) if isinstance(rval, pywbem.CIMInt): rval = int(rval) @@ -488,29 +488,29 @@ class _LmiInstance(BaseObject): raise LmiMethodCallError("Could not perform CIM -> LMI object transformation") return LmiReturnValue(rval = rval, rparams = {}, errorstr = errorstr) (new_inst, _, errorstr) = self._client._get_instance( - self._instance.path, LocalOnly = False) + self._lmi_instance.path, LocalOnly = False) if not new_inst: # NOTE: this is wrong! What should we do? if LmiBaseClient._get_use_exceptions(): raise LmiMethodCallError("Could not update an LMI object after a method call") return LmiReturnValue(rval = rval, rparams = {}, errorstr = errorstr) - self._instance._inst = new_inst + self._lmi_instance._cim_instance = new_inst return LmiReturnValue( hostname = self._client.hostname, - instance = self._instance, + instance = self._lmi_instance, use_display_hook = True, rval = rval, rparams = rparams, errorstr = errorstr) - def __init__(self, client, klass, inst): + def __init__(self, client, lmi_class, cim_instance): super(self.__class__, self).__init__() # We use __dict__ to avoid recursion potentially caused by # combo __setattr__ and __getattr__ self.__dict__["_deleted"] = False - self.__dict__["_inst"] = inst + self.__dict__["_cim_instance"] = cim_instance self.__dict__["_client"] = client - self.__dict__["_class"] = klass + self.__dict__["_lmi_class"] = lmi_class @possibly_deleted def __getattr__(self, name): @@ -519,14 +519,14 @@ class _LmiInstance(BaseObject): methods = self.methods() if methods and name in methods: return _LmiInstance._LmiInstanceMethod(self._client, self, name) - elif name in self._inst: - return self._inst[name] + elif name in self._cim_instance: + return self._cim_instance[name] raise AttributeError(name) @possibly_deleted def __setattr__(self, name, value): - if name in self._inst: - self._inst[name] = value + if name in self._cim_instance: + self._cim_instance[name] = value else: self.__dict__[name] = value @@ -537,21 +537,21 @@ class _LmiInstance(BaseObject): @property @possibly_deleted def classname(self): - return self._class.classname + return self._lmi_class.classname @property @possibly_deleted def namespace(self): - return self._class.namespace + return self._lmi_class.namespace @property @possibly_deleted def path(self): - return self._inst.path + return self._cim_instance.path @possibly_deleted def doc(self): - _LmiXmlFormatter(self._inst.tocimxml()).fancy_format(self._client.interactive) + _LmiXmlFormatter(self._cim_instance.tocimxml()).fancy_format(self._client.interactive) @possibly_deleted def associators(self, AssocClass = None, ResultClass = None, Role = None,\ @@ -568,7 +568,7 @@ class _LmiInstance(BaseObject): assoc_args["ResultRole"] = ResultRole if Props: assoc_args["Props"] = Props - associators_list = self._client._get_associators(self._inst, **assoc_args) + associators_list = self._client._get_associators(self._cim_instance, **assoc_args) for i in associators_list: (cim_class, _, errorstr) = self._client._get_class(i.classname, i.path.namespace, LocalOnly = False) @@ -590,7 +590,7 @@ class _LmiInstance(BaseObject): references_args["Role"] = Role if Props: references_args["Props"] = Props - references_list = self._client._get_references(self._inst, **references_args) + references_list = self._client._get_references(self._cim_instance, **references_args) for i in references_list: (cim_class, _, errorstr) = self._client._get_class(i.classname, i.path.namespace, LocalOnly = False) @@ -604,27 +604,27 @@ class _LmiInstance(BaseObject): @possibly_deleted def properties(self): - return self._inst.properties.keys() + return self._cim_instance.properties.keys() @possibly_deleted def print_properties(self): - for (name, prop) in self._inst.properties.iteritems(): + for (name, prop) in self._cim_instance.properties.iteritems(): sys.stdout.write("%s\n" % name) @possibly_deleted def methods(self): - return self._class.methods() + return self._lmi_class.methods() @possibly_deleted def print_methods(self): - self._class.print_methods() + self._lmi_class.print_methods() @possibly_deleted def push(self): - return_value = self._client._modify_instance(self._inst) + return_value = self._client._modify_instance(self._cim_instance) return LmiReturnValue( hostname = self._client.hostname, - instance = self._inst, + instance = self._cim_instance, use_display_hook = True, rval = return_value.rval, rparams = return_value.rparams,
1
0
0
0
[cura-tools] master: catch exceptions in _LmiInstance::associators(), ::references() (5685d21)
by phatina@fedoraproject.org
30 Jan '13
30 Jan '13
Repository :
http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master >--------------------------------------------------------------- commit 5685d2197d10abe300c3cbb8b7a320930cdb0d00 Author: Peter Hatina <phatina(a)redhat.com> Date: Tue Jan 29 15:13:54 2013 +0100 catch exceptions in _LmiInstance::associators(), ::references() >--------------------------------------------------------------- cli-tools/lmi/lmi_client_base.py | 18 ++++++++++++------ 1 files changed, 12 insertions(+), 6 deletions(-) diff --git a/cli-tools/lmi/lmi_client_base.py b/cli-tools/lmi/lmi_client_base.py index 32c1123..ac6b66c 100644 --- a/cli-tools/lmi/lmi_client_base.py +++ b/cli-tools/lmi/lmi_client_base.py @@ -106,7 +106,7 @@ class LmiBaseClient(object): for i in inst_name_list: try: inst = self._cliconn.GetInstance(InstanceName=i, LocalOnly = False) - except pywbem.CIMError, e: + except pywbem.cim_operations.CIMError, e: # we can get this error for eg. Linux_UnixProcess instances # when, there the process exited earlier than this method if e.args[0] == pywbem.CIM_ERR_NOT_FOUND: @@ -166,29 +166,35 @@ class LmiBaseClient(object): return LmiReturnValue(rval = rval == 0, rparams = rparams, errorstr = errorstr) def _get_associators(self, instance, **params): - return self._cliconn.Associators(instance.path, **params) + try: + return self._cliconn.Associators(instance.path, **params) + except pywbem.cim_operations.CIMError, e: + return [] def _get_references(self, instance, **params): - return self._cliconn.References(instance.path, **params) + try: + return self._cliconn.References(instance.path, **params) + except pywbem.cim_operations.CIMError, e: + return [] def _modify_instance(self, instance, **params): try: self._cliconn.ModifyInstance(instance, **params) - except pywbem.CIMError, e: + except pywbem.cim_operations.CIMError, e: return LmiReturnValue(rval = e.args[0], rparams = {}, errorstr = e.args[1]) return LmiReturnValue(rval = 0, rparams = {}, errorstr = "") def _delete_instance(self, instance, **params): try: self._cliconn.DeleteInstance(instance, **params) - except pywbem.CIMError, e: + except pywbem.cim_operations.CIMError, e: return LmiReturnValue(rval = e.args[0], rparams = {}, errorstr = e.args[1]) return LmiReturnValue(rval = 0, rparams = {}, errorstr = "") def _exec_query(self, query_lang, query, namespace = None): try: inst_list = self._cliconn.ExecQuery(query_lang, query, namespace) - except pywbem.CIMError, e: + except pywbem.cim_operations.CIMError, e: return LmiReturnValue(rval = None, rparams = {}, errorstr = e.args[1]) return LmiReturnValue(rval = inst_list, rparams = {}, errorstr = "")
1
0
0
0
[cura-tools] master: add lmishell command line options check (21d86fe)
by phatina@fedorahosted.org
15 Jan '13
15 Jan '13
Repository :
http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master >--------------------------------------------------------------- commit 21d86fe144b997c3fa6911ee91ab2ddcc3e3870d Author: Peter Hatina <phatina(a)redhat.com> Date: Tue Jan 15 15:48:36 2013 +0100 add lmishell command line options check >--------------------------------------------------------------- cli-tools/lmishell | 15 ++++++++++++++- 1 files changed, 14 insertions(+), 1 deletions(-) diff --git a/cli-tools/lmishell b/cli-tools/lmishell index 82fb4f0..289b459 100755 --- a/cli-tools/lmishell +++ b/cli-tools/lmishell @@ -52,6 +52,7 @@ class _LmiShellOptions(object): self._argv = argv self._script_name = "" self._script_argv = [] + self._good = True self._inspect = False self._help = False for a in self._argv[1:]: @@ -62,8 +63,15 @@ class _LmiShellOptions(object): self._inspect = True elif not self._script_name and not a.startswith("-"): self._script_name = a - else: + elif self._script_name: self._script_argv.append(a) + else: + self._good = False + break + + @property + def good(self): + return self._good @property def help(self): @@ -257,6 +265,11 @@ def _use_display_sugar(use = True): if __name__ == "__main__": options = _LmiShellOptions(sys.argv) + if not options.good: + sys.stderr.write("Wrong tool usage!\n\n") + options.print_usage() + sys.exit(1) + if options.help: options.print_usage() sys.exit(0)
1
0
0
0
[cura-tools] master: introduce inspect feature, see python -i (79213ca)
by phatina@fedorahosted.org
15 Jan '13
15 Jan '13
Repository :
http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master >--------------------------------------------------------------- commit 79213ca5202cee4950209ceb57b789abaae62907 Author: Peter Hatina <phatina(a)redhat.com> Date: Tue Jan 15 15:31:13 2013 +0100 introduce inspect feature, see python -i >--------------------------------------------------------------- cli-tools/lmishell | 24 ++++++++++++++++++------ 1 files changed, 18 insertions(+), 6 deletions(-) diff --git a/cli-tools/lmishell b/cli-tools/lmishell index fb7aa0e..82fb4f0 100755 --- a/cli-tools/lmishell +++ b/cli-tools/lmishell @@ -52,11 +52,14 @@ class _LmiShellOptions(object): self._argv = argv self._script_name = "" self._script_argv = [] + self._inspect = False self._help = False for a in self._argv[1:]: - if not self._script_name and (a == "-h" or a == "--help"): + if not self._script_name and a in ("-h", "--help"): self._help = True return + elif not self._script_name and a in ("-i", "--inspect"): + self._inspect = True elif not self._script_name and not a.startswith("-"): self._script_name = a else: @@ -71,6 +74,10 @@ class _LmiShellOptions(object): return not self._script_name @property + def inspect(self): + return self._inspect + + @property def script_name(self): return self._script_name @@ -79,8 +86,10 @@ class _LmiShellOptions(object): return [self._script_name] + self._script_argv def print_usage(self): - sys.stdout.write("Usage: %s [script] [script-options]\n" % os.path.basename(self._argv[0])) - sys.stdout.write("\nOptions:\n -h, --help print this message\n") + sys.stdout.write("Usage: %s [options] [script] [script-options]\n" % os.path.basename(self._argv[0])) + sys.stdout.write("\nOptions:\n") + sys.stdout.write(" -h, --help print this message\n") + sys.stdout.write(" -i, --interact inspect interactively after running a script\n") class _LmiCompleter(rlcompleter.Completer): def __init__(self, namespace = None): @@ -204,8 +213,8 @@ class LmiInteractiveShell(code.InteractiveConsole): def clear_history(self): readline.clear_history() -def _lmi_interact(prompt = "> ", more_prompt = "... "): - console = LmiInteractiveShell(prompt, more_prompt) +def _lmi_interact(locals = None): + console = LmiInteractiveShell("> ", "... ", locals) console.interact() def _connect_interactive(hostname, username = "", password = ""): @@ -263,5 +272,8 @@ if __name__ == "__main__": try: execfile(options.script_name, locals) except SystemExit, e: - sys.exit(e.code) + if not options.inspect: + sys.exit(e.code) + if options.inspect: + _lmi_interact(locals) sys.exit(0)
1
0
0
0
[cura-tools] master: pass script exit code to the shell (51d9853)
by phatina@fedorahosted.org
15 Jan '13
15 Jan '13
Repository :
http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master >--------------------------------------------------------------- commit 51d9853c6112d2a2aebc7b5bebfdc0d85989acf4 Author: Peter Hatina <phatina(a)redhat.com> Date: Tue Jan 15 14:48:49 2013 +0100 pass script exit code to the shell >--------------------------------------------------------------- cli-tools/lmishell | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-) diff --git a/cli-tools/lmishell b/cli-tools/lmishell index 927d65d..fb7aa0e 100755 --- a/cli-tools/lmishell +++ b/cli-tools/lmishell @@ -260,5 +260,8 @@ if __name__ == "__main__": "connect" : _connect_noninteractive } sys.argv = options.script_args - execfile(options.script_name, locals) + try: + execfile(options.script_name, locals) + except SystemExit, e: + sys.exit(e.code) sys.exit(0)
1
0
0
0
[cura-tools] master: switch to case insensitive rparams dict in LmiReturnValue (bbb2fe1)
by phatina@fedorahosted.org
15 Jan '13
15 Jan '13
Repository :
http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master >--------------------------------------------------------------- commit bbb2fe17d4b4629164dc6987466fa7ea71fa7d30 Author: Peter Hatina <phatina(a)redhat.com> Date: Tue Jan 15 13:37:44 2013 +0100 switch to case insensitive rparams dict in LmiReturnValue >--------------------------------------------------------------- cli-tools/lmi/lmi_client_shell.py | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-) diff --git a/cli-tools/lmi/lmi_client_shell.py b/cli-tools/lmi/lmi_client_shell.py index bd40dfa..26b694d 100644 --- a/cli-tools/lmi/lmi_client_shell.py +++ b/cli-tools/lmi/lmi_client_shell.py @@ -403,7 +403,7 @@ class _LmiInstance(BaseObject): self._method = instance._class._class.methods[method] def __transform_return_values(self, rparams): - lmi_rparams = {} + lmi_rparams = pywbem.NocaseDict() for (key, value) in rparams.iteritems(): if isinstance(value, pywbem.cim_obj.CIMInstance): (lmi_class, _, errorstr) = self._client._get_class(value.classname, @@ -425,6 +425,8 @@ class _LmiInstance(BaseObject): elif isinstance(m, pywbem.cim_obj.CIMInstanceName): result.append(_LmiInstanceName(self._client, m)) lmi_rparams[key] = result + else: + lmi_rparams[key] = value return lmi_rparams def __call__(self, *args, **kwargs): @@ -454,7 +456,7 @@ class _LmiInstance(BaseObject): use_display_hook = True) return_value = self._client._call_method_raw( self._instance, self._method.name, **kwargs) - lmi_rparams = [] + lmi_rparams = pywbem.NocaseDict() if return_value.rparams: lmi_rparams = self.__transform_return_values(return_value.rparams) if not lmi_rparams:
1
0
0
0
← Newer
1
2
Older →
Jump to page:
1
2
Results per page:
10
25
50
100
200