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
October 2012
----- 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
3 participants
35 discussions
Start a n
N
ew thread
[cura-tools] master: introduce history with tab-completion in lmi-shell.py (78f9596)
by phatina@fedoraproject.org
30 Oct '12
30 Oct '12
Repository :
http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master >--------------------------------------------------------------- commit 78f9596114c1555445721e9e459905d982fa655e Author: Peter Hatina <phatina(a)redhat.com> Date: Tue Oct 30 23:38:07 2012 +0100 introduce history with tab-completion in lmi-shell.py >--------------------------------------------------------------- cli-tools/lmi-shell.py | 90 +++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 86 insertions(+), 4 deletions(-) diff --git a/cli-tools/lmi-shell.py b/cli-tools/lmi-shell.py index 9ee8d51..6a6d1bd 100755 --- a/cli-tools/lmi-shell.py +++ b/cli-tools/lmi-shell.py @@ -17,7 +17,75 @@ import os import sys import code +import atexit +import readline +import rlcompleter from lmi.lmi_client_shell import LmiConnection +from lmi.lmi_client_shell import _LmiNamespace +from lmi.lmi_client_shell import _LmiClass +from lmi.lmi_client_shell import _LmiInstance + +class _LmiCompleter(rlcompleter.Completer): + def __init__(self, namespace = None): + rlcompleter.Completer.__init__(self, namespace) + + def __fetchClasses(self, client, expr): + namespace = expr.name.split("/")[-1] + if self.m_cache[client][namespace].classes: + return + result = {} + classes = expr.classes() + for c in classes: + result[c] = _LmiCompleterClassCache() + self.m_cache[client][namespace].classes = result + + def __completeObjectMethods(self, obj, text): + result = filter(lambda m: not m.startswith("_") \ + 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__'): + word = word + "(" + return word + + def complete(self, text, state): + if not text: + return ("\t", None)[state] + + matches = [] + members = text.split(".") + if members[0] in self.namespace: + cmd = ".".join(members[0:-1]) + to_complete = members[-1] + expr = eval(cmd, self.namespace) + if isinstance(expr, LmiConnection): + namespaces = expr.namespaces() + for n in namespaces: + if n.lower().startswith(to_complete.lower()): + matches.append(cmd + "." + n) + return matches[state] + elif isinstance(expr, _LmiNamespace): + for c in expr.classes(): + if c.lower().startswith(to_complete.lower()): + matches.append(cmd + "." + c) + return matches[state] + elif isinstance(expr, _LmiClass): + methods = self.__completeObjectMethods(expr, to_complete) + matches = [cmd + "." + m + "(" for m in methods] + return matches[state] + elif isinstance(expr, _LmiInstance): + for m in expr.methods(): + if m.lower().startswith(to_complete.lower()): + matches.append(cmd + "." + m + "(") + for p in expr.properties(): + if p.lower().startswith(to_complete.lower()): + matches.append(cmd + "." + p) + methods = self.__completeObjectMethods(expr, to_complete) + matches.extend(cmd + "." + m for m in methods) + return matches[state] + return rlcompleter.Completer.complete(self, text, state) class LmiInteractiveShell(code.InteractiveConsole): def __init__(self, prompt, more_prompt, locals = None): @@ -27,9 +95,15 @@ class LmiInteractiveShell(code.InteractiveConsole): locals = {} locals["LmiConnection"] = LmiConnection locals["connect"] = _connect + locals["clear_history"] = self.clearHistory code.InteractiveConsole.__init__(self, locals) + self.m_completer = _LmiCompleter(self.locals) + self.m_history_path = os.path.expanduser("~/.lmi_shell_history") + readline.set_completer(self.m_completer.complete) + readline.parse_and_bind('tab: complete') def interact(self): + self.loadHistory() try: sys.ps1 except AttributeError: @@ -60,13 +134,21 @@ class LmiInteractiveShell(code.InteractiveConsole): self.write("\n") self.resetbuffer() more = 0 + self.saveHistory() + + def loadHistory(self): + if not os.path.exists(self.m_history_path): + return + readline.read_history_file(self.m_history_path) + + def saveHistory(self): + readline.write_history_file(self.m_history_path) + + def clearHistory(self): + readline.clear_history() def _lmi_interact(prompt = "> ", more_prompt = "... "): console = LmiInteractiveShell(prompt, more_prompt) - try: - import readline - except ImportError: - pass console.interact() def _connect(hostname, username = "", password = ""):
1
0
0
0
[cura-tools] master: add _LmiInstance::classname, ::namespace (f339055)
by phatina@fedoraproject.org
30 Oct '12
30 Oct '12
Repository :
http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master >--------------------------------------------------------------- commit f339055bea2caef28a68ab962b89fd52a16c29fa Author: Peter Hatina <phatina(a)redhat.com> Date: Tue Oct 30 20:31:26 2012 +0100 add _LmiInstance::classname, ::namespace >--------------------------------------------------------------- cli-tools/lmi/lmi_client_shell.py | 8 ++++++++ 1 files changed, 8 insertions(+), 0 deletions(-) diff --git a/cli-tools/lmi/lmi_client_shell.py b/cli-tools/lmi/lmi_client_shell.py index 45cd7f4..06cbb6a 100644 --- a/cli-tools/lmi/lmi_client_shell.py +++ b/cli-tools/lmi/lmi_client_shell.py @@ -222,6 +222,14 @@ class _LmiInstance(BaseObject): return None @property + def classname(self): + return self.m_klass.classname + + @property + def namespace(self): + return self.m_klass.namespace + + @property def path(self): return self.m_inst.path
1
0
0
0
[cura-tools] master: add _LmiInstance::properties(), ::methods() (7774623)
by phatina@fedoraproject.org
30 Oct '12
30 Oct '12
Repository :
http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master >--------------------------------------------------------------- commit 77746232433509f526166c9d16f4623908abab3d Author: Peter Hatina <phatina(a)redhat.com> Date: Mon Oct 29 17:16:28 2012 +0100 add _LmiInstance::properties(), ::methods() >--------------------------------------------------------------- cli-tools/lmi/lmi_client_shell.py | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-) diff --git a/cli-tools/lmi/lmi_client_shell.py b/cli-tools/lmi/lmi_client_shell.py index 35162cc..97099a9 100644 --- a/cli-tools/lmi/lmi_client_shell.py +++ b/cli-tools/lmi/lmi_client_shell.py @@ -225,9 +225,15 @@ class _LmiInstance(BaseObject): def path(self): return self.m_inst.path + def properties(self): + return self.m_klass.properties() + def printProperties(self, detailed = False): self.m_klass.printProperties(detailed) + def methods(self): + return self.m_klass.methods() + def printMethods(self, detailed = False): self.m_klass.printMethods(detailed)
1
0
0
0
[cura-tools] master: cache class names in _LmiShellClient::getClassNames() (999665f)
by phatina@fedoraproject.org
30 Oct '12
30 Oct '12
Repository :
http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master >--------------------------------------------------------------- commit 999665f1f881851b9316b34908945a5a4c050e94 Author: Peter Hatina <phatina(a)redhat.com> Date: Tue Oct 30 21:58:27 2012 +0100 cache class names in _LmiShellClient::getClassNames() >--------------------------------------------------------------- cli-tools/lmi/lmi_client_shell.py | 14 +++++++++++--- 1 files changed, 11 insertions(+), 3 deletions(-) diff --git a/cli-tools/lmi/lmi_client_shell.py b/cli-tools/lmi/lmi_client_shell.py index e362355..88e4fd0 100644 --- a/cli-tools/lmi/lmi_client_shell.py +++ b/cli-tools/lmi/lmi_client_shell.py @@ -248,9 +248,17 @@ class _LmiInstance(BaseObject): class _LmiShellClient(LmiBaseClient): def __init__(self, hostname, username = "", password = ""): super(self.__class__, self).__init__(hostname, username, password) - - def getClassNames(self, namespace = None): - return self._getClassNames(namespace, DeepInheritance = True) + self.m_cache_class_names = {} + + 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 getInstances(self, class_name, filter_key = "", **kwargs): (instance_list, _) = self._getInstances(class_name, filter_key, **kwargs)
1
0
0
0
[cura-tools] master: add _LmiClass::properties(), ::methods() (f4ed2c3)
by phatina@fedoraproject.org
30 Oct '12
30 Oct '12
Repository :
http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master >--------------------------------------------------------------- commit f4ed2c361ce4145adf62488b1a98367305de6ac1 Author: Peter Hatina <phatina(a)redhat.com> Date: Mon Oct 29 17:16:11 2012 +0100 add _LmiClass::properties(), ::methods() >--------------------------------------------------------------- cli-tools/lmi/lmi_client_shell.py | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-) diff --git a/cli-tools/lmi/lmi_client_shell.py b/cli-tools/lmi/lmi_client_shell.py index dcdff28..35162cc 100644 --- a/cli-tools/lmi/lmi_client_shell.py +++ b/cli-tools/lmi/lmi_client_shell.py @@ -118,6 +118,9 @@ class _LmiClass(BaseObject): return _LmiErrorHandler("'%s' instance does not exist" % filter_key) return instance_list[0] + def properties(self): + return self.m_klass.properties.keys() + def printProperties(self, detailed = False): for (name, prop) in self.m_klass.properties.iteritems(): if not detailed: @@ -131,6 +134,9 @@ class _LmiClass(BaseObject): except KeyError, e: sys.stderr.write("No such property '%s'\n" % prop_name) + def methods(self): + return self.m_klass.methods.keys() + def printMethods(self, detailed = False): for (name, method) in self.m_klass.methods.iteritems(): if not detailed:
1
0
0
0
[cura-tools] master: add _LmiShell::namespaces() (77bb73e)
by phatina@fedoraproject.org
30 Oct '12
30 Oct '12
Repository :
http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master >--------------------------------------------------------------- commit 77bb73e6c04f13aeb8950070171623c034800143 Author: Peter Hatina <phatina(a)redhat.com> Date: Mon Oct 29 21:00:58 2012 +0100 add _LmiShell::namespaces() >--------------------------------------------------------------- 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 97099a9..45cd7f4 100644 --- a/cli-tools/lmi/lmi_client_shell.py +++ b/cli-tools/lmi/lmi_client_shell.py @@ -260,6 +260,9 @@ class LmiShell(object): def __init__(self, hostname, username = "", password = ""): self.m_shell_client = _LmiShellClient(hostname, username, password) + def namespaces(self): + return ["root", "cimv2", "interop"] + def printNamespaces(self): sys.stdout.write("root\n") sys.stdout.write("cimv2\n")
1
0
0
0
[cura-tools] master: cache classes in _LmiShellClient::getClass() (b2239e2)
by phatina@fedoraproject.org
30 Oct '12
30 Oct '12
Repository :
http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master >--------------------------------------------------------------- commit b2239e2632b98744942143e0bbf48c474b69bc89 Author: Peter Hatina <phatina(a)redhat.com> Date: Tue Oct 30 22:53:00 2012 +0100 cache classes in _LmiShellClient::getClass() >--------------------------------------------------------------- cli-tools/lmi/lmi_client_shell.py | 16 ++++++++++++++-- 1 files changed, 14 insertions(+), 2 deletions(-) diff --git a/cli-tools/lmi/lmi_client_shell.py b/cli-tools/lmi/lmi_client_shell.py index 88e4fd0..9c44dea 100644 --- a/cli-tools/lmi/lmi_client_shell.py +++ b/cli-tools/lmi/lmi_client_shell.py @@ -249,6 +249,11 @@ 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 = "" @@ -266,8 +271,15 @@ class _LmiShellClient(LmiBaseClient): return None return instance_list - def getClass(self, class_name, namespace = None): - return self._getClass(class_name, namespace) + 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 callMethodRaw(self, instance, method, **params): return self._callMethodRaw(instance, method, **params)
1
0
0
0
[cura-tools] master: rename LmiShell to LmiConnection (6001299)
by phatina@fedoraproject.org
30 Oct '12
30 Oct '12
Repository :
http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master >--------------------------------------------------------------- commit 6001299da760e6d1329c0b1322e519dd3f75465c Author: Peter Hatina <phatina(a)redhat.com> Date: Tue Oct 30 21:00:37 2012 +0100 rename LmiShell to LmiConnection >--------------------------------------------------------------- cli-tools/lmi-shell.py | 8 ++++---- cli-tools/lmi/lmi_client_shell.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cli-tools/lmi-shell.py b/cli-tools/lmi-shell.py index 8d7cf68..9ee8d51 100755 --- a/cli-tools/lmi-shell.py +++ b/cli-tools/lmi-shell.py @@ -17,7 +17,7 @@ import os import sys import code -from lmi.lmi_client_shell import LmiShell +from lmi.lmi_client_shell import LmiConnection class LmiInteractiveShell(code.InteractiveConsole): def __init__(self, prompt, more_prompt, locals = None): @@ -25,7 +25,7 @@ class LmiInteractiveShell(code.InteractiveConsole): sys.ps2 = more_prompt if locals == None: locals = {} - locals["LmiShell"] = LmiShell + locals["LmiConnection"] = LmiConnection locals["connect"] = _connect code.InteractiveConsole.__init__(self, locals) @@ -70,13 +70,13 @@ def _lmi_interact(prompt = "> ", more_prompt = "... "): console.interact() def _connect(hostname, username = "", password = ""): - return LmiShell(hostname, username, password) + return LmiConnection(hostname, username, password) if __name__ == "__main__": if len(sys.argv) < 2: _lmi_interact() else: - locals = { "LmiShell" : LmiShell } + locals = { "LmiConnection" : LmiConnection } i = 1 while sys.argv[i].startswith("-"): i += 1 diff --git a/cli-tools/lmi/lmi_client_shell.py b/cli-tools/lmi/lmi_client_shell.py index 06cbb6a..e362355 100644 --- a/cli-tools/lmi/lmi_client_shell.py +++ b/cli-tools/lmi/lmi_client_shell.py @@ -264,7 +264,7 @@ class _LmiShellClient(LmiBaseClient): def callMethodRaw(self, instance, method, **params): return self._callMethodRaw(instance, method, **params) -class LmiShell(object): +class LmiConnection(object): def __init__(self, hostname, username = "", password = ""): self.m_shell_client = _LmiShellClient(hostname, username, password)
1
0
0
0
[cura-tools] master: add _LmiNamespace::classes() (42ec501)
by phatina@fedoraproject.org
30 Oct '12
30 Oct '12
Repository :
http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master >--------------------------------------------------------------- commit 42ec50169d358dc77d0b9b7a6702c50ae189aa7b Author: Peter Hatina <phatina(a)redhat.com> Date: Mon Oct 29 17:15:25 2012 +0100 add _LmiNamespace::classes() >--------------------------------------------------------------- cli-tools/lmi/lmi_client_shell.py | 7 +++++-- 1 files changed, 5 insertions(+), 2 deletions(-) diff --git a/cli-tools/lmi/lmi_client_shell.py b/cli-tools/lmi/lmi_client_shell.py index 356f984..dcdff28 100644 --- a/cli-tools/lmi/lmi_client_shell.py +++ b/cli-tools/lmi/lmi_client_shell.py @@ -65,7 +65,7 @@ class _LmiNamespace(BaseObject): return _LmiErrorHandler("Error: %s" % errorstr) return _LmiClass(self.m_client, self, klass) - def printClasses(self, filter_key = "", exact_match = False): + def classes(self, filter_key = "", exact_match = False): (class_name_list, errorstr) = self.m_client.getClassNames(self.m_name) if not class_name_list: if errorstr: @@ -79,7 +79,10 @@ class _LmiNamespace(BaseObject): else: filter_lambda = lambda n: n.lower() == filter_key.lower() class_name_list = filter(filter_lambda, class_name_list) - for c in class_name_list: + return class_name_list + + def printClasses(self, filter_key = "", exact_match = False): + for c in self.classes(filter_key, exact_match): sys.stdout.write("%s\n" % c) class _LmiClass(BaseObject):
1
0
0
0
[cura-tools] master: introduce BaseObject (5b07ad7)
by phatina@fedoraproject.org
30 Oct '12
30 Oct '12
Repository :
http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master >--------------------------------------------------------------- commit 5b07ad7e0de8ba2213189b810867326ea2571fbc Author: Peter Hatina <phatina(a)redhat.com> Date: Mon Oct 29 17:07:56 2012 +0100 introduce BaseObject >--------------------------------------------------------------- cli-tools/lmi/lmi_client_shell.py | 19 +++++++++++++++---- 1 files changed, 15 insertions(+), 4 deletions(-) diff --git a/cli-tools/lmi/lmi_client_shell.py b/cli-tools/lmi/lmi_client_shell.py index 590a175..356f984 100644 --- a/cli-tools/lmi/lmi_client_shell.py +++ b/cli-tools/lmi/lmi_client_shell.py @@ -40,7 +40,18 @@ class _LmiErrorHandler(object): def __str__(self): return "" -class _LmiNamespace(object): +# Base class for classes, that are used for tab-completion. +# Used due to deprecated methods since python 2.2. +class BaseObject(object): + # deprecated + def __methods__(self): + return [] + + # deprecated + def __members__(self): + return [] + +class _LmiNamespace(BaseObject): def __init__(self, client, name): super(self.__class__, self).__init__() self.m_client = client @@ -71,7 +82,7 @@ class _LmiNamespace(object): for c in class_name_list: sys.stdout.write("%s\n" % c) -class _LmiClass(object): +class _LmiClass(BaseObject): def __init__(self, client, namespace, klass): super(self.__class__, self).__init__() self.m_client = client @@ -138,8 +149,8 @@ class _LmiClass(object): def namespace(self): return self.m_namespace.name -class _LmiInstance(object): - class _LmiInstanceMethod(object): +class _LmiInstance(BaseObject): + class _LmiInstanceMethod(BaseObject): def __init__(self, client, instance, method): super(self.__class__, self).__init__() self.m_client = client
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