summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgordon chung <gord@live.ca>2014-09-29 11:29:47 -0400
committergordon chung <gord@live.ca>2014-09-29 15:38:56 -0400
commit5aa2a69f36c1738d9cc24470e81651732f180859 (patch)
treee5bbd85875cbf85ad8a6538bce1605196d817a5e
parentae69fb0f975c485d14fc039ff4389439aa78e7eb (diff)
downloadpython-ceilometerclient-5aa2a69f36c1738d9cc24470e81651732f180859.tar.gz
switch to oslo.utils
oslo.utils is released and corresponding code in oslo-incubator has been removed. Change-Id: Ic3a13380809a8b00c979e5ac405b4084f486a31d
-rw-r--r--ceilometerclient/common/utils.py23
-rw-r--r--ceilometerclient/shell.py4
-rw-r--r--ceilometerclient/v2/shell.py2
-rw-r--r--openstack-common.conf1
-rw-r--r--requirements.txt1
5 files changed, 15 insertions, 16 deletions
diff --git a/ceilometerclient/common/utils.py b/ceilometerclient/common/utils.py
index a6682f9..288601f 100644
--- a/ceilometerclient/common/utils.py
+++ b/ceilometerclient/common/utils.py
@@ -19,13 +19,13 @@ import sys
import textwrap
import uuid
+from oslo.utils import encodeutils
+from oslo.utils import importutils
import prettytable
import six
from ceilometerclient import exc
from ceilometerclient.openstack.common import cliutils
-from ceilometerclient.openstack.common import importutils
-from ceilometerclient.openstack.common import strutils
# Decorator for cli-args
@@ -84,30 +84,29 @@ def format_nested_list_of_dict(l, column_names):
def print_dict(d, dict_property="Property", wrap=0):
- pt = prettytable.PrettyTable([dict_property, 'Value'],
- caching=False, print_empty=False)
+ pt = prettytable.PrettyTable([dict_property, 'Value'], print_empty=False)
pt.align = 'l'
- for k, v in sorted(six.iteritems(d)):
+ for k, v in six.iteritems(d):
# convert dict to str to check length
if isinstance(v, dict):
v = str(v)
- if isinstance(v, six.string_types):
- v = strutils.safe_encode(v)
+ if wrap > 0:
+ v = textwrap.fill(str(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:
lines = v.strip().split(r'\n')
col1 = k
for line in lines:
- if wrap > 0:
- line = textwrap.fill(str(line), wrap)
pt.add_row([col1, line])
col1 = ''
else:
- if wrap > 0:
- v = textwrap.fill(str(v), wrap)
pt.add_row([k, v])
- print(pt.get_string())
+ encoded = encodeutils.safe_encode(pt.get_string(sortby=dict_property))
+ # FIXME(gordc): https://bugs.launchpad.net/oslo-incubator/+bug/1370710
+ if six.PY3:
+ encoded = encoded.decode()
+ print(encoded)
def find_resource(manager, name_or_id):
diff --git a/ceilometerclient/shell.py b/ceilometerclient/shell.py
index d16dc51..e8f5752 100644
--- a/ceilometerclient/shell.py
+++ b/ceilometerclient/shell.py
@@ -20,6 +20,7 @@ import argparse
import logging
import sys
+from oslo.utils import encodeutils
import six
import ceilometerclient
@@ -27,7 +28,6 @@ from ceilometerclient import client as ceiloclient
from ceilometerclient.common import utils
from ceilometerclient import exc
from ceilometerclient.openstack.common import cliutils
-from ceilometerclient.openstack.common import strutils
class CeilometerShell(object):
@@ -278,7 +278,7 @@ def main(args=None):
if '--debug' in args or '-d' in args:
raise
else:
- print(strutils.safe_encode(six.text_type(e)), file=sys.stderr)
+ print(encodeutils.safe_encode(six.text_type(e)), file=sys.stderr)
sys.exit(1)
if __name__ == "__main__":
diff --git a/ceilometerclient/v2/shell.py b/ceilometerclient/v2/shell.py
index 8ee1149..aa6b4b1 100644
--- a/ceilometerclient/v2/shell.py
+++ b/ceilometerclient/v2/shell.py
@@ -22,11 +22,11 @@ import argparse
import functools
import json
+from oslo.utils import strutils
import six
from ceilometerclient.common import utils
from ceilometerclient import exc
-from ceilometerclient.openstack.common import strutils
from ceilometerclient.v2 import options
diff --git a/openstack-common.conf b/openstack-common.conf
index 34b5196..da77507 100644
--- a/openstack-common.conf
+++ b/openstack-common.conf
@@ -2,7 +2,6 @@
# The list of modules to copy from openstack-common
module=cliutils
-module=importutils
module=install_venv_common
# The base module to hold the copy of openstack.common
diff --git a/requirements.txt b/requirements.txt
index ffc4744..1692306 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -4,6 +4,7 @@
pbr>=0.6,!=0.7,<1.0
argparse
iso8601>=0.1.9
+oslo.utils>=1.0.0 # Apache-2.0
PrettyTable>=0.7,<0.8
python-keystoneclient>=0.10.0
six>=1.7.0