Remove six

Because Python 2 support was removed, we no longer need the six
library which is used to make our code compatible with both Python 2
and Python 3.

Change-Id: I9c956ec5623a58fceff6854a878b4b48197c1ff3
This commit is contained in:
Takashi Kajinami 2022-07-01 19:09:45 +09:00
parent 10460e0c14
commit 05de67a535
9 changed files with 23 additions and 32 deletions

View File

@ -13,7 +13,6 @@
# limitations under the License.
import os
import six
import stat
import uuid
import time
@ -76,7 +75,7 @@ class SshTarballTransferMixin(object):
dest = self.recipe_dir[len(self.resource_dir):].lstrip('/')
else:
dest = ''
for marker, recipes in six.iteritems(self._recipes):
for marker, recipes in self._recipes.items():
for path in recipes:
_dest = os.path.join(dest, os.path.basename(path))
pack.add(path, arcname=_dest)
@ -279,7 +278,7 @@ class Drone(object):
logger = logging.getLogger()
skip = skip or []
lastmarker = None
for mark, recipelist in six.iteritems(self._recipes):
for mark, recipelist in self._recipes.items():
if marker and marker != mark:
logger.debug('Skipping marker %s for node %s.' %
(mark, self.node))

View File

@ -17,7 +17,6 @@ Container set for groups and parameters
"""
from ..utils.datastructures import SortedDict
import six
class Parameter(object):
@ -32,7 +31,7 @@ class Parameter(object):
defaults = {}.fromkeys(self.allowed_keys)
defaults.update(attributes)
for key, value in six.iteritems(defaults):
for key, value in defaults.items():
if key not in self.allowed_keys:
raise KeyError('Given attribute %s is not allowed' % key)
self.__dict__[key] = value

View File

@ -11,17 +11,15 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from six.moves import configparser
from six.moves import StringIO
from functools import cmp_to_key
import configparser
import copy
import datetime
from functools import cmp_to_key
import getpass
import logging
from io import StringIO
import os
import re
import six
import sys
import traceback
import types
@ -243,19 +241,19 @@ def mask(input):
output = copy.deepcopy(input)
if isinstance(input, dict):
for key in input:
if isinstance(input[key], six.string_types):
if isinstance(input[key], str):
output[key] = utils.mask_string(input[key],
masked_value_set)
if isinstance(input, list):
for item in input:
org = item
orgIndex = input.index(org)
if isinstance(item, six.string_types):
if isinstance(item, str):
item = utils.mask_string(item, masked_value_set)
if item != org:
output.remove(org)
output.insert(orgIndex, item)
if isinstance(input, six.string_types):
if isinstance(input, str):
output = utils.mask_string(input, masked_value_set)
return output
@ -332,7 +330,7 @@ def _handleGroupCondition(config, conditionName, conditionValue):
# If the condition is a string - just read it to global conf
# We assume that if we get a string as a member it is the name of a member of conf_params
elif isinstance(conditionName, six.string_types):
elif isinstance(conditionName, str):
conditionValue = _loadParamFromFile(config, "general", conditionName)
else:
# Any other type is invalid
@ -548,7 +546,7 @@ def _getConditionValue(matchMember):
returnValue = False
if isinstance(matchMember, types.FunctionType):
returnValue = matchMember(controller.CONF)
elif isinstance(matchMember, six.string_types):
elif isinstance(matchMember, str):
# we assume that if we get a string as a member it is the name
# of a member of conf_params
if matchMember not in controller.CONF:

View File

@ -14,7 +14,6 @@
import re
import os
import six
import logging
import subprocess
@ -38,7 +37,7 @@ def execute(cmd, workdir=None, can_fail=True, mask_list=None,
mask_list = mask_list or []
repl_list = [("'", "'\\''")]
if not isinstance(cmd, six.string_types):
if not isinstance(cmd, str):
import pipes
masked = ' '.join((pipes.quote(i) for i in cmd))
else:
@ -55,9 +54,9 @@ def execute(cmd, workdir=None, can_fail=True, mask_list=None,
env=environ)
out, err = proc.communicate()
if not isinstance(out, six.text_type):
if not isinstance(out, str):
out = out.decode('utf-8')
if not isinstance(err, six.text_type):
if not isinstance(err, str):
err = err.decode('utf-8')
masked_out = mask_string(out, mask_list, repl_list)
masked_err = mask_string(err, mask_list, repl_list)
@ -115,9 +114,9 @@ class ScriptRunner(object):
script = "function t(){ exit $? ; } \n trap t ERR \n %s" % script
out, err = obj.communicate(script.encode('utf-8'))
if not isinstance(out, six.text_type):
if not isinstance(out, str):
out = out.decode('utf-8')
if not isinstance(err, six.text_type):
if not isinstance(err, str):
err = err.decode('utf-8')
masked_out = mask_string(out, mask_list, repl_list)
masked_err = mask_string(err, mask_list, repl_list)

View File

@ -15,11 +15,10 @@
import grp
import os
import pwd
import six
def host_iter(config):
for key, value in six.iteritems(config):
for key, value in config.items():
if key.endswith("_HOST"):
host = value.split('/')[0]
if host:

View File

@ -14,7 +14,6 @@
from functools import cmp_to_key
import re
import six
STR_MASK = '*' * 8
@ -45,7 +44,7 @@ def mask_string(unmasked, mask_list=None, replace_list=None):
mask_list = mask_list or []
replace_list = replace_list or []
if isinstance(unmasked, six.text_type):
if isinstance(unmasked, str):
masked = unmasked.encode('utf-8')
else:
masked = unmasked

View File

@ -5,4 +5,3 @@ docutils>=0.11
pyOpenSSL>=16.2.0
netifaces
distro
six

View File

@ -15,7 +15,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import six
import io
import sys
from unittest import TestCase
@ -29,7 +29,7 @@ class StepTestCase(PackstackTestCaseMixin, TestCase):
def setUp(self):
super(StepTestCase, self).setUp()
self._stdout = sys.stdout
sys.stdout = six.StringIO()
sys.stdout = io.StringIO()
def tearDown(self):
super(StepTestCase, self).tearDown()
@ -57,7 +57,7 @@ class SequenceTestCase(PackstackTestCaseMixin, TestCase):
def setUp(self):
super(SequenceTestCase, self).setUp()
self._stdout = sys.stdout
sys.stdout = six.StringIO()
sys.stdout = io.StringIO()
self.steps = [{'name': '1', 'function': lambda x, y: True,
'title': 'Step 1'},

View File

@ -19,7 +19,6 @@
Test cases for packstack.installer.core.parameters module.
"""
import six
from unittest import TestCase
from ..test_base import PackstackTestCaseMixin
@ -50,7 +49,7 @@ class ParameterTestCase(PackstackTestCaseMixin, TestCase):
initialization
"""
param = Parameter(self.data)
for key, value in six.iteritems(self.data):
for key, value in self.data.items():
self.assertEqual(getattr(param, key), value)
def test_default_attribute(self):
@ -81,7 +80,7 @@ class GroupTestCase(PackstackTestCaseMixin, TestCase):
Test packstack.installer.core.parameters.Group initialization
"""
group = Group(attributes=self.attrs, parameters=self.params)
for key, value in six.iteritems(self.attrs):
for key, value in self.attrs.items():
self.assertEqual(getattr(group, key), value)
for param in self.params:
self.assertIn(param['CONF_NAME'], group.parameters)