[cura-tools] master: code cleanup in LMINamespace (503e78b)
by phatina@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master
>---------------------------------------------------------------
commit 503e78b2d19c079b2cc235bf5d9ce4fc3d01d610
Author: Peter Hatina <phatina(a)redhat.com>
Date: Mon Jul 29 20:22:02 2013 +0200
code cleanup in LMINamespace
>---------------------------------------------------------------
cli-tools/lmi/shell/LMINamespace.py | 21 +++------------------
1 files changed, 3 insertions(+), 18 deletions(-)
diff --git a/cli-tools/lmi/shell/LMINamespace.py b/cli-tools/lmi/shell/LMINamespace.py
index cd1882f..89ec448 100644
--- a/cli-tools/lmi/shell/LMINamespace.py
+++ b/cli-tools/lmi/shell/LMINamespace.py
@@ -19,7 +19,7 @@ from LMIBaseObject import LMIBaseObject
from LMIBaseClient import LMIBaseClient
from LMIObjectFactory import LMIObjectFactory
-from LMIUtil import lmi_wrap_cim_instance
+from LMIUtil import lmi_transform_to_cim
class LMINamespace(LMIBaseObject):
"""
@@ -78,21 +78,6 @@ class LMINamespace(LMIBaseObject):
class_name_list = filter(filter_lambda, class_name_list)
return class_name_list
- def _wrap_cim_instance_list(self, cim_inst_list):
- """
- Wrapps a list of CIMInstance objects into the list of LMIInstnace objects.
-
- Arguments:
- cim_inst_list -- list of CIMInstances
- """
- lmi_inst_list = []
- for cim_inst in cim_inst_list:
- lmi_inst_list.append( \
- lmi_wrap_cim_instance(self._client, cim_inst, cim_inst.classname, \
- cim_inst.path.namespace) \
- )
- return lmi_inst_list
-
def print_classes(self, filter_key = "", exact_match = False):
"""
Prints out a list of classes.
@@ -117,7 +102,7 @@ class LMINamespace(LMIBaseObject):
(inst_list, _, errorstr) = self._client._exec_query(LMIBaseClient.QUERY_LANG_CQL, query, self._name)
if not inst_list:
return []
- return self._wrap_cim_instance_list(inst_list)
+ return lmi_transform_to_cim(self._client, inst_list)
def wql(self, query):
"""
@@ -130,7 +115,7 @@ class LMINamespace(LMIBaseObject):
(inst_list, _, errorstr) = self._client._exec_query(LMIBaseClient.QUERY_LANG_WQL, query, self._name)
if not inst_list:
return []
- return self._wrap_cim_instance_list(inst_list)
+ return lmi_transform_to_cim(self._client, inst_list)
@property
def name(self):
10 years, 10 months
[cura-tools] master: LMIMethod code cleanup (d835c2f)
by phatina@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master
>---------------------------------------------------------------
commit d835c2f68dfcfffb2148e94dcacda2a8f485e15b
Author: Peter Hatina <phatina(a)redhat.com>
Date: Mon Jul 29 19:50:46 2013 +0200
LMIMethod code cleanup
>---------------------------------------------------------------
cli-tools/lmi/shell/LMIMethod.py | 5 +----
1 files changed, 1 insertions(+), 4 deletions(-)
diff --git a/cli-tools/lmi/shell/LMIMethod.py b/cli-tools/lmi/shell/LMIMethod.py
index 4f70799..e381d76 100644
--- a/cli-tools/lmi/shell/LMIMethod.py
+++ b/cli-tools/lmi/shell/LMIMethod.py
@@ -339,10 +339,7 @@ class LMIMethod(LMIBaseObject):
use_display_hook = True)
(rval, call_rparams, call_errorstr) = self._client._call_method_raw(self._lmi_instance,
self._method.name, **kwargs)
- if isinstance(rval, pywbem.CIMInt):
- rval = int(rval)
- elif isinstance(rval, pywbem.CIMFloat):
- rval = float(rval)
+ rval = lmi_transform_to_cim(self._client, rval)
if call_rparams:
call_rparams = lmi_transform_to_cim(self._client, call_rparams)
if not call_rparams:
10 years, 10 months
[cura-tools] master: fix license comments (f3e9d32)
by phatina@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master
>---------------------------------------------------------------
commit f3e9d32ee2666f15a3112a52e83006db83a65402
Author: Peter Hatina <phatina(a)redhat.com>
Date: Mon Jul 29 17:26:00 2013 +0200
fix license comments
>---------------------------------------------------------------
cli-tools/lmi/__init__.py | 2 +-
cli-tools/lmi/shell/LMIBaseClient.py | 2 +-
cli-tools/lmi/shell/LMIBaseObject.py | 2 +-
cli-tools/lmi/shell/LMIClass.py | 2 +-
cli-tools/lmi/shell/LMICompleter.py | 2 +-
cli-tools/lmi/shell/LMIConnection.py | 2 +-
cli-tools/lmi/shell/LMIConsole.py | 2 +-
cli-tools/lmi/shell/LMIConstantValues.py | 2 +-
cli-tools/lmi/shell/LMIDecorators.py | 2 +-
cli-tools/lmi/shell/LMIExceptions.py | 2 +-
cli-tools/lmi/shell/LMIFormatter.py | 2 +-
cli-tools/lmi/shell/LMIIndication.py | 2 +-
cli-tools/lmi/shell/LMIIndicationListener.py | 2 +-
cli-tools/lmi/shell/LMIInstance.py | 2 +-
cli-tools/lmi/shell/LMIInstanceName.py | 2 +-
cli-tools/lmi/shell/LMIMethod.py | 2 +-
cli-tools/lmi/shell/LMINamespace.py | 2 +-
cli-tools/lmi/shell/LMIObjectFactory.py | 2 +-
cli-tools/lmi/shell/LMIReturnValue.py | 2 +-
cli-tools/lmi/shell/LMIShellCache.py | 2 +-
cli-tools/lmi/shell/LMIShellClient.py | 15 +++++++++++++++
cli-tools/lmi/shell/LMIShellConfig.py | 3 +--
cli-tools/lmi/shell/LMIShellOptions.py | 2 +-
cli-tools/lmi/shell/LMISubscription.py | 2 +-
cli-tools/lmi/shell/LMIUtil.py | 2 +-
cli-tools/lmi/shell/__init__.py | 3 +--
cli-tools/lmishell | 2 +-
27 files changed, 41 insertions(+), 28 deletions(-)
diff --git a/cli-tools/lmi/__init__.py b/cli-tools/lmi/__init__.py
index e46caaf..e554343 100644
--- a/cli-tools/lmi/__init__.py
+++ b/cli-tools/lmi/__init__.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
+# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
diff --git a/cli-tools/lmi/shell/LMIBaseClient.py b/cli-tools/lmi/shell/LMIBaseClient.py
index 1688cc9..9e481fd 100644
--- a/cli-tools/lmi/shell/LMIBaseClient.py
+++ b/cli-tools/lmi/shell/LMIBaseClient.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
+# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
diff --git a/cli-tools/lmi/shell/LMIBaseObject.py b/cli-tools/lmi/shell/LMIBaseObject.py
index f256a09..08d0551 100644
--- a/cli-tools/lmi/shell/LMIBaseObject.py
+++ b/cli-tools/lmi/shell/LMIBaseObject.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
+# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
diff --git a/cli-tools/lmi/shell/LMIClass.py b/cli-tools/lmi/shell/LMIClass.py
index 638e01e..43b316a 100644
--- a/cli-tools/lmi/shell/LMIClass.py
+++ b/cli-tools/lmi/shell/LMIClass.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
+# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
diff --git a/cli-tools/lmi/shell/LMICompleter.py b/cli-tools/lmi/shell/LMICompleter.py
index 105cf03..4ee4b95 100644
--- a/cli-tools/lmi/shell/LMICompleter.py
+++ b/cli-tools/lmi/shell/LMICompleter.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
+# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
diff --git a/cli-tools/lmi/shell/LMIConnection.py b/cli-tools/lmi/shell/LMIConnection.py
index fe101ff..e400214 100644
--- a/cli-tools/lmi/shell/LMIConnection.py
+++ b/cli-tools/lmi/shell/LMIConnection.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
+# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
diff --git a/cli-tools/lmi/shell/LMIConsole.py b/cli-tools/lmi/shell/LMIConsole.py
index 8c4c6da..9cc3897 100644
--- a/cli-tools/lmi/shell/LMIConsole.py
+++ b/cli-tools/lmi/shell/LMIConsole.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
+# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
diff --git a/cli-tools/lmi/shell/LMIConstantValues.py b/cli-tools/lmi/shell/LMIConstantValues.py
index c5f43aa..d4118f3 100644
--- a/cli-tools/lmi/shell/LMIConstantValues.py
+++ b/cli-tools/lmi/shell/LMIConstantValues.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
+# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
diff --git a/cli-tools/lmi/shell/LMIDecorators.py b/cli-tools/lmi/shell/LMIDecorators.py
index 66ac4c8..448befb 100644
--- a/cli-tools/lmi/shell/LMIDecorators.py
+++ b/cli-tools/lmi/shell/LMIDecorators.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
+# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
diff --git a/cli-tools/lmi/shell/LMIExceptions.py b/cli-tools/lmi/shell/LMIExceptions.py
index cb69314..30b22a3 100644
--- a/cli-tools/lmi/shell/LMIExceptions.py
+++ b/cli-tools/lmi/shell/LMIExceptions.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
+# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
diff --git a/cli-tools/lmi/shell/LMIFormatter.py b/cli-tools/lmi/shell/LMIFormatter.py
index 82b7571..274269e 100644
--- a/cli-tools/lmi/shell/LMIFormatter.py
+++ b/cli-tools/lmi/shell/LMIFormatter.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
+# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
diff --git a/cli-tools/lmi/shell/LMIIndication.py b/cli-tools/lmi/shell/LMIIndication.py
index b863317..1375aa2 100644
--- a/cli-tools/lmi/shell/LMIIndication.py
+++ b/cli-tools/lmi/shell/LMIIndication.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
+# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
diff --git a/cli-tools/lmi/shell/LMIIndicationListener.py b/cli-tools/lmi/shell/LMIIndicationListener.py
index ba6d929..5582f58 100644
--- a/cli-tools/lmi/shell/LMIIndicationListener.py
+++ b/cli-tools/lmi/shell/LMIIndicationListener.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
+# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
diff --git a/cli-tools/lmi/shell/LMIInstance.py b/cli-tools/lmi/shell/LMIInstance.py
index ac8b8c0..754c6a4 100644
--- a/cli-tools/lmi/shell/LMIInstance.py
+++ b/cli-tools/lmi/shell/LMIInstance.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
+# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
diff --git a/cli-tools/lmi/shell/LMIInstanceName.py b/cli-tools/lmi/shell/LMIInstanceName.py
index 6a25d1b..5a37c4b 100644
--- a/cli-tools/lmi/shell/LMIInstanceName.py
+++ b/cli-tools/lmi/shell/LMIInstanceName.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
+# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
diff --git a/cli-tools/lmi/shell/LMIMethod.py b/cli-tools/lmi/shell/LMIMethod.py
index 70ef130..4f70799 100644
--- a/cli-tools/lmi/shell/LMIMethod.py
+++ b/cli-tools/lmi/shell/LMIMethod.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
+# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
diff --git a/cli-tools/lmi/shell/LMINamespace.py b/cli-tools/lmi/shell/LMINamespace.py
index 28bf686..cd1882f 100644
--- a/cli-tools/lmi/shell/LMINamespace.py
+++ b/cli-tools/lmi/shell/LMINamespace.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
+# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
diff --git a/cli-tools/lmi/shell/LMIObjectFactory.py b/cli-tools/lmi/shell/LMIObjectFactory.py
index d4a6a2e..5e07af1 100644
--- a/cli-tools/lmi/shell/LMIObjectFactory.py
+++ b/cli-tools/lmi/shell/LMIObjectFactory.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
+# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
diff --git a/cli-tools/lmi/shell/LMIReturnValue.py b/cli-tools/lmi/shell/LMIReturnValue.py
index 0a249ec..5ca650c 100644
--- a/cli-tools/lmi/shell/LMIReturnValue.py
+++ b/cli-tools/lmi/shell/LMIReturnValue.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
+# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
diff --git a/cli-tools/lmi/shell/LMIShellCache.py b/cli-tools/lmi/shell/LMIShellCache.py
index a1b6e3f..ad28713 100644
--- a/cli-tools/lmi/shell/LMIShellCache.py
+++ b/cli-tools/lmi/shell/LMIShellCache.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
+# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
diff --git a/cli-tools/lmi/shell/LMIShellClient.py b/cli-tools/lmi/shell/LMIShellClient.py
index aa5892b..46ab9ae 100644
--- a/cli-tools/lmi/shell/LMIShellClient.py
+++ b/cli-tools/lmi/shell/LMIShellClient.py
@@ -1,3 +1,18 @@
+# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, see <http://www.gnu.org/licenses/>.
+
from LMIBaseClient import LMIBaseClient
from LMIReturnValue import LMIReturnValue
from LMIShellCache import LMIShellCache
diff --git a/cli-tools/lmi/shell/LMIShellConfig.py b/cli-tools/lmi/shell/LMIShellConfig.py
index 75cf897..66e05c8 100644
--- a/cli-tools/lmi/shell/LMIShellConfig.py
+++ b/cli-tools/lmi/shell/LMIShellConfig.py
@@ -1,5 +1,4 @@
-#!/usr/bin/env python
-# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
+# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
diff --git a/cli-tools/lmi/shell/LMIShellOptions.py b/cli-tools/lmi/shell/LMIShellOptions.py
index b3d7a1a..f96499d 100644
--- a/cli-tools/lmi/shell/LMIShellOptions.py
+++ b/cli-tools/lmi/shell/LMIShellOptions.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
+# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
diff --git a/cli-tools/lmi/shell/LMISubscription.py b/cli-tools/lmi/shell/LMISubscription.py
index 0e1d2f5..b8bd241 100644
--- a/cli-tools/lmi/shell/LMISubscription.py
+++ b/cli-tools/lmi/shell/LMISubscription.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
+# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
diff --git a/cli-tools/lmi/shell/LMIUtil.py b/cli-tools/lmi/shell/LMIUtil.py
index 655203f..607151b 100644
--- a/cli-tools/lmi/shell/LMIUtil.py
+++ b/cli-tools/lmi/shell/LMIUtil.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
+# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
diff --git a/cli-tools/lmi/shell/__init__.py b/cli-tools/lmi/shell/__init__.py
index aaaa34e..916a0e4 100644
--- a/cli-tools/lmi/shell/__init__.py
+++ b/cli-tools/lmi/shell/__init__.py
@@ -1,5 +1,4 @@
-#!/usr/bin/env python
-# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
+# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
diff --git a/cli-tools/lmishell b/cli-tools/lmishell
index c1673ab..e9f6f54 100755
--- a/cli-tools/lmishell
+++ b/cli-tools/lmishell
@@ -1,5 +1,5 @@
#!/usr/bin/env python
-# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
+# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
10 years, 10 months
[cura-tools] master: switch autotools for distutils (95a14d4)
by phatina@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master
>---------------------------------------------------------------
commit 95a14d4059e4efe921e88967d45ab5c503afecf0
Author: Peter Hatina <phatina(a)redhat.com>
Date: Mon Jul 29 17:24:04 2013 +0200
switch autotools for distutils
>---------------------------------------------------------------
INSTALL | 370 --------------------
autogen.sh | 9 -
cli-tools/lmi/makefile.am | 1 -
cli-tools/lmi/shell/makefile.am | 28 --
cli-tools/makefile.am | 7 -
cli-tools/{lmi/shell/LMIBaseObject.py => setup.py} | 33 +-
configure.ac | 19 -
m4/python_module.m4 | 11 -
makefile.am | 3 -
man/makefile.am | 1 -
10 files changed, 15 insertions(+), 467 deletions(-)
diff --git a/INSTALL b/INSTALL
deleted file mode 100644
index a1e89e1..0000000
--- a/INSTALL
+++ /dev/null
@@ -1,370 +0,0 @@
-Installation Instructions
-*************************
-
-Copyright (C) 1994-1996, 1999-2002, 2004-2011 Free Software Foundation,
-Inc.
-
- Copying and distribution of this file, with or without modification,
-are permitted in any medium without royalty provided the copyright
-notice and this notice are preserved. This file is offered as-is,
-without warranty of any kind.
-
-Basic Installation
-==================
-
- Briefly, the shell commands `./configure; make; make install' should
-configure, build, and install this package. The following
-more-detailed instructions are generic; see the `README' file for
-instructions specific to this package. Some packages provide this
-`INSTALL' file but do not implement all of the features documented
-below. The lack of an optional feature in a given package is not
-necessarily a bug. More recommendations for GNU packages can be found
-in *note Makefile Conventions: (standards)Makefile Conventions.
-
- The `configure' shell script attempts to guess correct values for
-various system-dependent variables used during compilation. It uses
-those values to create a `Makefile' in each directory of the package.
-It may also create one or more `.h' files containing system-dependent
-definitions. Finally, it creates a shell script `config.status' that
-you can run in the future to recreate the current configuration, and a
-file `config.log' containing compiler output (useful mainly for
-debugging `configure').
-
- It can also use an optional file (typically called `config.cache'
-and enabled with `--cache-file=config.cache' or simply `-C') that saves
-the results of its tests to speed up reconfiguring. Caching is
-disabled by default to prevent problems with accidental use of stale
-cache files.
-
- If you need to do unusual things to compile the package, please try
-to figure out how `configure' could check whether to do them, and mail
-diffs or instructions to the address given in the `README' so they can
-be considered for the next release. If you are using the cache, and at
-some point `config.cache' contains results you don't want to keep, you
-may remove or edit it.
-
- The file `configure.ac' (or `configure.in') is used to create
-`configure' by a program called `autoconf'. You need `configure.ac' if
-you want to change it or regenerate `configure' using a newer version
-of `autoconf'.
-
- The simplest way to compile this package is:
-
- 1. `cd' to the directory containing the package's source code and type
- `./configure' to configure the package for your system.
-
- Running `configure' might take a while. While running, it prints
- some messages telling which features it is checking for.
-
- 2. Type `make' to compile the package.
-
- 3. Optionally, type `make check' to run any self-tests that come with
- the package, generally using the just-built uninstalled binaries.
-
- 4. Type `make install' to install the programs and any data files and
- documentation. When installing into a prefix owned by root, it is
- recommended that the package be configured and built as a regular
- user, and only the `make install' phase executed with root
- privileges.
-
- 5. Optionally, type `make installcheck' to repeat any self-tests, but
- this time using the binaries in their final installed location.
- This target does not install anything. Running this target as a
- regular user, particularly if the prior `make install' required
- root privileges, verifies that the installation completed
- correctly.
-
- 6. You can remove the program binaries and object files from the
- source code directory by typing `make clean'. To also remove the
- files that `configure' created (so you can compile the package for
- a different kind of computer), type `make distclean'. There is
- also a `make maintainer-clean' target, but that is intended mainly
- for the package's developers. If you use it, you may have to get
- all sorts of other programs in order to regenerate files that came
- with the distribution.
-
- 7. Often, you can also type `make uninstall' to remove the installed
- files again. In practice, not all packages have tested that
- uninstallation works correctly, even though it is required by the
- GNU Coding Standards.
-
- 8. Some packages, particularly those that use Automake, provide `make
- distcheck', which can by used by developers to test that all other
- targets like `make install' and `make uninstall' work correctly.
- This target is generally not run by end users.
-
-Compilers and Options
-=====================
-
- Some systems require unusual options for compilation or linking that
-the `configure' script does not know about. Run `./configure --help'
-for details on some of the pertinent environment variables.
-
- You can give `configure' initial values for configuration parameters
-by setting variables in the command line or in the environment. Here
-is an example:
-
- ./configure CC=c99 CFLAGS=-g LIBS=-lposix
-
- *Note Defining Variables::, for more details.
-
-Compiling For Multiple Architectures
-====================================
-
- You can compile the package for more than one kind of computer at the
-same time, by placing the object files for each architecture in their
-own directory. To do this, you can use GNU `make'. `cd' to the
-directory where you want the object files and executables to go and run
-the `configure' script. `configure' automatically checks for the
-source code in the directory that `configure' is in and in `..'. This
-is known as a "VPATH" build.
-
- With a non-GNU `make', it is safer to compile the package for one
-architecture at a time in the source code directory. After you have
-installed the package for one architecture, use `make distclean' before
-reconfiguring for another architecture.
-
- On MacOS X 10.5 and later systems, you can create libraries and
-executables that work on multiple system types--known as "fat" or
-"universal" binaries--by specifying multiple `-arch' options to the
-compiler but only a single `-arch' option to the preprocessor. Like
-this:
-
- ./configure CC="gcc -arch i386 -arch x86_64 -arch ppc -arch ppc64" \
- CXX="g++ -arch i386 -arch x86_64 -arch ppc -arch ppc64" \
- CPP="gcc -E" CXXCPP="g++ -E"
-
- This is not guaranteed to produce working output in all cases, you
-may have to build one architecture at a time and combine the results
-using the `lipo' tool if you have problems.
-
-Installation Names
-==================
-
- By default, `make install' installs the package's commands under
-`/usr/local/bin', include files under `/usr/local/include', etc. You
-can specify an installation prefix other than `/usr/local' by giving
-`configure' the option `--prefix=PREFIX', where PREFIX must be an
-absolute file name.
-
- You can specify separate installation prefixes for
-architecture-specific files and architecture-independent files. If you
-pass the option `--exec-prefix=PREFIX' to `configure', the package uses
-PREFIX as the prefix for installing programs and libraries.
-Documentation and other data files still use the regular prefix.
-
- In addition, if you use an unusual directory layout you can give
-options like `--bindir=DIR' to specify different values for particular
-kinds of files. Run `configure --help' for a list of the directories
-you can set and what kinds of files go in them. In general, the
-default for these options is expressed in terms of `${prefix}', so that
-specifying just `--prefix' will affect all of the other directory
-specifications that were not explicitly provided.
-
- The most portable way to affect installation locations is to pass the
-correct locations to `configure'; however, many packages provide one or
-both of the following shortcuts of passing variable assignments to the
-`make install' command line to change installation locations without
-having to reconfigure or recompile.
-
- The first method involves providing an override variable for each
-affected directory. For example, `make install
-prefix=/alternate/directory' will choose an alternate location for all
-directory configuration variables that were expressed in terms of
-`${prefix}'. Any directories that were specified during `configure',
-but not in terms of `${prefix}', must each be overridden at install
-time for the entire installation to be relocated. The approach of
-makefile variable overrides for each directory variable is required by
-the GNU Coding Standards, and ideally causes no recompilation.
-However, some platforms have known limitations with the semantics of
-shared libraries that end up requiring recompilation when using this
-method, particularly noticeable in packages that use GNU Libtool.
-
- The second method involves providing the `DESTDIR' variable. For
-example, `make install DESTDIR=/alternate/directory' will prepend
-`/alternate/directory' before all installation names. The approach of
-`DESTDIR' overrides is not required by the GNU Coding Standards, and
-does not work on platforms that have drive letters. On the other hand,
-it does better at avoiding recompilation issues, and works well even
-when some directory options were not specified in terms of `${prefix}'
-at `configure' time.
-
-Optional Features
-=================
-
- If the package supports it, you can cause programs to be installed
-with an extra prefix or suffix on their names by giving `configure' the
-option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'.
-
- Some packages pay attention to `--enable-FEATURE' options to
-`configure', where FEATURE indicates an optional part of the package.
-They may also pay attention to `--with-PACKAGE' options, where PACKAGE
-is something like `gnu-as' or `x' (for the X Window System). The
-`README' should mention any `--enable-' and `--with-' options that the
-package recognizes.
-
- For packages that use the X Window System, `configure' can usually
-find the X include and library files automatically, but if it doesn't,
-you can use the `configure' options `--x-includes=DIR' and
-`--x-libraries=DIR' to specify their locations.
-
- Some packages offer the ability to configure how verbose the
-execution of `make' will be. For these packages, running `./configure
---enable-silent-rules' sets the default to minimal output, which can be
-overridden with `make V=1'; while running `./configure
---disable-silent-rules' sets the default to verbose, which can be
-overridden with `make V=0'.
-
-Particular systems
-==================
-
- On HP-UX, the default C compiler is not ANSI C compatible. If GNU
-CC is not installed, it is recommended to use the following options in
-order to use an ANSI C compiler:
-
- ./configure CC="cc -Ae -D_XOPEN_SOURCE=500"
-
-and if that doesn't work, install pre-built binaries of GCC for HP-UX.
-
- HP-UX `make' updates targets which have the same time stamps as
-their prerequisites, which makes it generally unusable when shipped
-generated files such as `configure' are involved. Use GNU `make'
-instead.
-
- On OSF/1 a.k.a. Tru64, some versions of the default C compiler cannot
-parse its `<wchar.h>' header file. The option `-nodtk' can be used as
-a workaround. If GNU CC is not installed, it is therefore recommended
-to try
-
- ./configure CC="cc"
-
-and if that doesn't work, try
-
- ./configure CC="cc -nodtk"
-
- On Solaris, don't put `/usr/ucb' early in your `PATH'. This
-directory contains several dysfunctional programs; working variants of
-these programs are available in `/usr/bin'. So, if you need `/usr/ucb'
-in your `PATH', put it _after_ `/usr/bin'.
-
- On Haiku, software installed for all users goes in `/boot/common',
-not `/usr/local'. It is recommended to use the following options:
-
- ./configure --prefix=/boot/common
-
-Specifying the System Type
-==========================
-
- There may be some features `configure' cannot figure out
-automatically, but needs to determine by the type of machine the package
-will run on. Usually, assuming the package is built to be run on the
-_same_ architectures, `configure' can figure that out, but if it prints
-a message saying it cannot guess the machine type, give it the
-`--build=TYPE' option. TYPE can either be a short name for the system
-type, such as `sun4', or a canonical name which has the form:
-
- CPU-COMPANY-SYSTEM
-
-where SYSTEM can have one of these forms:
-
- OS
- KERNEL-OS
-
- See the file `config.sub' for the possible values of each field. If
-`config.sub' isn't included in this package, then this package doesn't
-need to know the machine type.
-
- If you are _building_ compiler tools for cross-compiling, you should
-use the option `--target=TYPE' to select the type of system they will
-produce code for.
-
- If you want to _use_ a cross compiler, that generates code for a
-platform different from the build platform, you should specify the
-"host" platform (i.e., that on which the generated programs will
-eventually be run) with `--host=TYPE'.
-
-Sharing Defaults
-================
-
- If you want to set default values for `configure' scripts to share,
-you can create a site shell script called `config.site' that gives
-default values for variables like `CC', `cache_file', and `prefix'.
-`configure' looks for `PREFIX/share/config.site' if it exists, then
-`PREFIX/etc/config.site' if it exists. Or, you can set the
-`CONFIG_SITE' environment variable to the location of the site script.
-A warning: not all `configure' scripts look for a site script.
-
-Defining Variables
-==================
-
- Variables not defined in a site shell script can be set in the
-environment passed to `configure'. However, some packages may run
-configure again during the build, and the customized values of these
-variables may be lost. In order to avoid this problem, you should set
-them in the `configure' command line, using `VAR=value'. For example:
-
- ./configure CC=/usr/local2/bin/gcc
-
-causes the specified `gcc' to be used as the C compiler (unless it is
-overridden in the site shell script).
-
-Unfortunately, this technique does not work for `CONFIG_SHELL' due to
-an Autoconf bug. Until the bug is fixed you can use this workaround:
-
- CONFIG_SHELL=/bin/bash /bin/bash ./configure CONFIG_SHELL=/bin/bash
-
-`configure' Invocation
-======================
-
- `configure' recognizes the following options to control how it
-operates.
-
-`--help'
-`-h'
- Print a summary of all of the options to `configure', and exit.
-
-`--help=short'
-`--help=recursive'
- Print a summary of the options unique to this package's
- `configure', and exit. The `short' variant lists options used
- only in the top level, while the `recursive' variant lists options
- also present in any nested packages.
-
-`--version'
-`-V'
- Print the version of Autoconf used to generate the `configure'
- script, and exit.
-
-`--cache-file=FILE'
- Enable the cache: use and save the results of the tests in FILE,
- traditionally `config.cache'. FILE defaults to `/dev/null' to
- disable caching.
-
-`--config-cache'
-`-C'
- Alias for `--cache-file=config.cache'.
-
-`--quiet'
-`--silent'
-`-q'
- Do not print messages saying which checks are being made. To
- suppress all normal output, redirect it to `/dev/null' (any error
- messages will still be shown).
-
-`--srcdir=DIR'
- Look for the package's source code in directory DIR. Usually
- `configure' can determine that directory automatically.
-
-`--prefix=DIR'
- Use DIR as the installation prefix. *note Installation Names::
- for more details, including other options available for fine-tuning
- the installation locations.
-
-`--no-create'
-`-n'
- Run the configure checks, but stop before creating any output
- files.
-
-`configure' also accepts some other, not widely useful, options. Run
-`configure --help' for more details.
-
diff --git a/NEWS b/NEWS
deleted file mode 100644
index e69de29..0000000
diff --git a/autogen.sh b/autogen.sh
deleted file mode 100755
index 4feddf0..0000000
--- a/autogen.sh
+++ /dev/null
@@ -1,9 +0,0 @@
-#!/bin/bash
-
-# exit on errors
-set -e
-
-srcdir=$(dirname $0)
-test -z "$srcdir" && $srcdir=.
-
-autoreconf -ifv $srcdir
diff --git a/cli-tools/lmi/makefile.am b/cli-tools/lmi/makefile.am
deleted file mode 100644
index d09f387..0000000
--- a/cli-tools/lmi/makefile.am
+++ /dev/null
@@ -1 +0,0 @@
-SUBDIRS = shell
\ No newline at end of file
diff --git a/cli-tools/lmi/shell/makefile.am b/cli-tools/lmi/shell/makefile.am
deleted file mode 100644
index bc2b265..0000000
--- a/cli-tools/lmi/shell/makefile.am
+++ /dev/null
@@ -1,28 +0,0 @@
-lmi_PYTHON = \
- __init__.py \
- LMIBaseClient.py \
- LMIBaseObject.py \
- LMIClass.py \
- LMICompleter.py \
- LMIConnection.py \
- LMIConsole.py \
- LMIConstantValues.py \
- LMIDecorators.py \
- LMIExceptions.py \
- LMIFormatter.py \
- LMIIndicationListener.py \
- LMIIndication.py \
- LMIInstanceName.py \
- LMIInstance.py \
- LMIMethod.py \
- LMINamespace.py \
- LMIObjectFactory.py \
- LMIReturnValue.py \
- LMIShellCache.py \
- LMIShellClient.py \
- LMIShellConfig.py \
- LMIShellOptions.py \
- LMISubscription.py \
- LMIUtil.py
-
-lmidir = $(pythondir)/lmi/shell
diff --git a/cli-tools/makefile.am b/cli-tools/makefile.am
deleted file mode 100644
index 75241f9..0000000
--- a/cli-tools/makefile.am
+++ /dev/null
@@ -1,7 +0,0 @@
-SUBDIRS = lmi
-
-bin_SCRIPTS = lmishell
-
-EXTRA_DIST = $(bin_SCRIPTS)
-
-CLEANFILES = $(bin_SCRIPTS)
diff --git a/cli-tools/lmi/shell/LMIBaseObject.py b/cli-tools/setup.py
similarity index 57%
copy from cli-tools/lmi/shell/LMIBaseObject.py
copy to cli-tools/setup.py
index f256a09..fc4bd64 100644
--- a/cli-tools/lmi/shell/LMIBaseObject.py
+++ b/cli-tools/setup.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
+# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@@ -13,21 +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/>.
-# Base class for classes, that are used for tab-completion.
-# Used due to deprecated methods since python 2.2.
+from setuptools import setup
-class LMIBaseObject(object):
- """
- Base class for all LMI wrapper classes. It is useful for rlcompleter
- module.
- """
- # deprecated
- def __methods__(self):
- return []
-
- # deprecated
- def __members__(self):
- return []
-
- def __call__(self):
- pass
+setup(
+ name="openlmi-tools",
+ description="OpenLMI (non)interactive shell",
+ version="0.5",
+ license="GPLv2+",
+ url="http://fedorahosted.org/openlmi/",
+ author="Peter Hatina",
+ author_email="phatina(a)redhat.com",
+ packages=["lmi.shell"],
+ install_requires=["lmi"],
+ data_files=[("/usr/share/man/man1/", ["../man/lmishell.1"])],
+ scripts=["lmishell"]
+)
diff --git a/configure.ac b/configure.ac
deleted file mode 100644
index 4786daa..0000000
--- a/configure.ac
+++ /dev/null
@@ -1,19 +0,0 @@
-AC_PREREQ([2.60])
-AC_INIT([OpenLMI-tools], [0.5], [phatina(a)redhat.com])
-
-AC_CONFIG_MACRO_DIR([m4])
-m4_include([m4/python_module.m4])
-
-AM_INIT_AUTOMAKE([dist-bzip2])
-AM_PATH_PYTHON([2.7])
-
-AC_PYTHON_MODULE([pywbem])
-
-AC_CONFIG_FILES([
- makefile
- man/makefile
- cli-tools/makefile
- cli-tools/lmi/makefile
-])
-
-AC_OUTPUT
diff --git a/m4/python_module.m4 b/m4/python_module.m4
deleted file mode 100644
index bdb0cdf..0000000
--- a/m4/python_module.m4
+++ /dev/null
@@ -1,11 +0,0 @@
-AC_DEFUN([AC_PYTHON_MODULE], [
- AC_MSG_CHECKING(python module: $1)
- python -c "import $1" 2> /dev/null
- if test $? -eq 0; then
- AC_MSG_RESULT(yes)
- else
- AC_MSG_RESULT(no)
- AC_MSG_ERROR(failed to find required module $1)
- exit 1
- fi
-])
diff --git a/makefile.am b/makefile.am
deleted file mode 100644
index 2ec4e9d..0000000
--- a/makefile.am
+++ /dev/null
@@ -1,3 +0,0 @@
-SUBDIRS = \
- man \
- cli-tools
diff --git a/man/makefile.am b/man/makefile.am
deleted file mode 100644
index d776893..0000000
--- a/man/makefile.am
+++ /dev/null
@@ -1 +0,0 @@
-dist_man_MANS = lmishell.1
\ No newline at end of file
10 years, 10 months
[cura-tools] master: move LMICompleter, LMIConsole and LMIShellConfig out of lmishell (4912957)
by phatina@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master
>---------------------------------------------------------------
commit 49129573554b8e8ab984768c0cb42cf87c5bed11
Author: Peter Hatina <phatina(a)redhat.com>
Date: Mon Jul 29 15:49:10 2013 +0200
move LMICompleter, LMIConsole and LMIShellConfig out of lmishell
>---------------------------------------------------------------
cli-tools/lmi/shell/LMICompleter.py | 162 +++++++++++++
cli-tools/lmi/shell/LMIConsole.py | 224 +++++++++++++++++
cli-tools/lmi/shell/LMIShellConfig.py | 86 +++++++
cli-tools/lmi/shell/__init__.py | 2 +
cli-tools/lmi/shell/makefile.am | 3 +
cli-tools/lmishell | 426 +--------------------------------
6 files changed, 481 insertions(+), 422 deletions(-)
diff --git a/cli-tools/lmi/shell/LMICompleter.py b/cli-tools/lmi/shell/LMICompleter.py
new file mode 100644
index 0000000..105cf03
--- /dev/null
+++ b/cli-tools/lmi/shell/LMICompleter.py
@@ -0,0 +1,162 @@
+# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# 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 rlcompleter
+
+from LMIReturnValue import LMIReturnValue
+from LMIConstantValues import LMIConstantValues
+from LMINamespace import LMINamespace
+from LMINamespace import LMINamespaceRoot
+from LMIClass import LMIClass
+from LMIInstance import LMIInstance
+from LMIInstanceName import LMIInstanceName
+from LMIMethod import LMIMethod
+from LMIConnection import LMIConnection
+
+class LMICompleter(rlcompleter.Completer):
+ """
+ This LMIShell completer, which is used in the interactive mode, provides
+ tab-completion for user friendliness.
+ """
+ LMI_CLASSES = (
+ LMINamespace,
+ LMIClass,
+ LMIInstance,
+ LMIInstanceName,
+ LMIMethod,
+ LMIConstantValues,
+ LMIReturnValue
+ )
+
+ def __init__(self, namespace = None):
+ """
+ Constructs a LMICompleter object.
+
+ Arguments:
+ namespace -- dictionary, where to perform a completion. If unspecified, the
+ default namespace where completions are performed is __main__ (technically,
+ __main__.__dict__).
+ """
+ rlcompleter.Completer.__init__(self, namespace)
+ self._last_complete = []
+
+ def __complete_object_methods(self, obj, text):
+ """
+ Returns a list of strings of all object methods.
+
+ Arguments:
+ obj -- an object, on which the method completion is performed
+ text -- string to be completed
+ """
+ result = filter(lambda m: not m.startswith("_") \
+ and callable(getattr(obj, m)) \
+ and m.lower().startswith(text.lower()), dir(obj))
+ return result
+
+ def __complete_object_properties(self, obj, text):
+ """
+ Returns a list of string of all object properties.
+
+ Arguments:
+ obj -- an object, on which the property completion is performed
+ text -- string to be completed
+ """
+ result = filter(lambda m: not m.startswith("_") \
+ and not callable(getattr(obj, m)) \
+ and m.lower().startswith(text.lower()), dir(obj))
+ return result
+
+ def _callable_postfix(self, val, word):
+ """
+ Returns a string with opening parentheses, if the value provided is callable.
+
+ Arguments:
+ val -- object, which is checked, if it is callable
+ word -- modified input string, which has opening parentheses appended
+ """
+ if hasattr(val, '__call__') and not isinstance(val, LMICompleter.LMI_CLASSES):
+ word = word + "("
+ return word
+
+ def complete(self, text, state):
+ """
+ Returns a completed string.
+
+ Arguments:
+ test -- string to be completed.
+ state -- order number of the completion, see rlcompleter
+ """
+ if not text:
+ return ("\t", None)[state]
+ if state > 0:
+ return self._last_complete[state]
+ self._last_complete = []
+ members = text.split(".")
+ if members[0] in self.namespace:
+ 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, LMINamespaceRoot)):
+ for n in expr.namespaces:
+ if n.lower().startswith(to_complete.lower()):
+ self._last_complete.append(cmd + "." + n)
+ methods = [x for x in methods if x not in expr.namespaces]
+ elif isinstance(expr, LMINamespace):
+ for c in expr.classes():
+ if c.lower().startswith(to_complete.lower()):
+ self._last_complete.append(cmd + "." + c)
+ elif isinstance(expr, LMIClass):
+ for v in expr.valuemap_properties():
+ if v.lower().startswith(to_complete.lower()):
+ self._last_complete.append(cmd + "." + v + "Values")
+ elif isinstance(expr, LMIInstance):
+ expr_methods = expr.methods()
+ if expr_methods:
+ if to_complete and to_complete.lower() in "syn":
+ self._last_complete.append(cmd + ".Sync")
+ else:
+ sync_prefix = ""
+ if to_complete.lower().startswith("sync"):
+ sync_prefix = "Sync"
+ to_complete = to_complete[4:]
+ for m in expr_methods:
+ if m.lower().startswith(to_complete.lower()):
+ self._last_complete.append(cmd + "." + sync_prefix + m + "(")
+ to_complete = sync_prefix + to_complete
+ for p in expr.properties():
+ if p.lower().startswith(to_complete.lower()):
+ self._last_complete.append(cmd + "." + p)
+ elif isinstance(expr, LMIInstanceName):
+ for p in expr.key_properties():
+ if p.lower().startswith(to_complete.lower()):
+ self._last_complete.append(cmd + "." + p)
+ elif isinstance(expr, LMIMethod):
+ for p in expr.valuemap_parameters():
+ if p.lower().startswith(to_complete.lower()):
+ self._last_complete.append(cmd + "." + p + "Values")
+ elif isinstance(expr, LMIConstantValues):
+ for v in expr.values():
+ if v.lower().startswith(to_complete.lower()):
+ self._last_complete.append(cmd + "." + v)
+ elif isinstance(expr, LMIReturnValue):
+ for p in expr.properties():
+ if p.lower().startswith(to_complete.lower()):
+ self._last_complete.append(cmd + "." + p)
+ 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)
diff --git a/cli-tools/lmi/shell/LMIConsole.py b/cli-tools/lmi/shell/LMIConsole.py
new file mode 100644
index 0000000..8c4c6da
--- /dev/null
+++ b/cli-tools/lmi/shell/LMIConsole.py
@@ -0,0 +1,224 @@
+# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# 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 sys
+import code
+import readline
+import __builtin__
+
+from LMICompleter import LMICompleter
+from LMIConnection import LMIConnection
+from LMIShellConfig import LMIShellConfig
+from LMIReturnValue import LMIReturnValue
+
+from LMIConnection import connect
+
+from LMIUtil import lmi_set_use_exceptions
+from LMIUtil import lmi_get_use_exceptions
+
+def _lmi_displayhook(o):
+ """
+ LMIShell display hook, which is used, when run in the interactive mode. Prints out a
+ pretty message, when a LMIReturnValue is returned from a function, method call, etc.
+ It is important, that the LMIReturnValue object needs to have a property
+ "use_display_hook" set.
+ """
+ if o is None:
+ return
+ __builtin__._ = None
+ if isinstance(o, LMIReturnValue) and o.use_display_hook:
+ o.use_display_hook = False
+ if (type(o.rval) == int and o.rval in (0, 4096)) or (type(o.rval) == bool and o.rval == True):
+ result_str = "ok"
+ else:
+ result_str = "fail"
+ sys.stdout.write("%s: %s (%s)" % (o.hostname, result_str, str(o.rval)))
+ if o.errorstr:
+ sys.stdout.write(": %s" % o.errorstr)
+ sys.stdout.write("\n")
+ else:
+ print o
+ __builtin__._ = o
+
+sys.displayhook = _lmi_displayhook
+
+def _use_display_sugar(use = True):
+ """
+ Helper function, which controls, if to use display "sugar". That means, if to use LMI
+ display hook for LMIReturnValue.
+ """
+ sys.displayhook = _lmi_displayhook if use else sys.__displayhook__
+
+class LMIConsole(code.InteractiveConsole):
+ """
+ Class representing an interactive console.
+ """
+ SHELL_PS1 = "> "
+ SHELL_PS2 = "... "
+ DEFAULT_LOCALS = {
+ "LMIConnection" : LMIConnection,
+ "use_exceptions" : lmi_set_use_exceptions
+ }
+
+ def __init__(self):
+ """
+ Constructs a LMIConsole object.
+ """
+ # Setup default LMIConsole locals, that are needed
+ # for proper object construction
+ locals = dict(LMIConsole.DEFAULT_LOCALS.items())
+ code.InteractiveConsole.__init__(self, locals)
+
+ # Store configuration
+ config = LMIShellConfig()
+ self._history_file = config.history_file
+ self._history_length = config.history_length
+ self._use_cache = config.use_cache
+ self._use_exceptions = config.use_exceptions
+
+ # Setup LMIShell-wide option, which defines, whether the LMIShell
+ # should propagate caught exceptions, or dump them
+ lmi_set_use_exceptions(self._use_exceptions)
+
+ def setup_completer(self):
+ self._completer = LMICompleter(self.locals)
+ readline.set_completer(self._completer.complete)
+ readline.parse_and_bind("tab: complete")
+
+ def interact(self, locals = None):
+ """
+ Starts the interactive mode.
+
+ Arguments:
+ locals -- dictionary with locals
+ """
+ # Initialize the interpreter
+ if locals is None:
+ locals = {}
+ else:
+ for (k, v) in locals.iteritems():
+ if isinstance(v, LMIConnection):
+ locals[k]._client.interactive = True
+ locals["clear_history"] = self.clear_history
+ locals["use_display_sugar"] = _use_display_sugar
+ locals["connect"] = lambda h, u = "", p = "": connect(h, u, p, True, self._use_cache)
+ self.locals = dict(self.locals.items() + locals.items())
+ self.setup_completer()
+ self.load_history()
+ old_sys_ps1 = ""
+ try:
+ old_sys_ps1 = sys.ps1
+ except AttributeError, e:
+ old_sys_ps1 = ""
+ try:
+ old_sys_ps2 = sys.ps2
+ except AttributeError, e:
+ old_sys_ps2 = ""
+ sys.ps1 = LMIConsole.SHELL_PS1
+ sys.ps2 = LMIConsole.SHELL_PS2
+
+ # Interact
+ more = 0
+ while 1:
+ try:
+ if more:
+ prompt = sys.ps2
+ else:
+ prompt = sys.ps1
+ try:
+ line = self.raw_input(prompt)
+ # Can be None if sys.stdin was redefined
+ encoding = getattr(sys.stdin, "encoding", None)
+ if encoding and not isinstance(line, unicode):
+ line = line.decode(encoding)
+ except EOFError:
+ self.write("\n")
+ break
+ else:
+ more = self.push(line)
+ except KeyboardInterrupt:
+ self.write("\n")
+ self.resetbuffer()
+ more = 0
+ # Cleanup after the interpreter
+ if old_sys_ps1:
+ sys.ps1 = old_sys_ps1
+ if old_sys_ps2:
+ sys.ps2 = old_sys_ps2
+ self.save_history()
+
+ def interpret(self, script_name, script_argv, locals = None):
+ """
+ Interprets a specified script within additional provided locals.
+ There are LMIConsole.DEFAULT_LOCALS present.
+
+ Arguments:
+ script_name -- string containing a script name
+ script_argv -- script CLI arguments
+ locals -- dictionary with locals
+ """
+ # Initialize locals
+ if locals is None:
+ locals = {}
+ else:
+ for (k, v) in locals.iteritems():
+ if isinstance(v, LMIConnection):
+ locals[k]._client.interactive = False
+ locals["connect"] = lambda h, u = "", p = "": connect(h, u, p, False, self._use_cache)
+ self.locals = dict(self.locals.items() + locals.items())
+
+ # Execute the script
+ sys.argv = script_argv
+ exit_code = 0
+ try:
+ execfile(script_name, self.locals)
+ except SystemExit, e:
+ exit_code = e.code
+
+ # Return with exit_code
+ return exit_code
+
+ def load_history(self):
+ """
+ Loads the shell's history from the history file.
+ """
+ if self._history_length == 0 or not os.path.exists(self._history_file):
+ return
+ readline.read_history_file(self._history_file)
+ if self._history_length > 0 and readline.get_current_history_length() > self._history_length:
+ readline.set_history_length(length)
+ readline.write_history_file(self._history_file)
+ readline.read_history_file(self._history_file)
+
+ def save_history(self):
+ """
+ Saves current history of commands into the history file. If the length of history
+ exceeds a maximum history file length, the history will be truncated.
+ """
+ if self._history_length == 0:
+ return
+ elif self._history_length > 0:
+ readline.set_history_length(self._history_length)
+ try:
+ readline.write_history_file(self._history_file)
+ except IOError, e:
+ pass
+
+ def clear_history(self):
+ """
+ Clears the current history.
+ """
+ readline.clear_history()
diff --git a/cli-tools/lmi/shell/LMIShellConfig.py b/cli-tools/lmi/shell/LMIShellConfig.py
new file mode 100644
index 0000000..75cf897
--- /dev/null
+++ b/cli-tools/lmi/shell/LMIShellConfig.py
@@ -0,0 +1,86 @@
+#!/usr/bin/env python
+# Copyright (C) 2012-2013 Peter Hatina <phatina(a)redhat.com>
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# 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 sys
+
+from LMIUtil import lmi_get_item_or_default
+
+class LMIShellConfig(object):
+ """
+ Class representing the shell's configuration. The class is responsible for loading the
+ configuration from the file and provides a unified API to access these settings.
+ """
+ DEFAULT_CONFIG_FILE = "~/.lmishellrc"
+ DEFAULT_HISTORY_FILE = "~/.lmishell_history"
+ DEFAULT_HISTORY_LENGTH = -1
+ DEFAULT_USE_CACHE = True
+ DEFAULT_USE_EXCEPTIONS = False
+
+ def __init__(self):
+ """
+ Constructs a LMIShellConfig object and loads the configuration from the
+ file. If there is no such file, the shell's configuration properties are set to
+ default values. Configuration file uses python syntax. If there is a syntax error
+ in the configuration file, the properties are set to default values, as well.
+ """
+ try:
+ conf = {}
+ execfile(os.path.expanduser(LMIShellConfig.DEFAULT_CONFIG_FILE), conf)
+ self._history_file = os.path.expanduser(lmi_get_item_or_default(conf, "history_file",
+ LMIShellConfig.DEFAULT_HISTORY_FILE))
+ self._history_length = lmi_get_item_or_default(conf, "history_length",
+ LMIShellConfig.DEFAULT_HISTORY_LENGTH)
+ self._use_cache = lmi_get_item_or_default(conf, "use_cache",
+ LMIShellConfig.DEFAULT_USE_CACHE)
+ self._use_exceptions = lmi_get_item_or_default(conf, "use_exceptions",
+ LMIShellConfig.DEFAULT_USE_EXCEPTIONS)
+ except (SyntaxError, IOError), e:
+ if isinstance(e, SyntaxError):
+ sys.stderr.write("Error: %s\n" % e)
+ self._history_file = os.path.expanduser(LMIShellConfig.DEFAULT_HISTORY_FILE)
+ self._history_length = LMIShellConfig.DEFAULT_HISTORY_LENGTH
+ self._use_cache = LMIShellConfig.DEFAULT_USE_CACHE
+ self._use_exceptions = LMIShellConfig.DEFAULT_USE_EXCEPTIONS
+
+ @property
+ def history_file(self):
+ """
+ Property returning a string containing the shell's history file.
+ """
+ return self._history_file
+
+ @property
+ def history_length(self):
+ """
+ Property returning a number with the shell's history file length.
+ """
+ return self._history_length
+
+ @property
+ def use_cache(self):
+ """
+ Property returning a bool flag, if the shell should use cache for class retrieval.
+ """
+ return self._use_cache
+
+ @property
+ def use_exceptions(self):
+ """
+ Property returning a bool flag, if the shell should dump the exceptions, or if
+ they should be propagated further.
+ """
+ return self._use_exceptions
diff --git a/cli-tools/lmi/shell/__init__.py b/cli-tools/lmi/shell/__init__.py
index 11c6e16..aaaa34e 100644
--- a/cli-tools/lmi/shell/__init__.py
+++ b/cli-tools/lmi/shell/__init__.py
@@ -18,6 +18,7 @@
LMIShell
"""
+from LMIConsole import LMIConsole
from LMIExceptions import *
from LMIUtil import LMIPassByRef
from LMIIndication import LMIIndication
@@ -25,6 +26,7 @@ from LMIIndicationListener import LMIIndicationListener
from LMIReturnValue import LMIReturnValue
from LMIBaseClient import LMIBaseClient
from LMIShellClient import LMIShellClient
+from LMIShellConfig import LMIShellConfig
from LMIShellOptions import LMIShellOptions
from LMISubscription import LMISubscription
from LMINamespace import LMINamespace
diff --git a/cli-tools/lmi/shell/makefile.am b/cli-tools/lmi/shell/makefile.am
index 9e09fe3..bc2b265 100644
--- a/cli-tools/lmi/shell/makefile.am
+++ b/cli-tools/lmi/shell/makefile.am
@@ -3,7 +3,9 @@ lmi_PYTHON = \
LMIBaseClient.py \
LMIBaseObject.py \
LMIClass.py \
+ LMICompleter.py \
LMIConnection.py \
+ LMIConsole.py \
LMIConstantValues.py \
LMIDecorators.py \
LMIExceptions.py \
@@ -18,6 +20,7 @@ lmi_PYTHON = \
LMIReturnValue.py \
LMIShellCache.py \
LMIShellClient.py \
+ LMIShellConfig.py \
LMIShellOptions.py \
LMISubscription.py \
LMIUtil.py
diff --git a/cli-tools/lmishell b/cli-tools/lmishell
index 92b34ea..c1673ab 100755
--- a/cli-tools/lmishell
+++ b/cli-tools/lmishell
@@ -14,24 +14,11 @@
# 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 sys
-import code
-import copy
-import pywbem
-import readline
-import rlcompleter
-import __builtin__
-from lmi.shell import LMIReturnValue
-from lmi.shell import LMIConstantValues
+
+from lmi.shell import LMIConsole
+from lmi.shell import LMIShellConfig
from lmi.shell import LMIShellOptions
-from lmi.shell import LMINamespace
-from lmi.shell import LMINamespaceRoot
-from lmi.shell import LMIClass
-from lmi.shell import LMIInstance
-from lmi.shell import LMIInstanceName
-from lmi.shell import LMIMethod
-from lmi.shell import LMIConnection
from lmi.shell import connect
@@ -39,410 +26,6 @@ from lmi.shell.LMIUtil import lmi_get_use_exceptions
from lmi.shell.LMIUtil import lmi_set_use_exceptions
from lmi.shell.LMIUtil import lmi_get_item_or_default
-def _lmi_displayhook(o):
- """
- LMIShell display hook, which is used, when run in the interactive mode. Prints out a
- pretty message, when a LMIReturnValue is returned from a function, method call, etc.
- It is important, that the LMIReturnValue object needs to have a property
- "use_display_hook" set.
- """
- if o is None:
- return
- __builtin__._ = None
- if isinstance(o, LMIReturnValue) and o.use_display_hook:
- o.use_display_hook = False
- if (type(o.rval) == int and o.rval in (0, 4096)) or (type(o.rval) == bool and o.rval == True):
- result_str = "ok"
- else:
- result_str = "fail"
- sys.stdout.write("%s: %s (%s)" % (o.hostname, result_str, str(o.rval)))
- if o.errorstr:
- sys.stdout.write(": %s" % o.errorstr)
- sys.stdout.write("\n")
- else:
- print o
- __builtin__._ = o
-
-sys.displayhook = _lmi_displayhook
-
-class LMICompleter(rlcompleter.Completer):
- """
- This LMIShell completer, which is used in the interactive mode, provides
- tab-completion for user friendliness.
- """
- LMI_CLASSES = (
- LMINamespace,
- LMIClass,
- LMIInstance,
- LMIInstanceName,
- LMIMethod,
- LMIConstantValues,
- LMIReturnValue
- )
-
- def __init__(self, namespace = None):
- """
- Constructs a LMICompleter object.
-
- Arguments:
- namespace -- dictionary, where to perform a completion. If unspecified, the
- default namespace where completions are performed is __main__ (technically,
- __main__.__dict__).
- """
- rlcompleter.Completer.__init__(self, namespace)
- self._last_complete = []
-
- def __complete_object_methods(self, obj, text):
- """
- Returns a list of strings of all object methods.
-
- Arguments:
- obj -- an object, on which the method completion is performed
- text -- string to be completed
- """
- result = filter(lambda m: not m.startswith("_") \
- and callable(getattr(obj, m)) \
- and m.lower().startswith(text.lower()), dir(obj))
- return result
-
- def __complete_object_properties(self, obj, text):
- """
- Returns a list of string of all object properties.
-
- Arguments:
- obj -- an object, on which the property completion is performed
- text -- string to be completed
- """
- result = filter(lambda m: not m.startswith("_") \
- and not callable(getattr(obj, m)) \
- and m.lower().startswith(text.lower()), dir(obj))
- return result
-
- def _callable_postfix(self, val, word):
- """
- Returns a string with opening parentheses, if the value provided is callable.
-
- Arguments:
- val -- object, which is checked, if it is callable
- word -- modified input string, which has opening parentheses appended
- """
- if hasattr(val, '__call__') and not isinstance(val, LMICompleter.LMI_CLASSES):
- word = word + "("
- return word
-
- def complete(self, text, state):
- """
- Returns a completed string.
-
- Arguments:
- test -- string to be completed.
- state -- order number of the completion, see rlcompleter
- """
- if not text:
- return ("\t", None)[state]
- if state > 0:
- return self._last_complete[state]
- self._last_complete = []
- members = text.split(".")
- if members[0] in self.namespace:
- 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)
- # TODO: remove the if
- if 0:
- print ""
- print cmd
- print to_complete
- print methods
- print properties
- print ""
- if isinstance(expr, (LMIConnection, LMINamespaceRoot)):
- for n in expr.namespaces:
- if n.lower().startswith(to_complete.lower()):
- self._last_complete.append(cmd + "." + n)
- methods = [x for x in methods if x not in expr.namespaces]
- elif isinstance(expr, LMINamespace):
- for c in expr.classes():
- if c.lower().startswith(to_complete.lower()):
- self._last_complete.append(cmd + "." + c)
- elif isinstance(expr, LMIClass):
- for v in expr.valuemap_properties():
- if v.lower().startswith(to_complete.lower()):
- self._last_complete.append(cmd + "." + v + "Values")
- elif isinstance(expr, LMIInstance):
- expr_methods = expr.methods()
- if expr_methods:
- if to_complete and to_complete.lower() in "syn":
- self._last_complete.append(cmd + ".Sync")
- else:
- sync_prefix = ""
- if to_complete.lower().startswith("sync"):
- sync_prefix = "Sync"
- to_complete = to_complete[4:]
- for m in expr_methods:
- if m.lower().startswith(to_complete.lower()):
- self._last_complete.append(cmd + "." + sync_prefix + m + "(")
- to_complete = sync_prefix + to_complete
- for p in expr.properties():
- if p.lower().startswith(to_complete.lower()):
- self._last_complete.append(cmd + "." + p)
- elif isinstance(expr, LMIInstanceName):
- for p in expr.key_properties():
- if p.lower().startswith(to_complete.lower()):
- self._last_complete.append(cmd + "." + p)
- elif isinstance(expr, LMIMethod):
- for p in expr.valuemap_parameters():
- if p.lower().startswith(to_complete.lower()):
- self._last_complete.append(cmd + "." + p + "Values")
- elif isinstance(expr, LMIConstantValues):
- for v in expr.values():
- if v.lower().startswith(to_complete.lower()):
- self._last_complete.append(cmd + "." + v)
- elif isinstance(expr, LMIReturnValue):
- for p in expr.properties():
- if p.lower().startswith(to_complete.lower()):
- self._last_complete.append(cmd + "." + p)
- 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 LMIInteractiveShellConfig(object):
- """
- Class representing the shell's configuration. The class is responsible for loading the
- configuration from the file and provides a unified API to access these settings.
- """
- DEFAULT_CONFIG_FILE = "~/.lmishellrc"
- DEFAULT_HISTORY_FILE = "~/.lmishell_history"
- DEFAULT_HISTORY_LENGTH = -1
- DEFAULT_USE_CACHE = True
- DEFAULT_USE_EXCEPTIONS = False
-
- def __init__(self):
- """
- Constructs a LMIInteractiveShellConfig object and loads the configuration from the
- file. If there is no such file, the shell's configuration properties are set to
- default values. Configuration file uses python syntax. If there is a syntax error
- in the configuration file, the properties are set to default values, as well.
- """
- try:
- conf = {}
- execfile(os.path.expanduser(LMIInteractiveShellConfig.DEFAULT_CONFIG_FILE), conf)
- self._history_file = os.path.expanduser(lmi_get_item_or_default(conf, "history_file",
- LMIInteractiveShellConfig.DEFAULT_HISTORY_FILE))
- self._history_length = lmi_get_item_or_default(conf, "history_length",
- LMIInteractiveShellConfig.DEFAULT_HISTORY_LENGTH)
- self._use_cache = lmi_get_item_or_default(conf, "use_cache",
- LMIInteractiveShellConfig.DEFAULT_USE_CACHE)
- self._use_exceptions = lmi_get_item_or_default(conf, "use_exceptions",
- LMIInteractiveShellConfig.DEFAULT_USE_EXCEPTIONS)
- except (SyntaxError, IOError), e:
- if isinstance(e, SyntaxError):
- sys.stderr.write("Error: %s\n" % e)
- self._history_file = os.path.expanduser(LMIInteractiveShellConfig.DEFAULT_HISTORY_FILE)
- self._history_length = LMIInteractiveShellConfig.DEFAULT_HISTORY_LENGTH
- self._use_cache = LMIInteractiveShellConfig.DEFAULT_USE_CACHE
- self._use_exceptions = LMIInteractiveShellConfig.DEFAULT_USE_EXCEPTIONS
-
- @property
- def history_file(self):
- """
- Property returning a string containing the shell's history file.
- """
- return self._history_file
-
- @property
- def history_length(self):
- """
- Property returning a number with the shell's history file length.
- """
- return self._history_length
-
- @property
- def use_cache(self):
- """
- Property returning a bool flag, if the shell should use cache for class retrieval.
- """
- return self._use_cache
-
- @property
- def use_exceptions(self):
- """
- Property returning a bool flag, if the shell should dump the exceptions, or if
- they should be propagated further.
- """
- return self._use_exceptions
-
-class LMIInteractiveShell(code.InteractiveConsole):
- """
- Class representing an interactive console.
- """
- SHELL_PS1 = "> "
- SHELL_PS2 = "... "
- DEFAULT_LOCALS = {
- "LMIConnection" : LMIConnection,
- "use_exceptions" : lmi_set_use_exceptions
- }
-
- def __init__(self):
- """
- Constructs a LMIInteractiveShell object.
- """
- # Setup default LMIInteractiveShell locals, that are needed
- # for proper object construction
- locals = dict(LMIInteractiveShell.DEFAULT_LOCALS.items())
- code.InteractiveConsole.__init__(self, locals)
-
- # Store configuration
- config = LMIInteractiveShellConfig()
- self._history_file = config.history_file
- self._history_length = config.history_length
- self._use_cache = config.use_cache
- self._use_exceptions = config.use_exceptions
-
- # Setup LMIShell-wide option, which defines, whether the LMIShell
- # should propagate caught exceptions, or dump them
- lmi_set_use_exceptions(self._use_exceptions)
-
- def setup_completer(self):
- self._completer = LMICompleter(self.locals)
- readline.set_completer(self._completer.complete)
- readline.parse_and_bind("tab: complete")
-
- def interact(self, locals = None):
- """
- Starts the interactive mode.
-
- Arguments:
- locals -- dictionary with locals
- """
- # Initialize the interpreter
- if locals is None:
- locals = {}
- else:
- for (k, v) in locals.iteritems():
- if isinstance(v, LMIConnection):
- locals[k]._client.interactive = True
- locals["clear_history"] = self.clear_history
- locals["use_display_sugar"] = _use_display_sugar
- locals["connect"] = lambda h, u = "", p = "": connect(h, u, p, True, self._use_cache)
- self.locals = dict(self.locals.items() + locals.items())
- self.setup_completer()
- self.load_history()
- old_sys_ps1 = ""
- try:
- old_sys_ps1 = sys.ps1
- except AttributeError, e:
- old_sys_ps1 = ""
- try:
- old_sys_ps2 = sys.ps2
- except AttributeError, e:
- old_sys_ps2 = ""
- sys.ps1 = LMIInteractiveShell.SHELL_PS1
- sys.ps2 = LMIInteractiveShell.SHELL_PS2
-
- # Interact
- more = 0
- while 1:
- try:
- if more:
- prompt = sys.ps2
- else:
- prompt = sys.ps1
- try:
- line = self.raw_input(prompt)
- # Can be None if sys.stdin was redefined
- encoding = getattr(sys.stdin, "encoding", None)
- if encoding and not isinstance(line, unicode):
- line = line.decode(encoding)
- except EOFError:
- self.write("\n")
- break
- else:
- more = self.push(line)
- except KeyboardInterrupt:
- self.write("\n")
- self.resetbuffer()
- more = 0
- # Cleanup after the interpreter
- if old_sys_ps1:
- sys.ps1 = old_sys_ps1
- if old_sys_ps2:
- sys.ps2 = old_sys_ps2
- self.save_history()
-
- def interpret(self, script_name, script_argv, locals = None):
- """
- Interprets a specified script within additional provided locals.
- There are LMIInteractiveShell.DEFAULT_LOCALS present.
-
- Arguments:
- script_name -- string containing a script name
- script_argv -- script CLI arguments
- locals -- dictionary with locals
- """
- # Initialize locals
- if locals is None:
- locals = {}
- else:
- for (k, v) in locals.iteritems():
- if isinstance(v, LMIConnection):
- locals[k]._client.interactive = False
- locals["connect"] = lambda h, u = "", p = "": connect(h, u, p, False, self._use_cache)
- self.locals = dict(self.locals.items() + locals.items())
-
- # Execute the script
- sys.argv = script_argv
- exit_code = 0
- try:
- execfile(script_name, self.locals)
- except SystemExit, e:
- exit_code = e.code
-
- # Return with exit_code
- return exit_code
-
- def load_history(self):
- """
- Loads the shell's history from the history file.
- """
- if self._history_length == 0 or not os.path.exists(self._history_file):
- return
- readline.read_history_file(self._history_file)
- if self._history_length > 0 and readline.get_current_history_length() > self._history_length:
- readline.set_history_length(length)
- readline.write_history_file(self._history_file)
- readline.read_history_file(self._history_file)
-
- def save_history(self):
- """
- Saves current history of commands into the history file. If the length of history
- exceeds a maximum history file length, the history will be truncated.
- """
- if self._history_length == 0:
- return
- elif self._history_length > 0:
- readline.set_history_length(self._history_length)
- try:
- readline.write_history_file(self._history_file)
- except IOError, e:
- pass
-
- def clear_history(self):
- """
- Clears the current history.
- """
- readline.clear_history()
-
-def _use_display_sugar(use = True):
- """
- Helper function, which controls, if to use display "sugar". That means, if to use LMI
- display hook for LMIReturnValue.
- """
- sys.displayhook = _lmi_displayhook if use else sys.__displayhook__
-
if __name__ == "__main__":
options = LMIShellOptions(sys.argv)
if not options.good:
@@ -454,9 +37,8 @@ if __name__ == "__main__":
options.print_usage()
sys.exit(0)
- console = LMIInteractiveShell()
+ console = LMIConsole()
if options.interactive:
- console = LMIInteractiveShell()
console.interact()
else:
script_name = options.script_name
10 years, 10 months
[cura-tools] master: huge code change (af62716)
by phatina@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master
>---------------------------------------------------------------
commit af62716e5bb67d75380d648f85e0cc3048d72358
Author: Peter Hatina <phatina(a)redhat.com>
Date: Mon Jul 29 14:48:44 2013 +0200
huge code change
LMIShell is the only main CLI tool held in the repository. There was pretty big code split and cleanup performed.
>---------------------------------------------------------------
Diff suppressed because of size. To see it, use:
git diff --patch-with-stat --no-color --find-copies-harder --ignore-space-at-eol ^af62716e5bb67d75380d648f85e0cc3048d72358~1 af62716e5bb67d75380d648f85e0cc3048d72358
10 years, 10 months
[cura-tools] master: add doc string for man page generator (c264af5)
by phatina@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master
>---------------------------------------------------------------
commit c264af5632215274af6b5872f67fa998859e6869
Author: Peter Hatina <phatina(a)redhat.com>
Date: Wed Jul 24 09:44:29 2013 +0200
add doc string for man page generator
>---------------------------------------------------------------
util/man-page-generator/generate_man_page | 8 ++++++++
1 files changed, 8 insertions(+), 0 deletions(-)
diff --git a/util/man-page-generator/generate_man_page b/util/man-page-generator/generate_man_page
index 3887cd5..1c039da 100755
--- a/util/man-page-generator/generate_man_page
+++ b/util/man-page-generator/generate_man_page
@@ -106,6 +106,14 @@ def reformat_line(line):
return (False, line)
def generate(stream):
+ """
+ Man page content generator. This function fetches the wiki page contant,
+ transforms retrieved formatting marks into troff marks and outputs the
+ reformatted wiki content into the provided stream.
+
+ Arguments:
+ stream -- stream object, where the content will be typeset
+ """
# Print out man page header
stream.write("%s\n" % man_page_header)
10 years, 10 months
[cura-tools] master: drop obselete documentation for example scripts (79f7fae)
by phatina@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master
>---------------------------------------------------------------
commit 79f7faeaacae9d03ad17896aadcfeac1b73e7881
Author: Peter Hatina <phatina(a)redhat.com>
Date: Wed Jul 24 09:40:25 2013 +0200
drop obselete documentation for example scripts
>---------------------------------------------------------------
README | 157 +---------------------------------------------------------------
1 files changed, 2 insertions(+), 155 deletions(-)
diff --git a/README b/README
index 65f9b58..cb688ad 100644
--- a/README
+++ b/README
@@ -13,29 +13,7 @@ bindings, standard APIs, and standard scripting interfaces.
* OpenLMI-tools *
*******************************************************************************
-OpenLMI-tools is a set of command line tools for OpenLMI-providers.
-
-Following cli tools are part of this sub-project:
-
-* lmiservice
- This tool provides remote service management. Supported operations with
- services are: start, stop, restart, enable, disable, reload, try-restart,
- cond-restart, reload-or-restart and status.
-
-* lmipower
- This tool provides remote power management. Supported operations with
- remote machine are: poweroff, reboot, suspend, hibernate, force-poweroff,
- force-reboot.
-
-* lmiuser
- This tool provides remote user management. Currently supported operations
- are: list-users, list-groups, group-members (list of groups, where
- the specified user belongs to), useradd.
-
-* lmiip
- This tool provides remote networking management. Currently it provides
- following operations: set static ip address, remove address assigned
- to an interface, list ip address setting for all/selected interface.
+OpenLMI-tools currently contains lmishell (non)interactive command interpreter.
* lmishell
This tool provides interactive shell for CIM objects management.
@@ -62,135 +40,4 @@ $ ../configure --prefix=/usr
* Example usage *
*******************************************************************************
-Following examples show, how to use command-line tools:
-
-* lmiservice
- $ lmiservice -h <hostname> -u <username> -p <password> status <service_name>
- $ lmiservice -h <hostname> -u <username> -p <password> start <service_name>
- $ lmiservice -h <hostname> -u <username> -p <password> stop <service_name>
-
-* lmipower
- $ lmipower -h <hostname> -u <username> -p <password> poweroff
- $ lmipower -h <hostname> -u <username> -p <password> reboot
-
-* lmiuser
- $ lmiuser -h <hostname> -u <username> -p <password> list-users
- $ lmiuser -h <hostname> -u <username> -p <password> list-groups
- $ lmiuser -h <hostname> -u <username> -p <password> group-members <group_name>
-
-* lmiip
- $ lmiip -h <hostname> -u <username> -p <password> addr show
- - shows available network interfaces and their associated addresses
- $ lmiip -h <hostname> -u <username> -p <password> addr set <address>/<mask> dev <device_name>
- - sets the ipv4 address to specified interface
- $ lmiip -h <hostname> -u <username> -p <password> addr
-
-* lmi-shell
- - general usage example:
- - how to start a shell:
- $ lmishell
- >
-
- - 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:
- $ lmishell
- > c = connect("hostname", "username", "password")
- > service = c.root.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:
- $ lmishell
- > c = connect("hostname", "username", "password")
- > lmi_service = c.root.cimv2.LMI_Service
- > lmi_service.doc()
- ... class documentation ...
- <q>
- > <ctrl+d>
- $
-
- -example how to show an instance documentation with properties:
- $ lmishell
- > c = connect("hostname", "username", "password")
- > service = c.root.cimv2.LMI_Service.first_instance()
- > service.doc()
- ... instance documentation with properties ...
- > <ctrl+d>
- $
-
- - example how to print available namespaces, classes, methods, etc
- $ lmishell
- > c = connect("hostname", "username", "password")
- > c.print_namespaces()
- root
- > c.root.print_namespaces()
- cimv2
- interop
- PG_InterOp
- PG_Internal
- > c.root.cimv2.print_classes()
- ... available classes ...
- > service = c.root.cimv2.LMI_Service.first_instance()
- > service.print_methods()
- ... instance methods ...
- > service.print_properties()
- ... instance properties ...
- > <ctrl+d>
- $
-
- - example how to get associated objects with an instance
- $ lmishell
- > c = connect("hostname", "username", "password")
- > instance = c.root.cimv2.LMI_Group.first_instance()
- > associated_objects = instance.associators()
- > <ctrl+d>
- $
- - example how to get association objects with an instance
- $ lmishell
- > c = connect("hostname", "username", "password")
- > os = c.root.cimv2.Linux_OperatingSystem.first_instance()
- > association_objects = os.references()
- > <ctrl+d>
-
- - example how to update an object property value
- $ lmishell
- > c = connect("hostname", "username", "password")
- > user = c.root.cimv2.LMI_Account.first_instance()
- > user.LoginShell = "/usr/bin/zsh"
- > user.push()
- > <ctrl+d>
- $
-
- - example how to delete an instance from CIM broker
- $ lmishell
- > c = connect("hostname", "username", "password")
- > instance = c.root.cimv2.LMI_Account.first_instance()
- > instance.delete()
- > <ctrl+d>
- $
+See man/lmishell.1 manual page.
10 years, 10 months
[cura-tools] master: fix typos in man page (445873d)
by phatina@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master
>---------------------------------------------------------------
commit 445873d813e40917662529da4f28931293bcaa30
Author: Peter Hatina <phatina(a)redhat.com>
Date: Wed Jul 24 09:31:10 2013 +0200
fix typos in man page
>---------------------------------------------------------------
man/lmishell.1 | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/man/lmishell.1 b/man/lmishell.1
index 7790749..edc5495 100644
--- a/man/lmishell.1
+++ b/man/lmishell.1
@@ -380,7 +380,7 @@ To get association instance names, run following:
.SH INDICATIONS
Indication is a reaction to some specific event that occurs in response to a
change to a particular change in data. LMIShell can perform a indication
-subcription, by which we can receive such event responses.
+subscription, by which we can receive such event responses.
.SS SUBSCRIBING TO AN INDICATION
The shell is capable of creating an indication subscription with the filter
and handler objects in one single step. This example is based upon sblim-cmpi-
@@ -447,7 +447,7 @@ user specific; those arguments need to be specified, when adding a handler to
the listener. In the example, there is a special string used in the
`.add_handler()` call; note the eight "X" characters. Those characters will be
replaced by random string, which is generated by the listeners to avoid
-handler name clasing. If you want to use that random-based string, start
+handler name clashing. If you want to use that random-based string, start
indication listener first, then subscribe to an indication, so the
\fBDestination\fR property of a handler object contains `<schema>://<hostname
>/<random-based string>`.
10 years, 10 months
[cura-tools] master: introduce man page generator (b3e5613)
by phatina@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master
>---------------------------------------------------------------
commit b3e561348f1c8aa9d9ccacabfda6ec0fdd55ccb4
Author: Peter Hatina <phatina(a)redhat.com>
Date: Tue Jul 23 22:38:27 2013 +0200
introduce man page generator
The man page generator fetches the content from https://fedorahosted.org/openlmi/wiki/shell
>---------------------------------------------------------------
util/man-page-generator/README.md | 15 +++
util/man-page-generator/generate_man_page | 148 +++++++++++++++++++++++++++++
2 files changed, 163 insertions(+), 0 deletions(-)
diff --git a/util/man-page-generator/README.md b/util/man-page-generator/README.md
new file mode 100644
index 0000000..422bb34
--- /dev/null
+++ b/util/man-page-generator/README.md
@@ -0,0 +1,15 @@
+# Introduction
+`generate_man_page` is a simplistic tool, which generates a manual page for LMIShell by
+fetching wiki pages from [LMIShell wiki](https://fedorahosted.org/openlmi/wiki/shell).
+
+# Requirements
+To make the generator run, you need to have a `html2text` python module installed. This
+module is not considered as a project dependency and will not autogenerate the man
+page at each `make install` time.
+
+# Usage
+To recreate a manual page for LMIShell, run following command:
+
+```
+$ generate_man_page lmishell.1
+```
diff --git a/util/man-page-generator/generate_man_page b/util/man-page-generator/generate_man_page
new file mode 100755
index 0000000..3887cd5
--- /dev/null
+++ b/util/man-page-generator/generate_man_page
@@ -0,0 +1,148 @@
+#!/usr/bin/env python
+# Copyright (C) 2013 Peter Hatina <phatina(a)redhat.com>
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, see <http://www.gnu.org/licenses/>.
+
+"""
+Man page generator. It uses a set of wiki pages available at
+https://fedorahosted.org/openlmi/wiki/shell.
+
+If run with no command line arguments, the man page will be typeset on stdout; otherwise
+the provided file as a first command line argument will be used.
+"""
+
+import re
+import sys
+import urllib
+try:
+ import html2text
+except ImportError, e:
+ sys.exit(e.message)
+ sys.exit(1)
+
+# Tuple of urls, where the documentation of LMIShell lives.
+wiki_pages = (
+ "https://fedorahosted.org/openlmi/wiki/shell/startup",
+ "https://fedorahosted.org/openlmi/wiki/shell/namespace",
+ "https://fedorahosted.org/openlmi/wiki/shell/class",
+ "https://fedorahosted.org/openlmi/wiki/shell/instance",
+ "https://fedorahosted.org/openlmi/wiki/shell/instance_name",
+ "https://fedorahosted.org/openlmi/wiki/shell/associated_object",
+ "https://fedorahosted.org/openlmi/wiki/shell/association_object",
+ "https://fedorahosted.org/openlmi/wiki/shell/indications",
+ "https://fedorahosted.org/openlmi/wiki/shell/return_values",
+ "https://fedorahosted.org/openlmi/wiki/shell/interactive_interface"
+)
+
+# The page margins from top and bottom. The header and footer are omitted,
+# because they contain fedorahosted.org related stuff, not the LMIShell
+# content.
+page_begin_line = 27
+page_end_line = 17
+# The man page static header with LMIShell Synopsis, Description
+# and command line options.
+man_page_header = \
+""".TH lmishell "1" "July 2013" "openlmi-tools version 0.5" "User Commands"
+.SH NAME
+lmishell \\- (non)interactive WBEM client and interpreter.
+.SH SYNOPSIS
+.B lmishell
+[\\fB\\-i\\fR] [\\fB\\-\\-interact\\fR] script [script-options]
+.SH DESCRIPTION
+lmishell provides a (non)interactive or interactive way how to access CIM
+objects provided by OpenPegasus or sblim-sfcb CIMOM.
+
+OpenLMI Shell is based on a python interpreter and added logic, therefore what
+you can do in pure python, it is possible in LMIShell. There are classes added
+to manipulate with CIM classes, instance names, instances, etc. Additional
+classes are added to fulfill wrapper pattern and expose only those methods,
+which are necessary for the purpose of a shell. Following scheme depicts a
+structure of the OpenLMI Shell.
+.SH OPTIONS
+\\fB\\-h\\fR \\fB\\-\\-help\\fR Print summary of usage, command line options and exit.
+.TP
+\\fB-h\\fR \\fB\\-\\-interact\\fR Enter interactive mode, when the script passed
+as the first positional argument is executed."""
+# The man page static footer containing Authors section.
+man_page_footer = \
+""".SH "AUTHORS"
+.LP
+Peter Hatina <phatina(a)redhat.com>"""
+
+def reformat_line(line):
+ """
+ Helper function for wiki page reformating. It transforms formatting marks,
+ such as #, ##, ### for headings, ** for bold font, etc.
+
+ Returns a reformatted string
+
+ Arguments:
+ line -- string of wiki page line, which will be reformatted
+ """
+ if line.startswith("###"):
+ heading3 = line[4:].upper()
+ return (True, ".TP 4\n.B %s" % heading3)
+ elif line.startswith("##"):
+ heading2 = line[3:].upper()
+ return (True, ".SS %s" % heading2)
+ elif line.startswith("#"):
+ heading1 = line[2:].upper()
+ return (True, ".SH %s" % heading1)
+ if "**" in line:
+ line = re.sub(r"(.*)\*\*(.*)\*\*(.*)", r"\1\\fB\2\\fR\3", line)
+ if "_" in line:
+ line = re.sub(r"\b_([^_]*)_\b", r"\\fB\1\\fR", line)
+ return (False, line)
+
+def generate(stream):
+ # Print out man page header
+ stream.write("%s\n" % man_page_header)
+
+ # Print out reformated wiki pages
+ for page in wiki_pages:
+ url = urllib.urlopen(page)
+ data = url.read().decode("utf8")
+ h = html2text.HTML2Text(baseurl=page)
+ h.ignore_links = True
+ h.ignore_images = True
+ lines = h.handle(data).split("\n")
+
+ empty_lines = 0
+ reformat = False
+ last_reformat = False
+ for line in lines[page_begin_line:-page_end_line]:
+ ls = line.strip()
+ if not ls:
+ empty_lines += 1
+ else:
+ last_reformat = reformat
+ (reformat, ref_line) = reformat_line(line)
+ if empty_lines and not reformat and not last_reformat:
+ stream.write("\n")
+ empty_lines = 0
+ stream.write("%s\n" % ref_line)
+
+ # Print out man page footer
+ stream.write("%s\n" % man_page_footer)
+ stream.close()
+
+if __name__ == "__main__":
+ stream = sys.stdout
+ if len(sys.argv) > 1:
+ try:
+ stream = open(sys.argv[1], "w")
+ except IOError, e:
+ sys.stderr.write(e.message)
+ sys.exit(1)
+ generate(stream)
10 years, 10 months