Repository :
http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master
---------------------------------------------------------------
commit 46ccdaa14972a1d603e9c2e7e8b607a2be44ee08
Author: Peter Hatina <phatina(a)redhat.com>
Date: Mon Oct 29 09:44:50 2012 +0100
LmiShell, switch to private implementation model
---------------------------------------------------------------
cli-tools/lmi-shell.py | 16 ++++++------
cli-tools/lmi/lmi_client_shell.py | 44 ++++++++++++++++++++----------------
2 files changed, 32 insertions(+), 28 deletions(-)
diff --git a/cli-tools/lmi-shell.py b/cli-tools/lmi-shell.py
index 8016f61..8d7cf68 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 LmiShellClient
+from lmi.lmi_client_shell import LmiShell
class LmiInteractiveShell(code.InteractiveConsole):
def __init__(self, prompt, more_prompt, locals = None):
@@ -25,8 +25,8 @@ class LmiInteractiveShell(code.InteractiveConsole):
sys.ps2 = more_prompt
if locals == None:
locals = {}
- locals["LmiShellClient"] = LmiShellClient
- locals["connect"] = connect
+ locals["LmiShell"] = LmiShell
+ locals["connect"] = _connect
code.InteractiveConsole.__init__(self, locals)
def interact(self):
@@ -61,7 +61,7 @@ class LmiInteractiveShell(code.InteractiveConsole):
self.resetbuffer()
more = 0
-def lmi_interact(prompt = "> ", more_prompt = "... "):
+def _lmi_interact(prompt = "> ", more_prompt = "... "):
console = LmiInteractiveShell(prompt, more_prompt)
try:
import readline
@@ -69,14 +69,14 @@ def lmi_interact(prompt = "> ", more_prompt = "...
"):
pass
console.interact()
-def connect(hostname, username = "", password = ""):
- return LmiShellClient(hostname, username, password)
+def _connect(hostname, username = "", password = ""):
+ return LmiShell(hostname, username, password)
if __name__ == "__main__":
if len(sys.argv) < 2:
- lmi_interact()
+ _lmi_interact()
else:
- locals = { "LmiShellClient" : LmiShellClient }
+ locals = { "LmiShell" : LmiShell }
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 7417aaa..590a175 100644
--- a/cli-tools/lmi/lmi_client_shell.py
+++ b/cli-tools/lmi/lmi_client_shell.py
@@ -19,28 +19,28 @@ import pywbem
import inspect
from lmi_client_base import LmiBaseClient
-class LmiErrorHandler(object):
+class _LmiErrorHandler(object):
def __init__(self, errormsg):
super(self.__class__, self).__init__()
if errormsg:
sys.stderr.write("Error: %s\n" % errormsg)
def __getattr__(self, name):
- return LmiErrorHandler("")
+ return _LmiErrorHandler("")
def __call__(self, *args, **kwargs):
- return LmiErrorHandler("")
+ return _LmiErrorHandler("")
def __iter__(self):
- return LmiErrorHandler("")
+ return _LmiErrorHandler("")
def __getitem__(self, key):
- return LmiErrorHandler("")
+ return _LmiErrorHandler("")
def __str__(self):
return ""
-class LmiNamespace(object):
+class _LmiNamespace(object):
def __init__(self, client, name):
super(self.__class__, self).__init__()
self.m_client = client
@@ -51,8 +51,8 @@ class LmiNamespace(object):
return self.m_name
(klass, errorstr) = self.m_client.getClass(name, self.m_name)
if not klass:
- return LmiErrorHandler("Error: %s" % errorstr)
- return LmiClass(self.m_client, self, klass)
+ return _LmiErrorHandler("Error: %s" % errorstr)
+ return _LmiClass(self.m_client, self, klass)
def printClasses(self, filter_key = "", exact_match = False):
(class_name_list, errorstr) = self.m_client.getClassNames(self.m_name)
@@ -71,7 +71,7 @@ class LmiNamespace(object):
for c in class_name_list:
sys.stdout.write("%s\n" % c)
-class LmiClass(object):
+class _LmiClass(object):
def __init__(self, client, namespace, klass):
super(self.__class__, self).__init__()
self.m_client = client
@@ -92,16 +92,16 @@ class LmiClass(object):
def instances(self, filter_key = "", **kwargs):
instance_list = self.m_client.getInstances(self.m_klass.classname, filter_key,
**kwargs)
if not instance_list:
- return LmiErrorHandler("'%s' instance does not exist" %
filter_key)
+ return _LmiErrorHandler("'%s' instance does not exist" %
filter_key)
result = []
for i in instance_list:
- result.append(LmiInstance(self.m_client, self, i))
+ result.append(_LmiInstance(self.m_client, self, i))
return result
def firstInstance(self, filter_key = "", **kwargs):
instance_list = self.instances(filter_key, **kwargs)
if not instance_list:
- return LmiErrorHandler("'%s' instance does not exist" %
filter_key)
+ return _LmiErrorHandler("'%s' instance does not exist" %
filter_key)
return instance_list[0]
def printProperties(self, detailed = False):
@@ -138,8 +138,8 @@ class LmiClass(object):
def namespace(self):
return self.m_namespace.name
-class LmiInstance(object):
- class LmiInstanceMethod(object):
+class _LmiInstance(object):
+ class _LmiInstanceMethod(object):
def __init__(self, client, instance, method):
super(self.__class__, self).__init__()
self.m_client = client
@@ -178,9 +178,9 @@ class LmiInstance(object):
def __getattr__(self, name):
methods = self.__methods()
if methods and name in methods:
- return LmiInstance.LmiInstanceMethod(self.m_client, self,
self.__method(name))
+ return _LmiInstance._LmiInstanceMethod(self.m_client, self,
self.__method(name))
elif not name in self.m_inst.properties.keys():
- return LmiErrorHandler("'%s' is not valid property of the class
'%s'" % (name, self.m_klass.classname))
+ return _LmiErrorHandler("'%s' is not valid property of the class
'%s'" % (name, self.m_klass.classname))
return self.m_inst.properties[name].value
def __getitem__(self, key):
@@ -211,7 +211,7 @@ class LmiInstance(object):
def printMethods(self, detailed = False):
self.m_klass.printMethods(detailed)
-class LmiShellClient(LmiBaseClient):
+class _LmiShellClient(LmiBaseClient):
def __init__(self, hostname, username = "", password = ""):
super(self.__class__, self).__init__(hostname, username, password)
@@ -230,6 +230,10 @@ class LmiShellClient(LmiBaseClient):
def callMethodRaw(self, instance, method, **params):
return self._callMethodRaw(instance, method, **params)
+class LmiShell(object):
+ def __init__(self, hostname, username = "", password = ""):
+ self.m_shell_client = _LmiShellClient(hostname, username, password)
+
def printNamespaces(self):
sys.stdout.write("root\n")
sys.stdout.write("cimv2\n")
@@ -237,12 +241,12 @@ class LmiShellClient(LmiBaseClient):
@property
def root(self):
- return LmiNamespace(self, "root")
+ return _LmiNamespace(self.m_shell_client, "root")
@property
def cimv2(self):
- return LmiNamespace(self, "root/cimv2")
+ return _LmiNamespace(self.m_shell_client, "root/cimv2")
@property
def interop(self):
- return LmiNamespace(self, "root/interop")
+ return _LmiNamespace(self.m_shell_client, "root/interop")