]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
pybind/mgr/dashboard: drop py2 support
authorKefu Chai <kchai@redhat.com>
Sun, 28 Jun 2020 11:15:25 +0000 (19:15 +0800)
committerKefu Chai <kchai@redhat.com>
Sun, 5 Jul 2020 02:58:28 +0000 (10:58 +0800)
Signed-off-by: Kefu Chai <kchai@redhat.com>
17 files changed:
src/pybind/mgr/dashboard/cherrypy_backports.py
src/pybind/mgr/dashboard/ci/check_grafana_uids.py
src/pybind/mgr/dashboard/constraints.txt
src/pybind/mgr/dashboard/controllers/__init__.py
src/pybind/mgr/dashboard/controllers/orchestrator.py
src/pybind/mgr/dashboard/plugins/__init__.py
src/pybind/mgr/dashboard/requirements.txt
src/pybind/mgr/dashboard/services/cephfs.py
src/pybind/mgr/dashboard/services/exception.py
src/pybind/mgr/dashboard/services/orchestrator.py
src/pybind/mgr/dashboard/services/rbd.py
src/pybind/mgr/dashboard/services/rgw_client.py
src/pybind/mgr/dashboard/services/sso.py
src/pybind/mgr/dashboard/settings.py
src/pybind/mgr/dashboard/tests/__init__.py
src/pybind/mgr/dashboard/tools.py
src/pybind/mgr/dashboard/tox.ini

index d11b541fab1a178c7b6b3bb0479795e31436e1b1..94c44fe13d4218205ed125339b6ed63b30c30704 100644 (file)
@@ -118,12 +118,7 @@ def accept_socket_error_0(v):
         pass
 
     if v < StrictVersion("9.0.0") or cheroot_version < StrictVersion("6.5.5"):
-        import six
-        if six.PY3:
-            generic_socket_error = OSError
-        else:
-            import socket
-            generic_socket_error = socket.error
+        generic_socket_error = OSError
 
         def accept_socket_error_0(func):
             def wrapper(self, sock):
index fac3b9953971551d1c392a5997ff94caedb55113..ab27ab663993d0f7c09e512f19030b237c1887e8 100644 (file)
@@ -18,18 +18,13 @@ import copy
 import json
 import os
 
-import six
-from six.moves.html_parser import HTMLParser
+from html.parser import HTMLParser
 
 
 class TemplateParser(HTMLParser):
 
     def __init__(self, _file, search_tag):
-        if six.PY3:
-            super(TemplateParser, self).__init__()
-        else:
-            # HTMLParser is not a new-style class in py2
-            HTMLParser.__init__(self)
+        super().__init__()
         self.search_tag = search_tag
         self.file = _file
         self.parsed_data = []
@@ -54,10 +49,6 @@ class TemplateParser(HTMLParser):
         exit(error_msg)
 
 
-def stdout(msg):
-    six.print_(msg)
-
-
 def get_files(base_dir, file_ext):
     result = []
     for root, _, files in os.walk(base_dir):
@@ -132,7 +123,7 @@ def main():
         exit(error_msg)
 
     if verbose:
-        stdout('Found mappings:')
+        print('Found mappings:')
     no_dashboard_tags = []
     for tag in tags:
         uid = tag['attrs']['uid']
@@ -144,7 +135,7 @@ def main():
                 format(uid, tag['file'], tag['line'],
                        grafana_dashboards[uid]['title'],
                        grafana_dashboards[uid]['file'])
