diff --git a/service-mgmt-api/centos/sm-api.spec b/service-mgmt-api/centos/sm-api.spec index 1aed9d11..ddea7dfd 100644 --- a/service-mgmt-api/centos/sm-api.spec +++ b/service-mgmt-api/centos/sm-api.spec @@ -17,7 +17,7 @@ BuildRequires: util-linux BuildRequires: systemd BuildRequires: systemd-devel Requires: python-libs - +Requires: python-six # Needed for /etc/init.d, can be removed when we go fully systemd Requires: chkconfig # Needed for /etc/pmon.d diff --git a/service-mgmt-api/sm-api/sm_api/objects/utils.py b/service-mgmt-api/sm-api/sm_api/objects/utils.py index c641920b..cd6035dd 100644 --- a/service-mgmt-api/sm-api/sm_api/objects/utils.py +++ b/service-mgmt-api/sm-api/sm_api/objects/utils.py @@ -22,6 +22,7 @@ import ast import datetime import iso8601 import netaddr +import six from sm_api.openstack.common import timeutils @@ -42,7 +43,7 @@ def datetime_or_none(dt): def datetime_or_str_or_none(val): - if isinstance(val, basestring): + if isinstance(val, six.string_types): return timeutils.parse_isotime(val) return datetime_or_none(val) diff --git a/service-mgmt-api/sm-api/sm_api/openstack/common/config/generator.py b/service-mgmt-api/sm-api/sm_api/openstack/common/config/generator.py index 375e2d36..a3b91775 100755 --- a/service-mgmt-api/sm-api/sm_api/openstack/common/config/generator.py +++ b/service-mgmt-api/sm-api/sm_api/openstack/common/config/generator.py @@ -30,7 +30,7 @@ import re import socket import sys import textwrap - +import six from oslo_config import cfg from sm_api.openstack.common import gettextutils @@ -221,7 +221,7 @@ def _print_opt(opt): if opt_default is None: print('#%s=' % opt_name) elif opt_type == STROPT: - assert(isinstance(opt_default, basestring)) + assert(isinstance(opt_default, six.string_types)) print('#%s=%s' % (opt_name, _sanitize_default(opt_default))) elif opt_type == BOOLOPT: assert(isinstance(opt_default, bool)) diff --git a/service-mgmt-api/sm-api/sm_api/openstack/common/jsonutils.py b/service-mgmt-api/sm-api/sm_api/openstack/common/jsonutils.py index 17a27655..38877a96 100644 --- a/service-mgmt-api/sm-api/sm_api/openstack/common/jsonutils.py +++ b/service-mgmt-api/sm-api/sm_api/openstack/common/jsonutils.py @@ -56,7 +56,7 @@ _nasty_type_tests = [inspect.ismodule, inspect.isclass, inspect.ismethod, inspect.iscode, inspect.isbuiltin, inspect.isroutine, inspect.isabstract] -_simple_types = (types.NoneType, int, basestring, bool, float, long) +_simple_types = (types.NoneType, int, six.string_types, bool, float, long) def to_primitive(value, convert_instances=False, convert_datetime=True, diff --git a/service-mgmt-api/sm-api/sm_api/openstack/common/notifier/api.py b/service-mgmt-api/sm-api/sm_api/openstack/common/notifier/api.py index bc5564ec..7df0bc83 100644 --- a/service-mgmt-api/sm-api/sm_api/openstack/common/notifier/api.py +++ b/service-mgmt-api/sm-api/sm_api/openstack/common/notifier/api.py @@ -18,6 +18,7 @@ import uuid +import six from oslo_config import cfg @@ -166,7 +167,7 @@ def add_driver(notification_driver): """Add a notification driver at runtime.""" # Make sure the driver list is initialized. _get_drivers() - if isinstance(notification_driver, basestring): + if isinstance(notification_driver, six.string_types): # Load and add try: driver = importutils.import_module(notification_driver) diff --git a/service-mgmt-api/sm-api/sm_api/openstack/common/policy.py b/service-mgmt-api/sm-api/sm_api/openstack/common/policy.py index ea959767..1f875afd 100644 --- a/service-mgmt-api/sm-api/sm_api/openstack/common/policy.py +++ b/service-mgmt-api/sm-api/sm_api/openstack/common/policy.py @@ -428,7 +428,7 @@ def _parse_list_rule(rule): continue # Handle bare strings - if isinstance(inner_rule, basestring): + if isinstance(inner_rule, six.string_types): inner_rule = [inner_rule] # Parse the inner rules into Check objects @@ -693,7 +693,7 @@ def parse_rule(rule): """ # If the rule is a string, it's in the policy language - if isinstance(rule, basestring): + if isinstance(rule, six.string_types): return _parse_text_rule(rule) return _parse_list_rule(rule) diff --git a/service-mgmt-api/sm-api/sm_api/openstack/common/timeutils.py b/service-mgmt-api/sm-api/sm_api/openstack/common/timeutils.py index c420c2d7..c4771729 100644 --- a/service-mgmt-api/sm-api/sm_api/openstack/common/timeutils.py +++ b/service-mgmt-api/sm-api/sm_api/openstack/common/timeutils.py @@ -25,7 +25,7 @@ Time related utilities and helper functions. import calendar import datetime - +import six import iso8601 @@ -79,14 +79,14 @@ def normalize_time(timestamp): def is_older_than(before, seconds): """Return True if before is older than seconds.""" - if isinstance(before, basestring): + if isinstance(before, six.string_types): before = parse_strtime(before).replace(tzinfo=None) return utcnow() - before > datetime.timedelta(seconds=seconds) def is_newer_than(after, seconds): """Return True if after is newer than seconds.""" - if isinstance(after, basestring): + if isinstance(after, six.string_types): after = parse_strtime(after).replace(tzinfo=None) return after - utcnow() > datetime.timedelta(seconds=seconds) diff --git a/service-mgmt-client/centos/sm-client.spec b/service-mgmt-client/centos/sm-client.spec index 2bb525e0..6d98098b 100644 --- a/service-mgmt-client/centos/sm-client.spec +++ b/service-mgmt-client/centos/sm-client.spec @@ -13,7 +13,7 @@ Source0: %{name}-%{version}.tar.gz BuildRequires: python BuildRequires: python-setuptools Requires: python-libs - +Requires: python-six %prep %setup -q diff --git a/service-mgmt-client/sm-client/sm_client/common/utils.py b/service-mgmt-client/sm-client/sm_client/common/utils.py index 1f4af8a8..1576d8ce 100644 --- a/service-mgmt-client/sm-client/sm_client/common/utils.py +++ b/service-mgmt-client/sm-client/sm_client/common/utils.py @@ -22,8 +22,8 @@ import os import sys import textwrap import uuid - import prettytable +import six from sm_client import exc from sm_client.openstack.common import importutils @@ -134,7 +134,7 @@ def print_mapping(data, fields, dict_property="Property", 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, basestring) and r'\n' in v: + 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: @@ -161,7 +161,7 @@ def print_dict(d, fields, dict_property="Property", 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, basestring) and r'\n' in v: + 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: diff --git a/service-mgmt-client/sm-client/sm_client/openstack/common/config/generator.py b/service-mgmt-client/sm-client/sm_client/openstack/common/config/generator.py index e065adc9..756cd3f7 100644 --- a/service-mgmt-client/sm-client/sm_client/openstack/common/config/generator.py +++ b/service-mgmt-client/sm-client/sm_client/openstack/common/config/generator.py @@ -30,7 +30,7 @@ import re import socket import sys import textwrap - +import six from oslo_config import cfg from sm_client.openstack.common import gettextutils @@ -221,7 +221,7 @@ def _print_opt(opt): if opt_default is None: print('#%s=' % opt_name) elif opt_type == STROPT: - assert(isinstance(opt_default, basestring)) + assert(isinstance(opt_default, six.string_types)) print('#%s=%s' % (opt_name, _sanitize_default(opt_default))) elif opt_type == BOOLOPT: assert(isinstance(opt_default, bool))