Repository : http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master
commit 8466b121a4f32077a1278e2fbe67828d7cd1ab16 Author: Peter Hatina phatina@redhat.com Date: Mon Jun 24 11:04:24 2013 +0200
introduce _LmiInstanceName::key_properties(), ::print_key_properties(), ::key_properties_dict(), ::key_property_value()
cli-tools/lmi/lmi_client_shell.py | 21 +++++++++++++++++++++ cli-tools/lmishell | 4 ++++ 2 files changed, 25 insertions(+), 0 deletions(-)
diff --git a/cli-tools/lmi/lmi_client_shell.py b/cli-tools/lmi/lmi_client_shell.py index 1583a97..6de7273 100644 --- a/cli-tools/lmi/lmi_client_shell.py +++ b/cli-tools/lmi/lmi_client_shell.py @@ -589,6 +589,14 @@ class _LmiInstanceName(BaseObject): self._client = client self._cim_instance_name = cim_instance_name
+ def __getattr__(self, name): + if name in self.__dict__: + return self.__dict__[name] + key_props = self.key_properties() + if key_props and name in key_props: + return self._cim_instance_name[name] + raise AttributeError(name) + def __repr__(self): return "%s(...)" % self.__class__.__name__
@@ -602,6 +610,19 @@ class _LmiInstanceName(BaseObject): lmi_class = _LmiClass(self._client, lmi_namespace, cim_classname) return _LmiInstance(self._client, lmi_class, cim_instance)
+ def key_properties(self): + return self._cim_instance_name.keys() + + def print_key_properties(self): + for name in self._cim_instance_name.keys(): + sys.stdout.write("%s\n" % name) + + def key_properties_dict(self): + return dict(self._cim_instance_name.items()) + + def key_property_value(self, prop_name): + return getattr(self, prop_name) + @property def path(self): return self._cim_instance_name diff --git a/cli-tools/lmishell b/cli-tools/lmishell index 74f4728..1d7009e 100755 --- a/cli-tools/lmishell +++ b/cli-tools/lmishell @@ -168,6 +168,10 @@ class _LmiCompleter(rlcompleter.Completer): 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, LmiReturnValue): for p in expr.properties(): if p.lower().startswith(to_complete.lower()):
cura-tools-devel@lists.fedorahosted.org