-            stdout(msg)
+            print(msg)
 
     if no_dashboard_tags:
         title = ('Checking Grafana dashboards UIDs: ERROR\n'
@@ -156,7 +147,7 @@ def main():
         error_msg = title + '\n'.join(lines)
         exit(error_msg)
     else:
-        stdout('Checking Grafana dashboards UIDs: OK')
+        print('Checking Grafana dashboards UIDs: OK')
 
 
 if __name__ == '__main__':
index 5255f89a6c3f8401b2edbc799cf74a03ebf1af88..3e8532d4514f6d8ca59944f9badc4068674f0ed3 100644 (file)
@@ -7,4 +7,3 @@ bcrypt==3.1.4
 python3-saml==1.4.1
 requests==2.20.0
 Routes==2.4.1
-six==1.14.0
index a72ed73ce0a4f883ba117ec18e7a7e4a28818c03..de66b394589c721278d10eaf2b25eb79604179fd 100644 (file)
@@ -11,15 +11,15 @@ import os
 import pkgutil
 import re
 import sys
+import urllib
 
-import six
-from six.moves.urllib.parse import unquote
+from functools import wraps
 
 # pylint: disable=wrong-import-position
 import cherrypy
 
 from ..security import Scope, Permission
-from ..tools import wraps, getargspec, TaskManager, get_request_body_params
+from ..tools import getargspec, TaskManager, get_request_body_params
 from ..exceptions import ScopeNotValid, PermissionNotValid
 from ..services.auth import AuthManager, JwtManager
 from ..plugins import PLUGIN_MANAGER
@@ -655,8 +655,8 @@ class BaseController(object):
         @wraps(func)
         def inner(*args, **kwargs):
             for key, value in kwargs.items():
-                if isinstance(value, six.text_type):
-                    kwargs[key] = unquote(value)
+                if isinstance(value, str):
+                    kwargs[key] = urllib.parse.unquote(value)
 
             # Process method arguments.
             params = get_request_body_params(cherrypy.request)
index c9172b83942809e70220865c080fee473ee802bf..70ee3d9307d136d1f280c70d9227cd8c3fc28b14 100644 (file)
@@ -3,6 +3,7 @@ from __future__ import absolute_import
 import os.path
 
 import time
+from functools import wraps
 
 from . import ApiController, Endpoint, ReadPermission, UpdatePermission
 from . import RESTController, Task
@@ -11,7 +12,7 @@ from ..exceptions import DashboardException
 from ..security import Scope
 from ..services.exception import handle_orchestrator_error
 from ..services.orchestrator import OrchClient
-from ..tools import TaskManager, wraps
+from ..tools import TaskManager
 
 
 def get_device_osd_map():
index 8973654770278f8bcd1296a6f1e6853c6461f141..9726b971844b63a61c8cd4e386a494d5739e25a1 100644 (file)
@@ -2,13 +2,11 @@
 from __future__ import absolute_import
 
 import abc
-import six
 
 from .pluggy import HookspecMarker, HookimplMarker, PluginManager
 
 
-@six.add_metaclass(abc.ABCMeta)
-class Interface(object):
+class Interface(object, metaclass=abc.ABCMeta):
     pass
 
 
index 1b8ce514329f0d1656fea27710b0711cb6fd25eb..eb0da8026734fb743786dde2cc3cea0882db0351 100644 (file)
@@ -7,7 +7,6 @@ pyopenssl
 python3-saml
 requests
 Routes
-six
 -e ../../../python-common
 prettytable
 pyyaml
index a40a370c8cf14fa7bb78e47762cdd99d8d871edd..a9d9cb5093619edc0876e67efb6ee7f434bbf651 100644 (file)
@@ -6,7 +6,6 @@ import logging
 
 import datetime
 import os
-import six
 import cephfs
 
 from .. import mgr
@@ -92,7 +91,7 @@ class CephFS(object):
             ]
         :rtype: list
         """
-        if isinstance(path, six.string_types):
+        if isinstance(path, str):
             path = path.encode()
         logger.debug("get_dir_list dirpath=%s depth=%s", path,
                      depth)
index 26b6ee4b19dd89fa31ce50e1f62258574374ce9a..61ec52d451d4ec4e8d5213311e315bb0058a840f 100644 (file)
@@ -4,7 +4,6 @@ from __future__ import absolute_import
 import json
 from contextlib import contextmanager
 import logging
-import six
 
 import cherrypy
 
@@ -14,57 +13,11 @@ import rados
 
 from ..services.ceph_service import SendCommandError
 from ..exceptions import ViewCacheNoDataException, DashboardException
-from ..tools import wraps
 
 
 logger = logging.getLogger('exception')
 
 
-if six.PY2:
-    # Monkey-patch a __call__ method into @contextmanager to make
-    # it compatible to Python 3
-
-    # pylint: disable=no-name-in-module,ungrouped-imports
-    from contextlib import GeneratorContextManager
-
-    def init(self, *args):
-        if len(args) == 1:
-            self.gen = args[0]
-        elif len(args) == 3:
-            self.func, self.args, self.kwargs = args
-        else:
-            raise TypeError()
-
-    def enter(self):
-        if hasattr(self, 'func'):
-            self.gen = self.func(*self.args, **self.kwargs)
-        try:
-            return self.gen.next()
-        except StopIteration:
-            raise RuntimeError("generator didn't yield")
-
-    def call(self, f):
-        @wraps(f)
-        def wrapper(*args, **kwargs):
-            with self:
-                return f(*args, **kwargs)
-
-        return wrapper
-
-    GeneratorContextManager.__init__ = init
-    GeneratorContextManager.__enter__ = enter
-    GeneratorContextManager.__call__ = call
-
-    # pylint: disable=function-redefined
-    def contextmanager(func):  # noqa: F811
-
-        @wraps(func)
-        def helper(*args, **kwds):
-            return GeneratorContextManager(func, args, kwds)
-
-        return helper
-
-
 def serialize_dashboard_exception(e, include_http_status=False, task=None):
     """
     :type e: Exception
