Fix undefined basestring and unicode in py35

In py3 basestring and unicode are no longer valid,
and should use `str` instead. In order to cover
py2 and py3, we change to use six lib to cover both.
Closes-Bug: #1682015

Change-Id: I3159470965e3a20161ff0e997af625b45ebe21fa
This commit is contained in:
ricolin 2017-04-12 14:51:10 +08:00 committed by Rico Lin
parent 1351cc322b
commit e4df67e265
3 changed files with 6 additions and 3 deletions

View File

@ -15,6 +15,7 @@
import json import json
import logging import logging
import os import os
import six
import subprocess import subprocess
import sys import sys
import yaml import yaml
@ -99,7 +100,7 @@ def main(argv=sys.argv):
if key in ['environment', 'volumes', 'volumes_from']: if key in ['environment', 'volumes', 'volumes_from']:
for value in config[container][key]: for value in config[container][key]:
# Somehow the lists get empty values sometimes # Somehow the lists get empty values sometimes
if type(value) is unicode and not value.strip(): if type(value) is six.text_type and not value.strip():
continue continue
cmd.append(docker_arg_map(key, value)) cmd.append(docker_arg_map(key, value))
elif key == 'image': elif key == 'image':

View File

@ -17,6 +17,7 @@ import dpath
import json import json
import logging import logging
import os import os
import six
import subprocess import subprocess
import sys import sys
import yaml import yaml
@ -87,7 +88,7 @@ def main(argv=sys.argv):
for value in dpath.util.values(config, '*/env_file'): for value in dpath.util.values(config, '*/env_file'):
if isinstance(value, list): if isinstance(value, list):
compose_env_files.extend(value) compose_env_files.extend(value)
elif isinstance(value, basestring): elif isinstance(value, six.string_types):
compose_env_files.extend([value]) compose_env_files.extend([value])
input_env_files = {} input_env_files = {}

View File

@ -21,6 +21,7 @@ import subprocess
import sys import sys
import requests import requests
import six
HOOKS_DIR_PATHS = ( HOOKS_DIR_PATHS = (
os.environ.get('HEAT_CONFIG_HOOKS'), os.environ.get('HEAT_CONFIG_HOOKS'),
@ -93,7 +94,7 @@ def invoke_hook(c, log):
hot_inputs = c.get('inputs', []) hot_inputs = c.get('inputs', [])
for hot_input in hot_inputs: for hot_input in hot_inputs:
if hot_input.get('type', None) == 'String' and \ if hot_input.get('type', None) == 'String' and \
not isinstance(hot_input['value'], basestring): not isinstance(hot_input['value'], six.text_type):
hot_input['value'] = str(hot_input['value']) hot_input['value'] = str(hot_input['value'])
iv = dict((i['name'], i['value']) for i in c['inputs']) iv = dict((i['name'], i['value']) for i in c['inputs'])
# The group property indicates whether it is softwarecomponent or # The group property indicates whether it is softwarecomponent or