From 599b2c289321f67c643e8db5009f8472d0d0107d Mon Sep 17 00:00:00 2001 From: Matthew Farrellee Date: Thu, 20 Feb 2014 19:34:43 -0500 Subject: [PATCH] Update oslo-incubator cliutils module Changes - * Use `six.text_type` instead of `str` in cliutils * py3kcompat: remove * Correct docstring in load_plugin_from_args * Removed set_loaded() method from Resource class * Add to_dict() method to apiclient Resource * Deleted duplicated method in cliutils. Change-Id: I87fb4928d5d3e62a2a609f6f5073b3331088ee27 --- .../openstack/common/apiclient/auth.py | 2 +- .../openstack/common/apiclient/base.py | 16 +++++++++------- savannaclient/openstack/common/cliutils.py | 19 ++----------------- 3 files changed, 12 insertions(+), 25 deletions(-) diff --git a/savannaclient/openstack/common/apiclient/auth.py b/savannaclient/openstack/common/apiclient/auth.py index 784e2d84..2f91d664 100644 --- a/savannaclient/openstack/common/apiclient/auth.py +++ b/savannaclient/openstack/common/apiclient/auth.py @@ -76,7 +76,7 @@ def load_plugin_from_args(args): alphabetical order. :type args: argparse.Namespace - :raises: AuthorizationFailure + :raises: AuthPluginOptionsMissing """ auth_system = args.os_auth_system if auth_system: diff --git a/savannaclient/openstack/common/apiclient/base.py b/savannaclient/openstack/common/apiclient/base.py index 7b0872e4..489ae9ff 100644 --- a/savannaclient/openstack/common/apiclient/base.py +++ b/savannaclient/openstack/common/apiclient/base.py @@ -24,6 +24,7 @@ Base utilities to build API operation managers and objects on top of. # pylint: disable=E1102 import abc +import copy import six from six.moves.urllib import parse @@ -456,17 +457,17 @@ class Resource(object): def __getattr__(self, k): if k not in self.__dict__: #NOTE(bcwaldon): disallow lazy-loading if already loaded once - if not self.is_loaded(): - self.get() + if not self.is_loaded: + self._get() return self.__getattr__(k) raise AttributeError(k) else: return self.__dict__[k] - def get(self): - # set_loaded() first ... so if we have to bail, we know we tried. - self.set_loaded(True) + def _get(self): + # set _loaded first ... so if we have to bail, we know we tried. + self._loaded = True if not hasattr(self.manager, 'get'): return @@ -484,8 +485,9 @@ class Resource(object): return self.id == other.id return self._info == other._info + @property def is_loaded(self): return self._loaded - def set_loaded(self, val): - self._loaded = val + def to_dict(self): + return copy.deepcopy(self._info) diff --git a/savannaclient/openstack/common/cliutils.py b/savannaclient/openstack/common/cliutils.py index 8681058b..bdc2ebb6 100644 --- a/savannaclient/openstack/common/cliutils.py +++ b/savannaclient/openstack/common/cliutils.py @@ -30,7 +30,6 @@ from six import moves from savannaclient.openstack.common.apiclient import exceptions from savannaclient.openstack.common.gettextutils import _ -from savannaclient.openstack.common import importutils from savannaclient.openstack.common import strutils from savannaclient.openstack.common import uuidutils @@ -181,9 +180,9 @@ def print_dict(dct, dict_property="Property", wrap=0): for k, v in six.iteritems(dct): # convert dict to str to check length if isinstance(v, dict): - v = str(v) + v = six.text_type(v) if wrap > 0: - v = textwrap.fill(str(v), wrap) + v = textwrap.fill(six.text_type(v), wrap) # if value has a newline, add in multiple rows # e.g. fault with stacktrace if v and isinstance(v, six.string_types) and r'\n' in v: @@ -304,20 +303,6 @@ def pretty_choice_list(l): return ', '.join("'%s'" % i for i in l) -def import_class(import_str): - """Returns a class from a string including module and class.""" - mod_str, _sep, class_str = import_str.rpartition('.') - __import__(mod_str) - return getattr(sys.modules[mod_str], class_str) - - -def import_versioned_module(version, submodule=None): - module = 'savannaclient.v%s' % version - if submodule: - module = '.'.join((module, submodule)) - return importutils.import_module(module) - - def exit(msg=''): if msg: print (msg, file=sys.stderr)