index ea33b9a37ee28e56fb107ee946dffe9e20804396..b5cf7142e8a4d24b99239700cd2bf950331e6cad 100644 (file)
@@ -2,6 +2,7 @@
 from __future__ import absolute_import
 import logging
 
+from functools import wraps
 from typing import List, Optional
 
 from orchestrator import InventoryFilter, DeviceLightLoc, Completion
@@ -9,7 +10,6 @@ from orchestrator import ServiceDescription, DaemonDescription
 from orchestrator import OrchestratorClientMixin, raise_if_exception, OrchestratorError
 from orchestrator import HostSpec
 from .. import mgr
-from ..tools import wraps
 
 logger = logging.getLogger('orchestrator')
 
index 4e628342282eb1ed5e92aa1ac3fe843f852c043f..fa46356f1c2ab375e9cba20a7980ce5ded68051c 100644 (file)
@@ -2,8 +2,6 @@
 # pylint: disable=unused-argument
 from __future__ import absolute_import
 
-import six
-
 import cherrypy
 
 import rbd
@@ -57,7 +55,7 @@ def format_features(features):
     @DISABLEDOCTEST: >>> format_features('deep-flatten, exclusive-lock')
     32
     """
-    if isinstance(features, six.string_types):
+    if isinstance(features, str):
         features = features.split(',')
 
     if not isinstance(features, list):
index 5507eb68007574ac890498de0f625f70dd2f4ba2..7295afb294a9bb94e137d57b3017f1b03b457f03 100644 (file)
@@ -6,7 +6,6 @@ import logging
 import ipaddress
 from distutils.util import strtobool
 import xml.etree.ElementTree as ET  # noqa: N814
-import six
 from ..awsauth import S3Auth
 from ..exceptions import DashboardException
 from ..settings import Settings, Options
@@ -139,7 +138,7 @@ def _parse_addr(value):
         #   Group 2: 2001:db8:85a3::8a2e:370:7334
         addr = match.group(3) if match.group(3) else match.group(2)
         try:
-            ipaddress.ip_address(six.u(addr))
+            ipaddress.ip_address(addr)
             return addr
         except ValueError:
             raise LookupError('Invalid RGW address \'{}\' found'.format(addr))
index adab60d5190a524837f9aa40b22106a55b1ab6bb..7f0bd683085b212ba61426aabd8c28160bd9f12f 100644 (file)
@@ -9,16 +9,12 @@ import logging
 import threading
 import warnings
 
-import six
-from six.moves.urllib import parse
+from urllib import parse
 
 from .. import mgr
 from ..tools import prepare_url_prefix
 
 
-if six.PY2:
-    FileNotFoundError = IOError  # pylint: disable=redefined-builtin
-
 logger = logging.getLogger('sso')
 
 try:
index 229f0c3d03dca8ddeff050c2e5c6287f6bc1decc..23e95b1f3d2c62bc02cd36b66b1bc4704bac1500 100644 (file)
@@ -3,7 +3,6 @@ from __future__ import absolute_import
 
 import errno
 import inspect
-from six import add_metaclass
 
 from . import mgr
 
@@ -112,8 +111,7 @@ class SettingsMeta(type):
 
 
 # pylint: disable=no-init
-@add_metaclass(SettingsMeta)
-class Settings(object):
+class Settings(object, metaclass=SettingsMeta):
     pass
 
 
index 421378a155d80633dbb44e8cb3fc2322fa904203..de25866695d144fa1023fb1405c5b757685308d5 100644 (file)
@@ -5,7 +5,6 @@ from __future__ import absolute_import
 import json
 import logging
 import threading
-import sys
 import time
 
 import cherrypy
@@ -94,11 +93,7 @@ class FakeFsMixin(object):
     fs = fake_filesystem.FakeFilesystem()
     f_open = fake_filesystem.FakeFileOpen(fs)
     f_os = fake_filesystem.FakeOsModule(fs)
-
-    if sys.version_info > (3, 0):
-        builtins_open = 'builtins.open'
-    else:
-        builtins_open = '__builtin__.open'
+    builtins_open = 'builtins.open'
 
 
 class ControllerTestCase(helper.CPWebCase):
index 2b6d92ca55f7d1ab90e4dadf2c380d4f7f2e79d7..cfa206c1238e14fb517c8cf0b1eb579a6589abfa 100644 (file)
@@ -1,10 +1,8 @@
 # -*- coding: utf-8 -*-
 from __future__ import absolute_import
 
-import sys
 import inspect
 import json
-import functools
 import ipaddress
 import logging
 
@@ -14,14 +12,9 @@ from distutils.util import strtobool
 import fnmatch
 import time
 import threading
-import six
-from six.moves import urllib
-import cherrypy
+import urllib
 
-try:
-    from urlparse import urljoin
-except ImportError:
-    from urllib.parse import urljoin
+import cherrypy
 
 from . import mgr
 from .exceptions import ViewCacheNoDataException
@@ -694,12 +687,7 @@ def build_url(host, scheme=None, port=None):
     :rtype: str
     """
     try:
