[cura-tools] master: fix LmiIpClient when setting an address (791a3d3)
by phatina@fedorahosted.org
Repository : http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master
>---------------------------------------------------------------
commit 791a3d3216997094850228582f8b1651735f0e59
Author: Peter Hatina <phatina(a)redhat.com>
Date: Thu Nov 29 17:42:06 2012 +0100
fix LmiIpClient when setting an address
>---------------------------------------------------------------
cli-tools/lmi/lmi_client_ip.py | 8 +++++++-
1 files changed, 7 insertions(+), 1 deletions(-)
diff --git a/cli-tools/lmi/lmi_client_ip.py b/cli-tools/lmi/lmi_client_ip.py
index b7ea669..7dc4df8 100644
--- a/cli-tools/lmi/lmi_client_ip.py
+++ b/cli-tools/lmi/lmi_client_ip.py
@@ -80,6 +80,8 @@ class LmiIpClient(LmiBaseClient):
(device_inst, errorstr) = self.__ip_get_ethernet_port_instance(device)
if not device_inst:
return (False, {}, errorstr)
+ if type(device_inst) is list:
+ device_inst = device_inst[0]
prot_type = self.__ip_get_address_type(address)
args = {
"Caption" : "static-" + device,
@@ -111,14 +113,18 @@ class LmiIpClient(LmiBaseClient):
(configuration_inst, errorstr) = self._get_instances(LmiIpClient.IP_CONFIGURATION_SERVICE_CLASS_NAME)
if not configuration_inst:
return (False, {}, errorstr)
+ if type(configuration_inst) is list:
+ configuration_inst = configuration_inst[0]
return self._call_method(configuration_inst, "CreateStaticSetting", **args)
def __ip_apply_static_setting(self, device, setting_inst):
(configuration_inst, errorstr) = self._get_instances(LmiIpClient.IP_CONFIGURATION_SERVICE_CLASS_NAME)
if not configuration_inst:
return (False, errorstr)
+ if type(configuration_inst) is list:
+ configuration_inst = configuration_inst[0]
(device_inst, errorstr) = self.__ip_get_ip_protocol_endpoint_instances(device)
- if type(device_inst) == list:
+ if type(device_inst) is list:
device_inst = device_inst[0]
if not device_inst:
return (False, errorstr)
11 years, 5 months
[cura-tools] master: fix namespace hierarchy (10698c5)
by phatina@fedorahosted.org
Repository : http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master
>---------------------------------------------------------------
commit 10698c5f1c469395449b55d5a67bd0057876abf0
Author: Peter Hatina <phatina(a)redhat.com>
Date: Thu Nov 29 15:54:38 2012 +0100
fix namespace hierarchy
>---------------------------------------------------------------
cli-tools/lmi-shell.py | 3 +-
cli-tools/lmi/lmi_client_shell.py | 43 ++++++++++++++++++++++++++----------
2 files changed, 33 insertions(+), 13 deletions(-)
diff --git a/cli-tools/lmi-shell.py b/cli-tools/lmi-shell.py
index 0b33d5e..122bc34 100755
--- a/cli-tools/lmi-shell.py
+++ b/cli-tools/lmi-shell.py
@@ -23,6 +23,7 @@ import __builtin__
from lmi.lmi_client_base import LmiReturnValue
from lmi.lmi_client_shell import LmiConnection
from lmi.lmi_client_shell import _LmiNamespace
+from lmi.lmi_client_shell import _LmiNamespaceRoot
from lmi.lmi_client_shell import _LmiClass
from lmi.lmi_client_shell import _LmiInstance
@@ -116,7 +117,7 @@ class _LmiCompleter(rlcompleter.Completer):
expr = eval(cmd, self.namespace)
methods = self.__complete_object_methods(expr, to_complete)
properties = self.__complete_object_properties(expr, to_complete)
- if isinstance(expr, LmiConnection):
+ if isinstance(expr, (LmiConnection, _LmiNamespaceRoot)):
namespaces = expr.namespaces()
for n in namespaces:
if n.lower().startswith(to_complete.lower()):
diff --git a/cli-tools/lmi/lmi_client_shell.py b/cli-tools/lmi/lmi_client_shell.py
index af4d1cd..6b88d49 100644
--- a/cli-tools/lmi/lmi_client_shell.py
+++ b/cli-tools/lmi/lmi_client_shell.py
@@ -260,6 +260,35 @@ class _LmiNamespace(BaseObject):
for c in self.classes(filter_key, exact_match):
sys.stdout.write("%s\n" % c)
+class _LmiNamespaceRoot(_LmiNamespace):
+ def __init__(self, client):
+ super(self.__class__, self).__init__(client, "root")
+
+ @property
+ def cimv2(self):
+ return _LmiNamespace(self._client, "root/cimv2")
+
+ @property
+ def interop(self):
+ return _LmiNamespace(self._client, "root/interop")
+
+ @property
+ def PG_InterOp(self):
+ return _LmiNamespace(self._client, "root/PG_InterOp")
+
+ @property
+ def PG_Internal(self):
+ return _LmiNamespace(self._client, "root/PG_Internal")
+
+ def namespaces(self):
+ return ["cimv2", "interop", "PG_InterOp", "PG_Internal"]
+
+ def print_namespaces(self):
+ sys.stdout.write("cimv2\n")
+ sys.stdout.write("interop\n")
+ sys.stdout.write("PG_InterOp")
+ sys.stdout.write("PG_Internal")
+
class _LmiClass(BaseObject):
def __init__(self, client, namespace, klass):
super(self.__class__, self).__init__()
@@ -530,21 +559,11 @@ class LmiConnection(object):
self._shell_client = _LmiShellClient(hostname, username, password, interactive)
def namespaces(self):
- return ["root", "cimv2", "interop"]
+ return ["root"]
def print_namespaces(self):
sys.stdout.write("root\n")
- sys.stdout.write("cimv2\n")
- sys.stdout.write("interop\n")
@property
def root(self):
- return _LmiNamespace(self._shell_client, "root")
-
- @property
- def cimv2(self):
- return _LmiNamespace(self._shell_client, "root/cimv2")
-
- @property
- def interop(self):
- return _LmiNamespace(self._shell_client, "root/interop")
+ return _LmiNamespaceRoot(self._shell_client)
11 years, 5 months
[cura-tools] master: drop unnecessary calls for super ctors (3259313)
by phatina@fedorahosted.org
Repository : http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master
>---------------------------------------------------------------
commit 32593133a4e1255ef9abaff33660336817ed1b23
Author: Peter Hatina <phatina(a)redhat.com>
Date: Thu Nov 29 15:43:35 2012 +0100
drop unnecessary calls for super ctors
>---------------------------------------------------------------
cli-tools/lmi/lmi_client_shell.py | 2 --
1 files changed, 0 insertions(+), 2 deletions(-)
diff --git a/cli-tools/lmi/lmi_client_shell.py b/cli-tools/lmi/lmi_client_shell.py
index 6059796..af4d1cd 100644
--- a/cli-tools/lmi/lmi_client_shell.py
+++ b/cli-tools/lmi/lmi_client_shell.py
@@ -26,7 +26,6 @@ from lmi_client_base import LmiReturnValue
class _LmiErrorHandler(object):
def __init__(self, errormsg):
- super(self.__class__, self).__init__()
if errormsg:
sys.stderr.write("Error: %s\n" % errormsg)
@@ -231,7 +230,6 @@ class BaseObject(object):
class _LmiNamespace(BaseObject):
def __init__(self, client, name):
- super(self.__class__, self).__init__()
self._client = client
self._name = name
11 years, 5 months
[cura-tools] master: optimize methods and properties completion in _LmiCompleter (1ff8f53)
by phatina@fedorahosted.org
Repository : http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master
>---------------------------------------------------------------
commit 1ff8f535da38a28068895d65230f74b34c6e29a1
Author: Peter Hatina <phatina(a)redhat.com>
Date: Thu Nov 29 15:10:05 2012 +0100
optimize methods and properties completion in _LmiCompleter
>---------------------------------------------------------------
cli-tools/lmi-shell.py | 23 ++++++-----------------
1 files changed, 6 insertions(+), 17 deletions(-)
diff --git a/cli-tools/lmi-shell.py b/cli-tools/lmi-shell.py
index a649b90..0b33d5e 100755
--- a/cli-tools/lmi-shell.py
+++ b/cli-tools/lmi-shell.py
@@ -114,27 +114,18 @@ class _LmiCompleter(rlcompleter.Completer):
cmd = ".".join(members[0:-1])
to_complete = members[-1]
expr = eval(cmd, self.namespace)
+ methods = self.__complete_object_methods(expr, to_complete)
+ properties = self.__complete_object_properties(expr, to_complete)
if isinstance(expr, LmiConnection):
namespaces = expr.namespaces()
for n in namespaces:
if n.lower().startswith(to_complete.lower()):
self._last_complete.append(cmd + "." + n)
- return self._last_complete[state]
+ methods = [x for x in methods if x not in namespaces]
elif isinstance(expr, _LmiNamespace):
for c in expr.classes():
if c.lower().startswith(to_complete.lower()):
self._last_complete.append(cmd + "." + c)
- methods = self.__complete_object_methods(expr, to_complete)
- self._last_complete.extend(cmd + "." + m + "(" for m in methods)
- properties = self.__complete_object_properties(expr, to_complete)
- self._last_complete.extend(cmd + "." + p for p in properties)
- return self._last_complete[state]
- elif isinstance(expr, _LmiClass):
- methods = self.__complete_object_methods(expr, to_complete)
- self._last_complete= [cmd + "." + m + "(" for m in methods]
- properties = self.__complete_object_properties(expr, to_complete)
- self._last_complete.extend(cmd + "." + p for p in properties)
- return self._last_complete[state]
elif isinstance(expr, _LmiInstance):
for m in expr.methods():
if m.lower().startswith(to_complete.lower()):
@@ -142,11 +133,9 @@ class _LmiCompleter(rlcompleter.Completer):
for p in expr.properties():
if p.lower().startswith(to_complete.lower()):
self._last_complete.append(cmd + "." + p)
- methods = self.__complete_object_methods(expr, to_complete)
- self._last_complete.extend(cmd + "." + m + "(" for m in methods)
- properties = self.__complete_object_properties(expr, to_complete)
- self._last_complete.extend(cmd + "." + p for p in properties)
- return self._last_complete[state]
+ self._last_complete.extend(cmd + "." + m + "(" for m in methods)
+ self._last_complete.extend(cmd + "." + p for p in properties)
+ return self._last_complete[state]
return rlcompleter.Completer.complete(self, text, state)
class LmiInteractiveShell(code.InteractiveConsole):
11 years, 5 months
[cura-tools] master: fix _LmiNamespace::classes() when empty list (47cffd7)
by phatina@fedorahosted.org
Repository : http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master
>---------------------------------------------------------------
commit 47cffd7316707e421f7857b8263ae2da93dd49a1
Author: Peter Hatina <phatina(a)redhat.com>
Date: Thu Nov 29 15:06:30 2012 +0100
fix _LmiNamespace::classes() when empty list
>---------------------------------------------------------------
cli-tools/lmi/lmi_client_shell.py | 6 +-----
1 files changed, 1 insertions(+), 5 deletions(-)
diff --git a/cli-tools/lmi/lmi_client_shell.py b/cli-tools/lmi/lmi_client_shell.py
index 3a4dfc7..6059796 100644
--- a/cli-tools/lmi/lmi_client_shell.py
+++ b/cli-tools/lmi/lmi_client_shell.py
@@ -249,11 +249,7 @@ class _LmiNamespace(BaseObject):
def classes(self, filter_key = "", exact_match = False):
(class_name_list, errorstr) = self._client.get_class_names(self._name)
if not class_name_list:
- if errorstr:
- sys.stderr.write("Error: %s\n" % errorstr)
- else:
- sys.stderr.write("No classes present in namespace '%s'\n" % self._name)
- return
+ return []
if filter_key:
if not exact_match:
filter_lambda = lambda n: n.lower().find(filter_key.lower()) >= 0
11 years, 5 months
[cura-tools] master: add example usage for cli-tools to README (059f54f)
by phatina@fedorahosted.org
Repository : http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master
>---------------------------------------------------------------
commit 059f54f7ff903da916b899485e4a8c0f12c52457
Author: Peter Hatina <phatina(a)redhat.com>
Date: Thu Nov 29 14:12:59 2012 +0100
add example usage for cli-tools to README
>---------------------------------------------------------------
README | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 103 insertions(+), 0 deletions(-)
diff --git a/README b/README
index 6e382b2..46f8b4b 100644
--- a/README
+++ b/README
@@ -57,3 +57,106 @@ python clients for each OpenLMI provider.
$ mkdir build && cd build
$ ../configure --prefix=/usr
# make install
+
+*******************************************************************************
+* Example usage *
+*******************************************************************************
+
+Following examples show, how to use command-line tools:
+
+* lmi-service.py
+ $ lmi-service.py -h <hostname> -u <username> -p <password> status <service_name>
+ $ lmi-service.py -h <hostname> -u <username> -p <password> start <service_name>
+ $ lmi-service.py -h <hostname> -u <username> -p <password> stop <service_name>
+
+* lmi-power.py
+ $ lmi-power.py -h <hostname> -u <username> -p <password> poweroff
+ $ lmi-power.py -h <hostname> -u <username> -p <password> reboot
+
+* lmi-user.py
+ $ lmi-user.py -h <hostname> -u <username> -p <password> list-users
+ $ lmi-user.py -h <hostname> -u <username> -p <password> list-groups
+ $ lmi-user.py -h <hostname> -u <username> -p <password> group-members <group_name>
+
+* lmi-ip.py
+ $ lmi-ip.py -h <hostname> -u <username> -p <password> addr show
+ - shows available network interfaces and their associated addresses
+ $ lmi-ip.py -h <hostname> -u <username> -p <password> addr set <address>/<mask> dev <device_name>
+ - sets the ipv4 address to specified interface
+ $ lmi-ip.py -h <hostname> -u <username> -p <password> addr
+
+* lmi-shell
+ - general usage example:
+ - how to start a shell:
+ $ lmi-shell.py
+ >
+
+ - how to exit from the shell:
+ > <ctrl+d>
+ $
+ - how to use previous commands:
+ - press up arrow to list previous commands in history
+ - reverse-search by <ctrl+r> and type substring of the command
+
+ - how to clear a history:
+ > clear_history()
+
+ - how to connect to a remote machine:
+ > c = connect("hostname", "username", "password")
+
+ or
+
+ > c = connect("hostname", "username")
+ password: <not echoed>
+ >
+ - how to turn off display "sugar" for return values:
+ > use_display_sugar(False)
+
+ - example how to stop a service:
+ $ lmi-shell.py
+ > c = connect("hostname", "username", "password")
+ > service = c.cimv2.LMI_Service.first_instance("service")
+ > service.Status
+ OK
+ > service.StopService()
+ hostname: ok (0)
+ > service.Status
+ Stopped
+ > <ctrl+d>
+ $
+
+ - example how to show a class documentation:
+ $ lmi-shell.py
+ > c = connect("hostname", "username", "password")
+ > lmi_service = c.cimv2.LMI_Service
+ > lmi_service.doc()
+ ... class documentation ...
+ q
+ > <ctrl+d>
+ $
+
+ -example how to show an instance documentation with properties:
+ $ lmi-shell.py
+ > c = connect("hostname", "username", "password")
+ > service = c.cimv2.LMI_Service.first_instance()
+ > service.doc()
+ ... instance documentation with properties ...
+ > <ctrl+d>
+ $
+
+ - example how to print available namespaces, classes, methods, etc
+ $ lmi-shell.py
+ > c = connect("hostname", "username", "password")
+ > c.print_namespaces()
+ root
+ cimv2
+ interop
+ > c.cimv2.print_classes()
+ ... available classes ...
+ > service = c.cimv2.LMI_Service.first_instance()
+ > service.print_methods()
+ ... instance methods ...
+ > service.print_properties()
+ ... instance properties ...
+ > <ctrl+d>
+ $
11 years, 5 months
[cura-tools] master: override CIM::__repr__ in LMI classes (728f23f)
by phatina@fedorahosted.org
Repository : http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master
>---------------------------------------------------------------
commit 728f23f9295d7061870e6d7b734aa7bb669e8161
Author: Peter Hatina <phatina(a)redhat.com>
Date: Thu Nov 29 13:30:48 2012 +0100
override CIM::__repr__ in LMI classes
>---------------------------------------------------------------
cli-tools/lmi/lmi_client_shell.py | 15 ++++++++++++---
1 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/cli-tools/lmi/lmi_client_shell.py b/cli-tools/lmi/lmi_client_shell.py
index 08a1d5e..3a4dfc7 100644
--- a/cli-tools/lmi/lmi_client_shell.py
+++ b/cli-tools/lmi/lmi_client_shell.py
@@ -243,6 +243,9 @@ class _LmiNamespace(BaseObject):
return _LmiErrorHandler("Error: %s" % errorstr)
return _LmiClass(self._client, self, klass)
+ def __repr__(self):
+ return "%s(namespace='%s', ...)" % (self.__class__.__name__, self._name)
+
def classes(self, filter_key = "", exact_match = False):
(class_name_list, errorstr) = self._client.get_class_names(self._name)
if not class_name_list:
@@ -270,6 +273,9 @@ class _LmiClass(BaseObject):
self._namespace = namespace
self._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)
@@ -315,6 +321,9 @@ class _LmiInstanceName(BaseObject):
self._client = client
self._instance_name = instance_name
+ def __repr__(self):
+ return "%s(...)" % self.__class__.__name__
+
def to_instance(self):
(cim_inst, errorstr) = self._client.get_instance(self._instance_name)
if not cim_inst:
@@ -408,9 +417,6 @@ class _LmiInstance(BaseObject):
self._class = klass
self._inst = inst
- def __str__(self):
- return str(self._inst)
-
def __getattr__(self, name):
methods = self.__methods()
if methods and name in methods:
@@ -422,6 +428,9 @@ class _LmiInstance(BaseObject):
def __getitem__(self, key):
return self.__getattr__(key)
+ def __repr__(self):
+ return "%s(classname='%s', ...)" % (self.__class__.__name__, self.classname)
+
def __methods(self):
(klass, errorstr) = self._client.get_class(self._inst.classname, self._class.namespace)
if not klass:
11 years, 5 months
[cura-tools] master: add _LmiInstanceName::path (6e2d5ba)
by phatina@fedorahosted.org
Repository : http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master
>---------------------------------------------------------------
commit 6e2d5ba0c4f8549f295b1e8ab677d8ef6994f38d
Author: Peter Hatina <phatina(a)redhat.com>
Date: Thu Nov 29 13:19:17 2012 +0100
add _LmiInstanceName::path
>---------------------------------------------------------------
cli-tools/lmi/lmi_client_shell.py | 5 +++++
1 files changed, 5 insertions(+), 0 deletions(-)
diff --git a/cli-tools/lmi/lmi_client_shell.py b/cli-tools/lmi/lmi_client_shell.py
index 6b84022..08a1d5e 100644
--- a/cli-tools/lmi/lmi_client_shell.py
+++ b/cli-tools/lmi/lmi_client_shell.py
@@ -328,6 +328,11 @@ class _LmiInstanceName(BaseObject):
return None
return _LmiInstance(self._client, lmi_class, cim_inst)
+ @property
+ def path(self):
+ return str(self._instance_name)
+
+
class _LmiInstance(BaseObject):
class _LmiInstanceMethod(BaseObject):
def __init__(self, client, instance, method):
11 years, 5 months
[cura-tools] master: fix typos in _LmiInstance::associators() params (e9b640b)
by phatina@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master
>---------------------------------------------------------------
commit e9b640bf96dd822d99b7c53ab874268844677057
Author: Peter Hatina <phatina(a)redhat.com>
Date: Thu Nov 29 11:30:56 2012 +0100
fix typos in _LmiInstance::associators() params
>---------------------------------------------------------------
cli-tools/lmi/lmi_client_shell.py | 10 +++++-----
1 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/cli-tools/lmi/lmi_client_shell.py b/cli-tools/lmi/lmi_client_shell.py
index 4c78030..6b84022 100644
--- a/cli-tools/lmi/lmi_client_shell.py
+++ b/cli-tools/lmi/lmi_client_shell.py
@@ -451,15 +451,15 @@ class _LmiInstance(BaseObject):
ResultRole = None, Props = None):
result = []
assoc_args = {}
- if assocClass:
+ if AssocClass:
assoc_args["AssocClass"] = AssocClass
- if resultClass:
+ if ResultClass:
assoc_args["ResultClass"] = ResultClass
- if role:
+ if Role:
assoc_args["Role"] = Role
- if resultRole:
+ if ResultRole:
assoc_args["ResultRole"] = ResultRole
- if props:
+ if Props:
assoc_args["Props"] = Props
associators_list = self._client.get_associators(self._inst, **assoc_args)
for i in associators_list:
11 years, 5 months
[cura-tools] master: switch from file descriptors to files in _LmiTextFormater (5fceaa0)
by phatina@fedorahosted.org
Repository : http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master
>---------------------------------------------------------------
commit 5fceaa081505f2b043515c5974750434c84348bc
Author: Peter Hatina <phatina(a)redhat.com>
Date: Thu Nov 29 11:14:42 2012 +0100
switch from file descriptors to files in _LmiTextFormater
>---------------------------------------------------------------
cli-tools/lmi/lmi_client_shell.py | 101 +++++++++++++++++++------------------
1 files changed, 51 insertions(+), 50 deletions(-)
diff --git a/cli-tools/lmi/lmi_client_shell.py b/cli-tools/lmi/lmi_client_shell.py
index b92bc25..4c78030 100644
--- a/cli-tools/lmi/lmi_client_shell.py
+++ b/cli-tools/lmi/lmi_client_shell.py
@@ -49,16 +49,16 @@ class _LmiTextFormatter(object):
def __init__(self, text):
self._text = text
- def format(self, indent = 0, sub_indent = 0, width = 80, fd = sys.stdout.fileno(), **kwargs):
+ def format(self, indent = 0, sub_indent = 0, width = 80, f = sys.stdout, **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._text):
- os.write(fd, "%s%s\n" % (" " * indent, l))
+ f.write("%s%s\n" % (" " * indent, l))
if "separator" in kwargs and kwargs["separator"]:
- os.write(fd, "\n")
+ f.write("\n")
class _LmiXmlFormatter(object):
def __init__(self, xml):
@@ -67,23 +67,23 @@ class _LmiXmlFormatter(object):
if not self._width:
self._width = 80
- def __format_class_property_content(self, node, indent = 0, sub_indent = 0, width = 80, fd = sys.stdout.fileno()):
+ def __format_class_property_content(self, node, indent = 0, sub_indent = 0, width = 80, f = sys.stdout):
children = node.childNodes
children_len = len(children)
for (i, n) in enumerate(children):
if isinstance(n, pywbem.cim_xml.QUALIFIER):
- self.__format_qualifier(n, indent, sub_indent, width, fd)
+ self.__format_qualifier(n, indent, sub_indent, width, f)
elif isinstance(n, pywbem.cim_xml.PROPERTY):
- self.__format_class_property(n, indent, sub_indent, width, fd)
+ self.__format_class_property(n, indent, sub_indent, width, f)
elif isinstance(n, pywbem.cim_xml.PROPERTY_ARRAY):
- self.__format_class_property_array(n, indent, sub_indent, width, fd)
+ self.__format_class_property_array(n, indent, sub_indent, width, f)
elif isinstance(n, pywbem.cim_xml.METHOD):
- self.__format_method(n, indent, sub_indent, width, fd)
+ self.__format_method(n, indent, sub_indent, width, f)
elif isinstance(n, pywbem.cim_xml.VALUE):
# NOTE: we skip default value for the class
pass
- def __format_qualifier(self, node, indent = 0, sub_indent = 0, width = 80, fd = sys.stdout.fileno()):
+ def __format_qualifier(self, node, indent = 0, sub_indent = 0, width = 80, f = sys.stdout):
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"))
@@ -92,41 +92,41 @@ class _LmiXmlFormatter(object):
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)
+ _LmiTextFormatter(val).format(indent, sub_indent + 4, width, f, separator = True)
- def __format_class_property(self, node, indent = 0, sub_indent = 0, width = 80, fd = sys.stdout.fileno()):
+ def __format_class_property(self, node, indent = 0, sub_indent = 0, width = 80, f = sys.stdout):
val = "[property] %s %s" % (node.getAttribute("TYPE"), node.getAttribute("NAME"))
- _LmiTextFormatter(val).format(indent, sub_indent + 4, width, fd, separator = True)
- self.__format_class_property_content(node, indent + 4, sub_indent, width, fd)
+ _LmiTextFormatter(val).format(indent, sub_indent + 4, width, f, separator = True)
+ self.__format_class_property_content(node, indent + 4, sub_indent, width, f)
- def __format_class_property_array(self, node, indent = 0, sub_indent = 0, width = 80, fd = sys.stdout.fileno()):
+ def __format_class_property_array(self, node, indent = 0, sub_indent = 0, width = 80, f = sys.stdout):
val = "[property array] %s [] %s" % (node.getAttribute("TYPE"), node.getAttribute("TYPE"))
- _LmiTextFormatter(val).format(indent, sub_indent + 4, width, fd, separator = True)
- self.__format_class_property_content(node, indent + 4, sub_indent, width, fd)
+ _LmiTextFormatter(val).format(indent, sub_indent + 4, width, f, separator = True)
+ self.__format_class_property_content(node, indent + 4, sub_indent, width, f)
- def __format_class_property_reference(self, node, indent = 0, sub_indent = 0, width = 80, fd = sys.stdout.fileno()):
+ def __format_class_property_reference(self, node, indent = 0, sub_indent = 0, width = 80, f = sys.stdout):
val = "[property ref] %s %s" % (node.getAttribute("REFERENCECLASS"), node.getAttribute("NAME"))
- _LmiTextFormatter(val).format(indent, sub_indent + 4, width, fd, separator = True)
- self.__format_class_property_content(node, indent + 4, sub_indent, width, fd)
+ _LmiTextFormatter(val).format(indent, sub_indent + 4, width, f, separator = True)
+ self.__format_class_property_content(node, indent + 4, sub_indent, width, f)
- def __format_instance_property(self, node, indent = 0, sub_indent = 0, width = 80, fd = sys.stdout.fileno()):
+ def __format_instance_property(self, node, indent = 0, sub_indent = 0, width = 80, f = sys.stdout):
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)
+ _LmiTextFormatter(prop).format(indent, sub_indent + 4, width, f, separator = True)
- def __format_instance_property_array(self, node, indent = 0, sub_indent = 0, width = 80, fd = sys.stdout.fileno()):
+ def __format_instance_property_array(self, node, indent = 0, sub_indent = 0, width = 80, f = sys.stdout):
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)
+ _LmiTextFormatter(prop).format(indent, sub_indent + 4, width, f, separator = True)
- def __format_instance_property_reference(self, node, indent = 0, sub_indent = 0, width = 80, fd = sys.stdout.fileno()):
+ def __format_instance_property_reference(self, node, indent = 0, sub_indent = 0, width = 80, f = sys.stdout):
val = "[property ref] %s %s" % (node.getAttribute("REFERENCECLASS"), node.getAttribute("NAME"))
- _LmiTextFormatter(val).format(indent, sub_indent + 4, width, fd, separator = True)
+ _LmiTextFormatter(val).format(indent, sub_indent + 4, width, f, separator = True)
- def __format_method(self, node, indent = 0, sub_indent = 0, width = 80, fd = sys.stdout.fileno()):
+ def __format_method(self, node, indent = 0, sub_indent = 0, width = 80, f = sys.stdout):
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)]
@@ -134,47 +134,47 @@ class _LmiXmlFormatter(object):
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)
+ _LmiTextFormatter(val).format(indent, sub_indent, width, f, separator = True)
for q in qualifiers:
- self.__format_qualifier(q, indent + 4, sub_indent + 4, width, fd)
+ self.__format_qualifier(q, indent + 4, sub_indent + 4, width, f)
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)
+ _LmiTextFormatter(val).format(indent + 4, sub_indent + 4, width, f, 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)
+ _LmiTextFormatter(val).format(indent + 4, sub_indent + 4, width, f, 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)
+ _LmiTextFormatter(val).format(indent + 4, sub_indent + 4, width, f, 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)
+ _LmiTextFormatter(val).format(indent + 4, sub_indent + 4, width, f, separator = True)
- def __format_class(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)
+ def __format_class(self, node, indent = 0, sub_indent = 0, width = 80, f = sys.stdout):
+ _LmiTextFormatter("Class: %s" % node.getAttribute("NAME")).format(indent, sub_indent, width, f)
+ _LmiTextFormatter("SuperClass: %s" % node.getAttribute("SUPERCLASS")).format(indent + 4, sub_indent, width, f)
for n in node.childNodes:
if isinstance(n, pywbem.cim_xml.QUALIFIER):
- self.__format_qualifier(n, indent + 4, sub_indent, width, fd)
+ self.__format_qualifier(n, indent + 4, sub_indent, width, f)
elif isinstance(n, pywbem.cim_xml.PROPERTY):
- self.__format_class_property(n, indent + 4, sub_indent, width, fd)
+ self.__format_class_property(n, indent + 4, sub_indent, width, f)
elif isinstance(n, pywbem.cim_xml.PROPERTY_ARRAY):
- self.__format_class_property_array(n, indent + 4, sub_indent, width, fd)
+ self.__format_class_property_array(n, indent + 4, sub_indent, width, f)
elif isinstance(n, pywbem.cim_xml.PROPERTY_REFERENCE):
- self.__format_class_property_reference(n, indent + 4, sub_indent, width, fd)
+ self.__format_class_property_reference(n, indent + 4, sub_indent, width, f)
elif isinstance(n, pywbem.cim_xml.METHOD):
- self.__format_method(n, indent + 4, sub_indent, width, fd)
+ self.__format_method(n, indent + 4, sub_indent, width, f)
- def __format_instance(self, node, indent = 0, sub_indent = 0, width = 80, fd = sys.stdout.fileno()):
+ def __format_instance(self, node, indent = 0, sub_indent = 0, width = 80, f = sys.stdout):
instance = node.firstChild.nextSibling
- _LmiTextFormatter("Instance of %s" % instance.getAttribute("CLASSNAME")).format(indent, sub_indent, width, fd)
+ _LmiTextFormatter("Instance of %s" % instance.getAttribute("CLASSNAME")).format(indent, sub_indent, width, f)
for n in instance.childNodes:
if isinstance(n, pywbem.cim_xml.PROPERTY):
- self.__format_instance_property(n, indent + 4, sub_indent, width, fd)
+ self.__format_instance_property(n, indent + 4, sub_indent, width, f)
elif isinstance(n, pywbem.cim_xml.PROPERTY_ARRAY):
- self.__format_instance_property_array(n, indent + 4, sub_indent, width, fd)
+ self.__format_instance_property_array(n, indent + 4, sub_indent, width, f)
elif isinstance(n, pywbem.cim_xml.PROPERTY_REFERENCE):
- self.__format_instance_property_reference(n, indent + 4, sub_indent, width, fd)
+ self.__format_instance_property_reference(n, indent + 4, sub_indent, width, f)
@staticmethod
def __which(program):
@@ -198,17 +198,18 @@ class _LmiXmlFormatter(object):
if path:
return path
- def format(self, indent = 0, sub_indent = 0, width = 80, fd = sys.stdout.fileno()):
+ 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, fd)
+ 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, fd)
+ self.__format_instance(self._xml, indent, sub_indent, width, f)
def fancy_format(self, interactive):
if interactive:
tmpfile = tempfile.mkstemp()
- self.format(0, 0, self._width, tmpfile[0])
- os.close(tmpfile[0])
+ 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:
11 years, 5 months