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
July
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
November 2012
----- 2024 -----
July 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
39 discussions
Start a n
N
ew thread
[cura-tools] master: fix interpreter in non-interactive mode (bb867ae)
by phatina@fedorahosted.org
15 Nov '12
15 Nov '12
Repository :
http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master >--------------------------------------------------------------- commit bb867aef1bb690feeb3691ebf8449e3d477193ac Author: Peter Hatina <phatina(a)redhat.com> Date: Thu Nov 15 11:01:29 2012 +0100 fix interpreter in non-interactive mode >--------------------------------------------------------------- cli-tools/lmi-shell.py | 53 ++++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 47 insertions(+), 6 deletions(-) diff --git a/cli-tools/lmi-shell.py b/cli-tools/lmi-shell.py index 25102e6..46353aa 100755 --- a/cli-tools/lmi-shell.py +++ b/cli-tools/lmi-shell.py @@ -24,6 +24,41 @@ from lmi.lmi_client_shell import _LmiNamespace from lmi.lmi_client_shell import _LmiClass from lmi.lmi_client_shell import _LmiInstance +class _LmiShellOptions(object): + def __init__(self, argv): + self.m_argv = argv + self.m_script_name = "" + self.m_script_argv = [] + self.m_help = False + for a in self.m_argv[1:]: + if not self.m_script_name and (a == "-h" or a == "--help"): + self.m_help = True + return + elif not self.m_script_name and not a.startswith("-"): + self.m_script_name = a + else: + self.m_script_argv.append(a) + + @property + def help(self): + return self.m_help + + @property + def interactive(self): + return not self.m_script_name + + @property + def scriptName(self): + return self.m_script_name + + @property + def scriptArgs(self): + return [self.m_script_name] + self.m_script_argv + + def printUsage(self): + sys.stdout.write("Usage: %s [script] [script-options]\n" % os.path.basename(self.m_argv[0])) + sys.stdout.write("\nOptions:\n -h, --help print this message\n") + class _LmiCompleter(rlcompleter.Completer): def __init__(self, namespace = None): rlcompleter.Completer.__init__(self, namespace) @@ -186,12 +221,18 @@ def _connect(hostname, username = "", password = ""): return LmiConnection(hostname, username, password) if __name__ == "__main__": - if len(sys.argv) < 2: + options = _LmiShellOptions(sys.argv) + if options.help: + options.printUsage() + sys.exit(0) + + if options.interactive: _lmi_interact() else: - locals = { "LmiConnection" : LmiConnection } - i = 1 - while sys.argv[i].startswith("-"): - i += 1 - execfile(sys.argv[i]) in locals + locals = { + "LmiConnection" : LmiConnection, + "connect" : _connect + } + sys.argv = options.scriptArgs + execfile(options.scriptName, locals) sys.exit(0)
1
0
0
0
[cura-tools] master: drop unused modules in lmi-shell.py (03c9d57)
by phatina@fedorahosted.org
15 Nov '12
15 Nov '12
Repository :
http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master >--------------------------------------------------------------- commit 03c9d57c09147d7e8f1b2a3431722389bef974a1 Author: Peter Hatina <phatina(a)redhat.com> Date: Thu Nov 15 09:25:43 2012 +0100 drop unused modules in lmi-shell.py >--------------------------------------------------------------- cli-tools/lmi-shell.py | 1 - 1 files changed, 0 insertions(+), 1 deletions(-) diff --git a/cli-tools/lmi-shell.py b/cli-tools/lmi-shell.py index e63e15c..25102e6 100755 --- a/cli-tools/lmi-shell.py +++ b/cli-tools/lmi-shell.py @@ -17,7 +17,6 @@ import os import sys import code -import atexit import readline import rlcompleter from lmi.lmi_client_shell import LmiConnection
1
0
0
0
[cura-tools] master: make connect interactive (a398688)
by phatina@fedorahosted.org
15 Nov '12
15 Nov '12
Repository :
http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master >--------------------------------------------------------------- commit a398688b11953ff235f0c20f40f026b6ce7a137e Author: Peter Hatina <phatina(a)redhat.com> Date: Tue Nov 13 11:03:20 2012 +0100 make connect interactive >--------------------------------------------------------------- cli-tools/lmi-shell.py | 26 ++++++++++++++++++++++++++ 1 files changed, 26 insertions(+), 0 deletions(-) diff --git a/cli-tools/lmi-shell.py b/cli-tools/lmi-shell.py index ac201f1..e63e15c 100755 --- a/cli-tools/lmi-shell.py +++ b/cli-tools/lmi-shell.py @@ -158,6 +158,32 @@ def _lmi_interact(prompt = "> ", more_prompt = "... "): console.interact() def _connect(hostname, username = "", password = ""): + if not username: + while True: + try: + username = raw_input("username: ") + if username: + break + except EOFError, e: + sys.stdout.write("\n") + continue + except KeyboardInterrupt, e: + sys.stdout.write("\n") + return None + readline.remove_history_item(readline.get_current_history_length() - 1) + if not password: + try: + os.system("stty -echo") + password = raw_input("password: ") + os.system("stty echo") + except EOFError, e: + password = "" + except KeyboardInterrupt, e: + os.system("stty echo") + sys.stdout.write("\n") + return None + sys.stdout.write("\n") + readline.remove_history_item(readline.get_current_history_length() - 1) return LmiConnection(hostname, username, password) if __name__ == "__main__":
1
0
0
0
[cura-tools] master: introduce _LmiClass::doc(), _LmiInstance::doc() (676cea6)
by phatina@fedorahosted.org
15 Nov '12
15 Nov '12
Repository :
http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master >--------------------------------------------------------------- commit 676cea6b87275d9042a1ac70c54b0434ce274f52 Author: Peter Hatina <phatina(a)redhat.com> Date: Tue Nov 13 10:37:57 2012 +0100 introduce _LmiClass::doc(), _LmiInstance::doc() >--------------------------------------------------------------- cli-tools/lmi/lmi_client_shell.py | 220 +++++++++++++++++++++++++++++++------ 1 files changed, 184 insertions(+), 36 deletions(-) diff --git a/cli-tools/lmi/lmi_client_shell.py b/cli-tools/lmi/lmi_client_shell.py index 3e43017..e785802 100644 --- a/cli-tools/lmi/lmi_client_shell.py +++ b/cli-tools/lmi/lmi_client_shell.py @@ -13,9 +13,14 @@ # 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 os import new import sys import pywbem +import textwrap +import tempfile +import subprocess +from xml.dom.minicompat import NodeList from lmi_client_base import LmiBaseClient class _LmiErrorHandler(object): @@ -39,6 +44,172 @@ class _LmiErrorHandler(object): def __str__(self): return "" +class _LmiTextFormatter(object): + def __init__(self, text): + self.m_text = text + + def format(self, indent = 0, sub_indent = 0, width = 80, fd = sys.stdout.fileno(), **kwargs): + if indent > width: + return # NOTE: this is wrong! + wrapper = textwrap.TextWrapper() + wrapper.width = width - indent + wrapper.subsequent_indent = " " * sub_indent + for l in wrapper.wrap(self.m_text): + os.write(fd, "%s%s\n" % (" " * indent, l)) + if "separator" in kwargs and kwargs["separator"]: + os.write(fd, "\n") + +class _LmiXmlFormatter(object): + def __init__(self, xml): + self.m_xml = xml + self.m_width = int(os.popen('stty size', 'r').read().split()[1]) + if not self.m_width: + self.m_width = 80 + + def __formatClassPropertyContent(self, node, indent = 0, sub_indent = 0, width = 80, fd = sys.stdout.fileno()): + children = node.childNodes + children_len = len(children) + for (i, n) in enumerate(children): + if isinstance(n, pywbem.cim_xml.QUALIFIER): + self.__formatQualifier(n, indent, sub_indent, width, fd) + elif isinstance(n, pywbem.cim_xml.PROPERTY): + self.__formatClassProperty(n, indent, sub_indent, width, fd) + elif isinstance(n, pywbem.cim_xml.PROPERTY_ARRAY): + self.__formatClassPropertyArray(n, indent, sub_indent, width, fd) + elif isinstance(n, pywbem.cim_xml.METHOD): + self.__formatMethod(n, indent, sub_indent, width, fd) + elif isinstance(n, pywbem.cim_xml.VALUE): + # NOTE: we skip default value for the class + pass + + def __formatQualifier(self, node, indent = 0, sub_indent = 0, width = 80, fd = sys.stdout.fileno()): + is_array = isinstance(node.firstChild, pywbem.cim_xml.VALUE_ARRAY) + val = "[qualifier] %s%s %s" % (node.getAttribute("TYPE"), " []" if is_array else "", + node.getAttribute("NAME")) + values = node.childNodes + if values and isinstance(values[0], pywbem.cim_xml.VALUE_ARRAY): + val += ": { " + ", ".join(["'" + v.firstChild.nodeValue + "'" for v in values[0].childNodes]) + " }\n" + else: + val += ": '%s'\n" % values[0].firstChild.nodeValue + _LmiTextFormatter(val).format(indent, sub_indent + 4, width, fd, separator = True) + + def __formatClassProperty(self, node, indent = 0, sub_indent = 0, width = 80, fd = sys.stdout.fileno()): + val = "[property] %s %s" % (node.getAttribute("TYPE"), node.getAttribute("NAME")) + _LmiTextFormatter(val).format(indent, sub_indent + 4, width, fd, separator = True) + self.__formatClassPropertyContent(node, indent + 4, sub_indent, width, fd) + + def __formatClassPropertyArray(self, node, indent = 0, sub_indent = 0, width = 80, fd = sys.stdout.fileno()): + val = "[property array] %s [] %s" % (node.getAttribute("TYPE"), node.getAttribute("TYPE")) + _LmiTextFormatter(val).format(indent, sub_indent + 4, width, fd, separator = True) + self.__formatClassPropertyContent(node, indent + 4, sub_indent, width, fd) + + def __formatClassPropertyReference(self, node, indent = 0, sub_indent = 0, width = 80, fd = sys.stdout.fileno()): + val = "[property ref] %s %s" % (node.getAttribute("REFERENCECLASS"), node.getAttribute("NAME")) + _LmiTextFormatter(val).format(indent, sub_indent + 4, width, fd, separator = True) + self.__formatClassPropertyContent(node, indent + 4, sub_indent, width, fd) + + def __formatInstanceProperty(self, node, indent = 0, sub_indent = 0, width = 80, fd = sys.stdout.fileno()): + val = node.firstChild + prop = "[property] %s %s%s" % (node.getAttribute("TYPE"), node.getAttribute("NAME"), + " = '%s'" % val.firstChild.nodeValue if val else "") + _LmiTextFormatter(prop).format(indent, sub_indent + 4, width, fd, separator = True) + + def __formatInstancePropertyArray(self, node, indent = 0, sub_indent = 0, width = 80, fd = sys.stdout.fileno()): + prop = "[property array] %s [] %s" % (node.getAttribute("TYPE"), node.getAttribute("NAME")) + val = node.firstChild + if val: + prop += " = { " + ", ".join(["'" + v.firstChild.nodeValue + "'" for v in val.childNodes]) + " }" + _LmiTextFormatter(prop).format(indent, sub_indent + 4, width, fd, separator = True) + + def __formatInstancePropertyReference(self, node, indent = 0, sub_indent = 0, width = 80, fd = sys.stdout.fileno()): + val = "[property ref] %s %s" % (node.getAttribute("REFERENCECLASS"), node.getAttribute("NAME")) + _LmiTextFormatter(val).format(indent, sub_indent + 4, width, fd, separator = True) + + def __formatMethod(self, node, indent = 0, sub_indent = 0, width = 80, fd = sys.stdout.fileno()): + qualifiers = [x for x in node.childNodes if isinstance(x, pywbem.cim_xml.QUALIFIER)] + parameters = [x for x in node.childNodes if isinstance(x, pywbem.cim_xml.PARAMETER)] + parameters_arr = [x for x in node.childNodes if isinstance(x, pywbem.cim_xml.PARAMETER_ARRAY)] + parameters_ref = [x for x in node.childNodes if isinstance(x, pywbem.cim_xml.PARAMETER_REFERENCE)] + parameters_ref_arr = [x for x in node.childNodes if isinstance(x, pywbem.cim_xml.PARAMETER_REFARRAY)] + has_args = parameters != [] or parameters_arr != [] or parameters_ref != [] or parameters_ref_arr != [] + val = "[method] %s %s%s" % (node.getAttribute("TYPE"), node.getAttribute("NAME"), "(...)" if has_args else "()") + _LmiTextFormatter(val).format(indent, sub_indent, width, fd, separator = True) + for q in qualifiers: + self.__formatQualifier(q, indent + 4, sub_indent + 4, width, fd) + for p in parameters: + val = "[param] %s %s" % (p.getAttribute("TYPE"), p.getAttribute("NAME")) + _LmiTextFormatter(val).format(indent + 4, sub_indent + 4, width, fd, separator = True) + for p in parameters_arr: + val = "[param array] %s (ref) %s" % (p.getAttribute("TYPE"), p.getAttribute("NAME")) + _LmiTextFormatter(val).format(indent + 4, sub_indent + 4, width, fd, separator = True) + for p in parameters_ref: + val = "[param ref] %s (ref) %s" % (p.getAttribute("REFERENCECLASS"), p.getAttribute("NAME")) + _LmiTextFormatter(val).format(indent + 4, sub_indent + 4, width, fd, separator = True) + for p in parameters_ref_arr: + val = "[param ref array] %s (ref) %s" % (p.getAttribute("REFERENCECLASS"), p.getAttribute("NAME")) + _LmiTextFormatter(val).format(indent + 4, sub_indent + 4, width, fd, separator = True) + + def __formatClass(self, node, indent = 0, sub_indent = 0, width = 80, fd = sys.stdout.fileno()): + _LmiTextFormatter("Class: %s" % node.getAttribute("NAME")).format(indent, sub_indent, width, fd) + _LmiTextFormatter("SuperClass: %s" % node.getAttribute("SUPERCLASS")).format(indent + 4, sub_indent, width, fd) + for n in node.childNodes: + if isinstance(n, pywbem.cim_xml.QUALIFIER): + self.__formatQualifier(n, indent + 4, sub_indent, width, fd) + elif isinstance(n, pywbem.cim_xml.PROPERTY): + self.__formatClassProperty(n, indent + 4, sub_indent, width, fd) + elif isinstance(n, pywbem.cim_xml.PROPERTY_ARRAY): + self.__formatClassPropertyArray(n, indent + 4, sub_indent, width, fd) + elif isinstance(n, pywbem.cim_xml.PROPERTY_REFERENCE): + self.__formatClassPropertyReference(n, indent + 4, sub_indent, width, fd) + elif isinstance(n, pywbem.cim_xml.METHOD): + self.__formatMethod(n, indent + 4, sub_indent, width, fd) + + def __formatInstance(self, node, indent = 0, sub_indent = 0, width = 80, fd = sys.stdout.fileno()): + instance = node.firstChild.nextSibling + _LmiTextFormatter("Instance of %s" % instance.getAttribute("CLASSNAME")).format(indent, sub_indent, width, fd) + for n in instance.childNodes: + if isinstance(n, pywbem.cim_xml.PROPERTY): + self.__formatInstanceProperty(n, indent + 4, sub_indent, width, fd) + elif isinstance(n, pywbem.cim_xml.PROPERTY_ARRAY): + self.__formatInstancePropertyArray(n, indent + 4, sub_indent, width, fd) + elif isinstance(n, pywbem.cim_xml.PROPERTY_REFERENCE): + self.__formatInstancePropertyReference(n, indent + 4, sub_indent, width, fd) + + @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 __getPager(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, fd = sys.stdout.fileno()): + if isinstance(self.m_xml, pywbem.cim_xml.CLASS): + self.__formatClass(self.m_xml, indent, sub_indent, width, fd) + elif isinstance(self.m_xml, pywbem.cim_xml.VALUE_NAMEDINSTANCE): + self.__formatInstance(self.m_xml, indent, sub_indent, width, fd) + + def fancyFormat(self): + tmpfile = tempfile.mkstemp() + self.format(0, 0, self.m_width, tmpfile[0]) + os.close(tmpfile[0]) + subprocess.call([self.__getPager(), tmpfile[1]]) + os.remove(tmpfile[1]) + # Base class for classes, that are used for tab-completion. # Used due to deprecated methods since python 2.2. class BaseObject(object): @@ -94,16 +265,8 @@ class _LmiClass(BaseObject): self.m_namespace = namespace self.m_klass = klass - def __printMethod(self, method): - sys.stdout.write("Method name: %s\n" % method.name) - sys.stdout.write(" Return type: %s\n" % method.return_type) - for (name, param) in method.parameters.iteritems(): - sys.stdout.write(" Parameter: %s: %s\n" % (name, param.type)) - - def __printProperty(self, prop): - sys.stdout.write("Property name: %s\n" % prop.name) - sys.stdout.write(" Type: %s\n" % prop.type) - sys.stdout.write(" Is Array: %s\n" % str(prop.is_array)) + def doc(self): + _LmiXmlFormatter(self.m_klass.tocimxml()).fancyFormat() def instances(self, filter_key = "", **kwargs): instance_list = self.m_client.getInstances(self.m_klass.classname, filter_key, **kwargs) @@ -123,34 +286,16 @@ class _LmiClass(BaseObject): def properties(self): return self.m_klass.properties.keys() - def printProperties(self, detailed = False): + def printProperties(self): for (name, prop) in self.m_klass.properties.iteritems(): - if not detailed: - sys.stdout.write("%s\n" % name) - else: - self.__printProperty(prop) - - def printProperty(self, prop_name): - try: - self.__printProperty(self.m_klass.properties[prop_name]) - except KeyError, e: - sys.stderr.write("No such property '%s'\n" % prop_name) + sys.stdout.write("%s\n" % name) def methods(self): return self.m_klass.methods.keys() - def printMethods(self, detailed = False): + def printMethods(self): for (name, method) in self.m_klass.methods.iteritems(): - if not detailed: - sys.stdout.write("%s\n" % name) - else: - self.__printMethod(method) - - def printMethod(self, name): - try: - self.__printMethod(self.m_klass.methods[name]) - except KeyError, e: - sys.stderr.write("No such method '%s' exists\n" % name) + sys.stdout.write("%s\n" % name) @property def classname(self): @@ -235,17 +380,20 @@ class _LmiInstance(BaseObject): def path(self): return self.m_inst.path + def doc(self): + _LmiXmlFormatter(self.m_inst.tocimxml()).fancyFormat() + def properties(self): return self.m_klass.properties() - def printProperties(self, detailed = False): - self.m_klass.printProperties(detailed) + def printProperties(self): + self.m_klass.printProperties() def methods(self): return self.m_klass.methods() - def printMethods(self, detailed = False): - self.m_klass.printMethods(detailed) + def printMethods(self): + self.m_klass.printMethods() class _LmiShellClient(LmiBaseClient): def __init__(self, hostname, username = "", password = ""):
1
0
0
0
[cura-tools] master: fix missing methods in _LmiCompleter::complete() for _LmiNamespace (f2eb649)
by phatina@fedorahosted.org
15 Nov '12
15 Nov '12
Repository :
http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master >--------------------------------------------------------------- commit f2eb6494d3c324d989add4da8cf20481c9e98a83 Author: Peter Hatina <phatina(a)redhat.com> Date: Thu Nov 8 15:22:29 2012 +0100 fix missing methods in _LmiCompleter::complete() for _LmiNamespace >--------------------------------------------------------------- cli-tools/lmi-shell.py | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-) diff --git a/cli-tools/lmi-shell.py b/cli-tools/lmi-shell.py index 171f869..ac201f1 100755 --- a/cli-tools/lmi-shell.py +++ b/cli-tools/lmi-shell.py @@ -74,6 +74,8 @@ class _LmiCompleter(rlcompleter.Completer): for c in expr.classes(): if c.lower().startswith(to_complete.lower()): self.m_last_complete.append(cmd + "." + c) + methods = self.__completeObjectMethods(expr, to_complete) + self.m_last_complete.extend(cmd + "." + m + "(" for m in methods) return self.m_last_complete[state] elif isinstance(expr, _LmiClass): methods = self.__completeObjectMethods(expr, to_complete)
1
0
0
0
[cura-tools] master: inspect module no more needed (ec92d29)
by phatina@fedorahosted.org
01 Nov '12
01 Nov '12
Repository :
http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master >--------------------------------------------------------------- commit ec92d2955116d5e19904650964913cf8f1bbec41 Author: Peter Hatina <phatina(a)redhat.com> Date: Thu Nov 1 16:00:02 2012 +0100 inspect module no more needed >--------------------------------------------------------------- cli-tools/lmi/lmi_client_shell.py | 1 - 1 files changed, 0 insertions(+), 1 deletions(-) diff --git a/cli-tools/lmi/lmi_client_shell.py b/cli-tools/lmi/lmi_client_shell.py index 4c67693..3e43017 100644 --- a/cli-tools/lmi/lmi_client_shell.py +++ b/cli-tools/lmi/lmi_client_shell.py @@ -16,7 +16,6 @@ import new import sys import pywbem -import inspect from lmi_client_base import LmiBaseClient class _LmiErrorHandler(object):
1
0
0
0
[cura-tools] master: fix callable suffix in _LmiInstance methods (f47bc59)
by phatina@fedorahosted.org
01 Nov '12
01 Nov '12
Repository :
http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master >--------------------------------------------------------------- commit f47bc59abaab06da8d74dcc962af533f5dc48170 Author: Peter Hatina <phatina(a)redhat.com> Date: Thu Nov 1 14:43:10 2012 +0100 fix callable suffix in _LmiInstance methods >--------------------------------------------------------------- cli-tools/lmi-shell.py | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/cli-tools/lmi-shell.py b/cli-tools/lmi-shell.py index dcafb98..171f869 100755 --- a/cli-tools/lmi-shell.py +++ b/cli-tools/lmi-shell.py @@ -87,7 +87,7 @@ class _LmiCompleter(rlcompleter.Completer): if p.lower().startswith(to_complete.lower()): self.m_last_complete.append(cmd + "." + p) methods = self.__completeObjectMethods(expr, to_complete) - self.m_last_complete.extend(cmd + "." + m for m in methods) + self.m_last_complete.extend(cmd + "." + m + "(" for m in methods) return self.m_last_complete[state] return rlcompleter.Completer.complete(self, text, state)
1
0
0
0
[cura-tools] master: move caching from _LmiShellClient to tmp caching in _LmiCompleter (5f86873)
by phatina@fedorahosted.org
01 Nov '12
01 Nov '12
Repository :
http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master >--------------------------------------------------------------- commit 5f868738eea900beb52914c0244f2eb67f2390e0 Author: Peter Hatina <phatina(a)redhat.com> Date: Thu Nov 1 13:33:21 2012 +0100 move caching from _LmiShellClient to tmp caching in _LmiCompleter >--------------------------------------------------------------- cli-tools/lmi-shell.py | 26 ++++++++++++++------------ cli-tools/lmi/lmi_client_shell.py | 30 +++++------------------------- 2 files changed, 19 insertions(+), 37 deletions(-) diff --git a/cli-tools/lmi-shell.py b/cli-tools/lmi-shell.py index e8c5ced..dcafb98 100755 --- a/cli-tools/lmi-shell.py +++ b/cli-tools/lmi-shell.py @@ -28,6 +28,7 @@ from lmi.lmi_client_shell import _LmiInstance class _LmiCompleter(rlcompleter.Completer): def __init__(self, namespace = None): rlcompleter.Completer.__init__(self, namespace) + self.m_last_complete = [] def __fetchClasses(self, client, expr): namespace = expr.name.split("/")[-1] @@ -55,8 +56,9 @@ class _LmiCompleter(rlcompleter.Completer): def complete(self, text, state): if not text: return ("\t", None)[state] - - matches = [] + if state > 0: + return self.m_last_complete[state] + self.m_last_complete = [] members = text.split(".") if members[0] in self.namespace: cmd = ".".join(members[0:-1]) @@ -66,27 +68,27 @@ class _LmiCompleter(rlcompleter.Completer): namespaces = expr.namespaces() for n in namespaces: if n.lower().startswith(to_complete.lower()): - matches.append(cmd + "." + n) - return matches[state] + self.m_last_complete.append(cmd + "." + n) + return self.m_last_complete[state] elif isinstance(expr, _LmiNamespace): for c in expr.classes(): if c.lower().startswith(to_complete.lower()): - matches.append(cmd + "." + c) - return matches[state] + self.m_last_complete.append(cmd + "." + c) + return self.m_last_complete[state] elif isinstance(expr, _LmiClass): methods = self.__completeObjectMethods(expr, to_complete) - matches = [cmd + "." + m + "(" for m in methods] - return matches[state] + self.m_last_complete= [cmd + "." + m + "(" for m in methods] + return self.m_last_complete[state] elif isinstance(expr, _LmiInstance): for m in expr.methods(): if m.lower().startswith(to_complete.lower()): - matches.append(cmd + "." + m + "(") + self.m_last_complete.append(cmd + "." + m + "(") for p in expr.properties(): if p.lower().startswith(to_complete.lower()): - matches.append(cmd + "." + p) + self.m_last_complete.append(cmd + "." + p) methods = self.__completeObjectMethods(expr, to_complete) - matches.extend(cmd + "." + m for m in methods) - return matches[state] + self.m_last_complete.extend(cmd + "." + m for m in methods) + return self.m_last_complete[state] return rlcompleter.Completer.complete(self, text, state) class LmiInteractiveShell(code.InteractiveConsole): diff --git a/cli-tools/lmi/lmi_client_shell.py b/cli-tools/lmi/lmi_client_shell.py index f40f3ea..4c67693 100644 --- a/cli-tools/lmi/lmi_client_shell.py +++ b/cli-tools/lmi/lmi_client_shell.py @@ -251,22 +251,9 @@ class _LmiInstance(BaseObject): class _LmiShellClient(LmiBaseClient): def __init__(self, hostname, username = "", password = ""): super(self.__class__, self).__init__(hostname, username, password) - self.m_cache_class_names = {} - self.m_cache_classes = { - "root" : {}, - "root/cimv2" : {}, - "root/interop" : {} - } - - def getClassNames(self, namespace = None, use_cache = True): - errorstr = "" - ns = namespace if namespace else "none" - if ns not in self.m_cache_class_names or not use_cache: - (class_names, errorstr) = self._getClassNames(namespace, DeepInheritance = True) - if not class_names: - return (None, errorstr) - self.m_cache_class_names[ns] = class_names - return (self.m_cache_class_names[ns], errorstr) + + def getClassNames(self, namespace = None): + return self._getClassNames(namespace, DeepInheritance = True) def getInstances(self, class_name, filter_key = "", **kwargs): (instance_list, _) = self._getInstances(class_name, filter_key, **kwargs) @@ -274,15 +261,8 @@ class _LmiShellClient(LmiBaseClient): return None return instance_list - def getClass(self, class_name, namespace = None, use_cache = True): - errorstr = "" - ns = namespace if namespace else "none" - if class_name not in self.m_cache_classes[ns] or not use_cache: - (klass, errorstr) = self._getClass(class_name, namespace) - if not klass: - return (None, errorstr) - self.m_cache_classes[ns][class_name] = klass - return (self.m_cache_classes[ns][class_name], errorstr) + def getClass(self, class_name, namespace = None): + return self._getClass(class_name, namespace) def callMethodRaw(self, instance, method, **params): return self._callMethodRaw(instance, method, **params)
1
0
0
0
[cura-tools] master: Lmi objects has to be callable due to tab-completion (bd329ce)
by phatina@fedorahosted.org
01 Nov '12
01 Nov '12
Repository :
http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master >--------------------------------------------------------------- commit bd329ce4302b591db8d71c00695878d9d7de562c Author: Peter Hatina <phatina(a)redhat.com> Date: Thu Nov 1 11:19:13 2012 +0100 Lmi objects has to be callable due to tab-completion >--------------------------------------------------------------- cli-tools/lmi-shell.py | 4 +++- cli-tools/lmi/lmi_client_shell.py | 3 +++ 2 files changed, 6 insertions(+), 1 deletions(-) diff --git a/cli-tools/lmi-shell.py b/cli-tools/lmi-shell.py index 6a6d1bd..e8c5ced 100755 --- a/cli-tools/lmi-shell.py +++ b/cli-tools/lmi-shell.py @@ -41,12 +41,14 @@ class _LmiCompleter(rlcompleter.Completer): def __completeObjectMethods(self, obj, text): result = filter(lambda m: not m.startswith("_") \ + and not m.startswith("m_") \ and callable(getattr(obj, m)) \ and m.lower().startswith(text.lower()), dir(obj)) return result def _callable_postfix(self, val, word): - if hasattr(val, '__call__'): + if hasattr(val, '__call__') \ + and not isinstance(val, (_LmiNamespace, _LmiClass, _LmiInstance)): word = word + "(" return word diff --git a/cli-tools/lmi/lmi_client_shell.py b/cli-tools/lmi/lmi_client_shell.py index 9c44dea..f40f3ea 100644 --- a/cli-tools/lmi/lmi_client_shell.py +++ b/cli-tools/lmi/lmi_client_shell.py @@ -51,6 +51,9 @@ class BaseObject(object): def __members__(self): return [] + def __call__(self): + pass + class _LmiNamespace(BaseObject): def __init__(self, client, name): super(self.__class__, self).__init__()
1
0
0
0
← Newer
1
2
3
4
Older →
Jump to page:
1
2
3
4
Results per page:
10
25
50
100
200