-        try:
-            u_host = six.u(host)
-        except TypeError:
-            u_host = host
-
-        ipaddress.IPv6Address(u_host)
+        ipaddress.IPv6Address(host)
         netloc = '[{}]'.format(host)
     except ValueError:
         netloc = host
@@ -719,7 +707,7 @@ def prepare_url_prefix(url_prefix):
     """
     return '' if no prefix, or '/prefix' without slash in the end.
     """
-    url_prefix = urljoin('/', url_prefix)
+    url_prefix = urllib.parse.urljoin('/', url_prefix)
     return url_prefix.rstrip('/')
 
 
@@ -757,20 +745,6 @@ def dict_get(obj, path, default=None):
     return current
 
 
-if sys.version_info > (3, 0):
-    wraps = functools.wraps
-    _getargspec = inspect.getfullargspec
-else:
-    def wraps(func):
-        def decorator(wrapper):
-            new_wrapper = functools.wraps(func)(wrapper)
-            new_wrapper.__wrapped__ = func  # set __wrapped__ even for Python 2
-            return new_wrapper
-        return decorator
-
-    _getargspec = inspect.getargspec
-
-
 def getargspec(func):
     try:
         while True:
@@ -778,7 +752,7 @@ def getargspec(func):
     except AttributeError:
         pass
     # pylint: disable=deprecated-method
-    return _getargspec(func)
+    return inspect.getfullargspec(func)
 
 
 def str_to_bool(val):
index 6962d9b4bd793cc8c3c142fdb5b58e8ab829aed9..f611ace16234b8c6aced2d998a81afb794eb8f14 100644 (file)
@@ -137,7 +137,5 @@ commands =
 
 
 [testenv:check]
-deps = 
-    six==1.14.0
 commands =
     python ci/check_grafana_uids.py frontend/src/app ../../../../monitoring/grafana/dashboards