aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBryan Quigley <bryan.quigley@canonical.com>2020-04-08 13:13:25 -0700
committerBryan Quigley <bryan.quigley@canonical.com>2020-04-09 11:22:44 -0700
commit33bcb9a5de0d544abb482e06fc363e57507924b2 (patch)
tree1547bb4fa6add19180d26a3b8597fa34c1b1d6ef
parent902f1269500808c1a780eec46e2dc4f34be876fd (diff)
downloadsos-33bcb9a5de0d544abb482e06fc363e57507924b2.tar.gz
[global] Drop use of python six and other 2.X bits
Resolves: #2006 Signed-off-by: Bryan Quigley <bryan.quigley@canonical.com>
-rw-r--r--setup.py1
-rw-r--r--sos.spec3
-rw-r--r--sos/__init__.py1
-rw-r--r--sos/archive.py5
-rw-r--r--sos/options.py4
-rw-r--r--sos/policies/__init__.py6
-rw-r--r--sos/policies/redhat.py8
-rw-r--r--sos/report/__init__.py8
-rw-r--r--sos/report/plugins/__init__.py58
-rw-r--r--sos/report/plugins/navicli.py4
-rw-r--r--sos/report/plugins/ovn_central.py3
-rw-r--r--sos/report/plugins/xfs.py1
-rw-r--r--sos/report/reporting.py24
-rw-r--r--sos/utilities.py13
-rw-r--r--tests/archive_tests.py5
-rw-r--r--tests/plugin_tests.py9
-rw-r--r--tests/utilities_tests.py7
17 files changed, 40 insertions, 120 deletions
diff --git a/setup.py b/setup.py
index 6eab75a8..c633953b 100644
--- a/setup.py
+++ b/setup.py
@@ -75,7 +75,6 @@ setup(name='sos',
],
packages=['sos', 'sos.report.plugins', 'sos.policies', 'sos.report'],
cmdclass={'build': BuildData, 'install_data': InstallData},
- requires=['six', 'futures'],
)
diff --git a/sos.spec b/sos.spec
index 450ba986..851f10f9 100644
--- a/sos.spec
+++ b/sos.spec
@@ -12,14 +12,11 @@ BuildArch: noarch
Url: https://github.com/sosreport/sos/
BuildRequires: python-devel
BuildRequires: gettext
-BuildRequires: python-six
Requires: libxml2-python
Requires: rpm-python
Requires: tar
Requires: bzip2
Requires: xz
-Requires: python-six
-Requires: python-futures
%description
Sos is a set of tools that gathers information about system
diff --git a/sos/__init__.py b/sos/__init__.py
index 895324f6..05631c59 100644
--- a/sos/__init__.py
+++ b/sos/__init__.py
@@ -17,7 +17,6 @@ gettext to internationalize messages.
__version__ = "3.9"
import logging
-import six
import sys
import tempfile
diff --git a/sos/archive.py b/sos/archive.py
index b53e50ba..ef0ccd99 100644
--- a/sos/archive.py
+++ b/sos/archive.py
@@ -25,11 +25,6 @@ try:
except ImportError:
pass
-# PYCOMPAT
-import six
-if six.PY3:
- long = int
-
P_FILE = "file"
P_LINK = "link"
P_NODE = "node"
diff --git a/sos/options.py b/sos/options.py
index 61e61369..aeabe1ef 100644
--- a/sos/options.py
+++ b/sos/options.py
@@ -69,10 +69,8 @@ class SoSOptions():
# Convert Python source notation for sequences into plain strings
vals = [",".join(v) if _is_seq(v) else v for v in vals]
else:
- def is_string(val):
- return isinstance(val, six.string_types)
# Only quote strings if quote=False
- vals = ["'%s'" % v if is_string(v) else v for v in vals]
+ vals = ["'%s'" % v if isinstance(val, str) else v for v in vals]
return (args % tuple(vals)).strip(sep) + suffix
diff --git a/sos/policies/__init__.py b/sos/policies/__init__.py
index fc6ed055..81f995e7 100644
--- a/sos/policies/__init__.py
+++ b/sos/policies/__init__.py
@@ -19,8 +19,6 @@ from sos.report.plugins import IndependentPlugin, ExperimentalPlugin
from sos.options import SoSOptions
from sos import _sos as _
from textwrap import fill
-from six import print_
-from six.moves import input
from pipes import quote
PRESETS_PATH = "/var/lib/sos/presets"
@@ -825,9 +823,9 @@ any third party.
quiet mode"""
if always or not self.commons['cmdlineopts'].quiet:
if msg:
- print_(msg)
+ print(msg)
else:
- print_()
+ print()
def get_msg(self):
"""This method is used to prepare the preamble text to display to
diff --git a/sos/policies/redhat.py b/sos/policies/redhat.py
index 10a6f653..14ccb31f 100644
--- a/sos/policies/redhat.py
+++ b/sos/policies/redhat.py
@@ -19,14 +19,6 @@ from sos.options import SoSOptions
OS_RELEASE = "/etc/os-release"
-# In python2.7, input() will not properly return strings, and on python3.x
-# raw_input() was renamed to input(). So, if we're running on python2.7, map
-# input() to raw_input() to match the behavior
-try:
- input = raw_input
-except NameError:
- pass
-
class RedHatPolicy(LinuxPolicy):
distro = "Red Hat"
diff --git a/sos/report/__init__.py b/sos/report/__init__.py
index 5285d96f..63c226eb 100644
--- a/sos/report/__init__.py
+++ b/sos/report/__init__.py
@@ -33,10 +33,6 @@ from sos.report.reporting import (Report, Section, Command, CopiedFile,
CreatedFile, Alert, Note, PlainTextReport,
JSONReport, HTMLReport)
-# PYCOMPAT
-import six
-from six.moves import zip, input
-
# file system errors that should terminate a run
fatal_fs_errors = (errno.ENOSPC, errno.EROFS)
@@ -401,7 +397,7 @@ class SoSReport(SoSComponent):
# we are NOT in interactive mode, print the exception...
traceback.print_exception(etype, eval_, etrace, limit=2,
file=sys.stdout)
- six.print_()
+ print()
# ...then start the debugger in post-mortem mode.
pdb.pm()
@@ -411,7 +407,7 @@ class SoSReport(SoSComponent):
(etype, val, tb) = sys.exc_info()
# we are NOT in interactive mode, print the exception...
traceback.print_exception(etype, val, tb, file=sys.stdout)
- six.print_()
+ print()
# ...then start the debugger in post-mortem mode.
pdb.post_mortem(tb)
if plugname and func:
diff --git a/sos/report/plugins/__init__.py b/sos/report/plugins/__init__.py
index 408fe7d9..a7fa9de5 100644
--- a/sos/report/plugins/__init__.py
+++ b/sos/report/plugins/__init__.py
@@ -21,28 +21,8 @@ import logging
import fnmatch
import errno
-# PYCOMPAT
-import six
-from six.moves import zip, filter
from datetime import datetime
-# FileNotFoundError does not exist in 2.7, so map it to IOError
-try:
- FileNotFoundError
-except NameError:
- FileNotFoundError = IOError
-
-
-def _to_u(s):
- if not isinstance(s, six.text_type):
- # Workaround python.six mishandling of strings ending in '\' by
- # adding a single space following any '\' at end-of-line.
- # See Six issue #60.
- if s.endswith('\\'):
- s += " "
- s = six.u(s)
- return s
-
def regex_findall(regex, fname):
"""Return a list of all non overlapping matches in the string(s)"""
@@ -751,7 +731,7 @@ class Plugin(object):
return 0
readable = self.archive.open_file(path)
content = readable.read()
- if not isinstance(content, six.string_types):
+ if not isinstance(content, str):
content = content.decode('utf8', 'ignore')
result, replacements = re.subn(regexp, subst, content)
if replacements:
@@ -946,7 +926,7 @@ class Plugin(object):
"""Specify a path, or list of paths, to not copy, even if it's
part of a copy_specs[] entry.
"""
- if isinstance(forbidden, six.string_types):
+ if isinstance(forbidden, str):
forbidden = [forbidden]
if self.use_sysroot():
@@ -1050,7 +1030,7 @@ class Plugin(object):
if not copyspecs:
return False
- if isinstance(copyspecs, six.string_types):
+ if isinstance(copyspecs, str):
copyspecs = [copyspecs]
for copyspec in copyspecs:
@@ -1172,13 +1152,13 @@ class Plugin(object):
prepend_path=None, whitelist=[], blacklist=[]):
"""Run a command against all specified devices on the system.
"""
- if isinstance(cmds, six.string_types):
+ if isinstance(cmds, str):
cmds = [cmds]
- if isinstance(devices, six.string_types):
+ if isinstance(devices, str):
devices = [devices]
- if isinstance(whitelist, six.string_types):
+ if isinstance(whitelist, str):
whitelist = [whitelist]
- if isinstance(blacklist, six.string_types):
+ if isinstance(blacklist, str):
blacklist = [blacklist]
sizelimit = sizelimit or self.get_option('log_size')
for cmd in cmds:
@@ -1218,7 +1198,7 @@ class Plugin(object):
sizelimit=None, pred=None, subdir=None,
changes=False, foreground=False):
"""Run a program or a list of programs and collect the output"""
- if isinstance(cmds, six.string_types):
+ if isinstance(cmds, str):
cmds = [cmds]
if len(cmds) > 1 and (suggest_filename or root_symlink):
self._log_warn("ambiguous filename or symlink for command list")
@@ -1307,7 +1287,7 @@ class Plugin(object):
# Generate summary string for logging
summary = content.splitlines()[0] if content else ''
- if not isinstance(summary, six.string_types):
+ if not isinstance(summary, str):
summary = content.decode('utf8', 'ignore')
if not self.test_predicate(cmd=False, pred=pred):
@@ -1580,7 +1560,7 @@ class Plugin(object):
:param kwargs Optional arguments to pass to _add_cmd_output
(timeout, predicate, suggest_filename,..)
"""
- if isinstance(services, six.string_types):
+ if isinstance(services, str):
services = [services]
query = self.policy.init_system.query_cmd
@@ -1644,7 +1624,7 @@ class Plugin(object):
log_size = sizelimit or self.get_option("log_size")
log_size = max(log_size, journal_size) if not all_logs else 0
- if isinstance(units, six.string_types):
+ if isinstance(units, str):
units = [units]
if units:
@@ -1704,7 +1684,7 @@ class Plugin(object):
content = ''
if string:
content = string.splitlines()[0]
- if not isinstance(content, six.string_types):
+ if not isinstance(content, str):
content = content.decode('utf8', 'ignore')
self._log_info("collecting string ...'%s' as '%s'"
% (content, file_name))
@@ -1755,19 +1735,19 @@ class Plugin(object):
# some files or packages have been specified for this package
if any([self.files, self.packages, self.commands, self.kernel_mods,
self.services, self.architectures]):
- if isinstance(self.files, six.string_types):
+ if isinstance(self.files, str):
self.files = [self.files]
- if isinstance(self.packages, six.string_types):
+ if isinstance(self.packages, str):
self.packages = [self.packages]
- if isinstance(self.commands, six.string_types):
+ if isinstance(self.commands, str):
self.commands = [self.commands]
- if isinstance(self.kernel_mods, six.string_types):
+ if isinstance(self.kernel_mods, str):
self.kernel_mods = [self.kernel_mods]
- if isinstance(self.services, six.string_types):
+ if isinstance(self.services, str):
self.services = [self.services]
if isinstance(self, SCLPlugin):
@@ -1952,7 +1932,7 @@ class SCLPlugin(RedHatPlugin):
"""Same as add_cmd_output, except that it wraps command in
"scl enable" call and sets proper PATH.
"""
- if isinstance(cmds, six.string_types):
+ if isinstance(cmds, str):
cmds = [cmds]
scl_cmds = []
for cmd in cmds:
@@ -1975,7 +1955,7 @@ class SCLPlugin(RedHatPlugin):
"""Same as add_copy_spec, except that it prepends path to SCL root
to "copyspecs".
"""
- if isinstance(copyspecs, six.string_types):
+ if isinstance(copyspecs, str):
copyspecs = [copyspecs]
scl_copyspecs = []
for copyspec in copyspecs:
diff --git a/sos/report/plugins/navicli.py b/sos/report/plugins/navicli.py
index 4e46c23b..8e5dee50 100644
--- a/sos/report/plugins/navicli.py
+++ b/sos/report/plugins/navicli.py
@@ -13,10 +13,6 @@ from sos.report.plugins import Plugin, RedHatPlugin
from sos.utilities import is_executable
-# Just for completeness sake.
-from six.moves import input
-
-
class Navicli(Plugin, RedHatPlugin):
""" EMC Navicli
"""
diff --git a/sos/report/plugins/ovn_central.py b/sos/report/plugins/ovn_central.py
index 7639bad8..7ccb9f42 100644
--- a/sos/report/plugins/ovn_central.py
+++ b/sos/report/plugins/ovn_central.py
@@ -11,7 +11,6 @@
from sos.report.plugins import Plugin, RedHatPlugin, DebianPlugin, UbuntuPlugin
import json
import os
-import six
class OVNCentral(Plugin):
@@ -48,7 +47,7 @@ class OVNCentral(Plugin):
"Could not open DB schema file %s: %s" % (filename, ex))
return
try:
- return [table for table in six.iterkeys(
+ return [table for table in dict.keys(
db['tables']) if table not in skip]
except AttributeError:
self._log_error("DB schema %s has no 'tables' key" % filename)
diff --git a/sos/report/plugins/xfs.py b/sos/report/plugins/xfs.py
index 454817aa..534399d1 100644
--- a/sos/report/plugins/xfs.py
+++ b/sos/report/plugins/xfs.py
@@ -7,7 +7,6 @@
# See the LICENSE file in the source distribution for further information.
from sos.report.plugins import Plugin, RedHatPlugin, DebianPlugin, UbuntuPlugin
-from six.moves import zip
class Xfs(Plugin, RedHatPlugin, DebianPlugin, UbuntuPlugin):
diff --git a/sos/report/reporting.py b/sos/report/reporting.py
index e6fb17e9..f8e28eb5 100644
--- a/sos/report/reporting.py
+++ b/sos/report/reporting.py
@@ -18,9 +18,6 @@ try:
except ImportError:
import simplejson as json
-# PYCOMPAT
-import six
-
class Node(object):
@@ -53,7 +50,7 @@ class Report(Node):
def _decode(s):
"""returns a string text for a given unicode/str input"""
- return (s if isinstance(s, six.text_type) else s.decode('utf8', 'ignore'))
+ return (s if isinstance(s, str) else s.decode('utf8', 'ignore'))
class Section(Node):
@@ -155,7 +152,7 @@ class PlainTextReport(object):
line_buf = []
def __init__(self, report_node):
- self.report_data = sorted(six.iteritems(report_node.data))
+ self.report_data = sorted(dict.items(report_node.data))
def unicode(self):
self.line_buf = line_buf = []
@@ -186,18 +183,10 @@ class PlainTextReport(object):
if (len(self.FOOTER) > 0):
line_buf.append(self.FOOTER)
- # Workaround python.six mishandling of strings ending in '/' by
- # adding a single space following any '\' at end-of-line.
- # See Six issue #60.
- line_buf = [line + " " if ends_bs(line) else line for line in line_buf]
-
- output = u'\n'.join(map(lambda i: (i if isinstance(i, six.text_type)
+ output = u'\n'.join(map(lambda i: (i if isinstance(i, str)
else i.decode('utf8', 'ignore')),
line_buf))
- if six.PY3:
- return output
- else:
- return output.encode('utf8')
+ return output
def process_subsection(self, section, key, header, format_, footer):
if key in section:
@@ -251,9 +240,6 @@ class JSONReport(PlainTextReport):
def unicode(self):
output = json.dumps(self.report_data, indent=4, ensure_ascii=False)
- if six.PY3:
- return output
- else:
- return output.encode('utf8')
+ return output
# vim: set et ts=4 sw=4 :
diff --git a/sos/utilities.py b/sos/utilities.py
index 24b57d8a..562dde75 100644
--- a/sos/utilities.py
+++ b/sos/utilities.py
@@ -18,13 +18,11 @@ import glob
import tempfile
import threading
import time
+import io
from contextlib import closing
from collections import deque
-# PYCOMPAT
-import six
-
def tail(filename, number_of_bytes):
"""Returns the last number_of_bytes of filename"""
@@ -36,13 +34,13 @@ def tail(filename, number_of_bytes):
def fileobj(path_or_file, mode='r'):
"""Returns a file-like object that can be used as a context manager"""
- if isinstance(path_or_file, six.string_types):
+ if isinstance(path_or_file, str):
try:
return open(path_or_file, mode)
except IOError:
log = logging.getLogger('sos')
log.debug("fileobj: %s could not be opened" % path_or_file)
- return closing(six.StringIO())
+ return closing(io.StringIO())
else:
return closing(path_or_file)
@@ -138,9 +136,6 @@ def sos_get_command_output(command, timeout=300, stderr=False,
command
)
- # shlex.split() reacts badly to unicode on older python runtimes.
- if not six.PY3:
- command = command.encode('utf-8', 'ignore')
args = shlex.split(command)
# Expand arguments that are wildcard paths.
expanded_args = []
@@ -174,7 +169,7 @@ def sos_get_command_output(command, timeout=300, stderr=False,
raise e
if p.returncode == 126 or p.returncode == 127:
- stdout = six.binary_type(b"")
+ stdout = b""
return {
'status': p.returncode,
diff --git a/tests/archive_tests.py b/tests/archive_tests.py
index 8257997d..d890d12f 100644
--- a/tests/archive_tests.py
+++ b/tests/archive_tests.py
@@ -16,9 +16,6 @@ from sos.archive import TarFileArchive
from sos.utilities import tail
from sos.policies import Policy
-# PYCOMPAT
-import six
-
class TarFileArchiveTest(unittest.TestCase):
@@ -56,7 +53,7 @@ class TarFileArchiveTest(unittest.TestCase):
def test_add_string_from_file(self):
self.copy_strings = []
testfile = tempfile.NamedTemporaryFile(dir=self.tmpdir, delete=False)
- testfile.write(six.b("*" * 1000))
+ testfile.write(b"*" * 1000)
testfile.flush()
testfile.close()
diff --git a/tests/plugin_tests.py b/tests/plugin_tests.py
index 207cb724..c88534d8 100644
--- a/tests/plugin_tests.py
+++ b/tests/plugin_tests.py
@@ -10,12 +10,7 @@ import os
import tempfile
import shutil
-# PYCOMPAT
-import six
-try:
- from StringIO import StringIO
-except:
- from io import StringIO
+from io import StringIO
from sos.report.plugins import Plugin, regex_findall, _mangle_command
from sos.archive import TarFileArchive
@@ -29,7 +24,7 @@ def j(filename):
def create_file(size, dir=None):
f = tempfile.NamedTemporaryFile(delete=False, dir=dir)
- f.write(six.b("*" * size * 1024 * 1024))
+ f.write(b"*" * size * 1024 * 1024)
f.flush()
f.close()
return f.name
diff --git a/tests/utilities_tests.py b/tests/utilities_tests.py
index 9d8df584..3513f42c 100644
--- a/tests/utilities_tests.py
+++ b/tests/utilities_tests.py
@@ -9,8 +9,7 @@ import os.path
import unittest
# PYCOMPAT
-import six
-from six import StringIO
+from io import StringIO
from sos.utilities import grep, is_executable, sos_get_command_output, find, tail, shell_out
import sos
@@ -42,12 +41,12 @@ class TailTest(unittest.TestCase):
def test_tail(self):
t = tail("tests/tail_test.txt", 10)
- self.assertEquals(t, six.b("last line\n"))
+ self.assertEquals(t, b"last line\n")
def test_tail_too_many(self):
t = tail("tests/tail_test.txt", 200)
expected = open("tests/tail_test.txt", "r").read()
- self.assertEquals(t, six.b(expected))
+ self.assertEquals(t, str.encode(expected))
class ExecutableTest(unittest.TestCase):