Remove six usage from freezer package

We don't support Python 2 anymore so we don't need this
compatibility library.

This patch remove six usage.

Change-Id: I661e9cdaf33e89bdb905d1f34a001f3853c4c366
This commit is contained in:
caihui 2020-01-22 03:52:35 -08:00
parent bcaac1e3c1
commit 02e435f0ed
22 changed files with 41 additions and 81 deletions

View File

@ -21,25 +21,20 @@ import time
from oslo_log import log from oslo_log import log
from oslo_serialization import jsonutils as json from oslo_serialization import jsonutils as json
import six
# PyCharm will not recognize queue. Puts red squiggle line under it. That's OK. # PyCharm will not recognize queue. Puts red squiggle line under it. That's OK.
from six.moves import queue import queue
from freezer.exceptions import engine as engine_exceptions from freezer.exceptions import engine as engine_exceptions
from freezer.storage import base from freezer.storage import base
from freezer.utils import streaming from freezer.utils import streaming
from freezer.utils import utils from freezer.utils import utils
if six.PY3: from multiprocessing import SimpleQueue
from multiprocessing import SimpleQueue
else:
from multiprocessing.queues import SimpleQueue
LOG = log.getLogger(__name__) LOG = log.getLogger(__name__)
@six.add_metaclass(abc.ABCMeta) class BackupEngine(metaclass=abc.ABCMeta):
class BackupEngine(object):
""" """
The main part of making a backup and making a restore is the mechanism of The main part of making a backup and making a restore is the mechanism of
implementing it. For a long time Freezer had only one mechanism of implementing it. For a long time Freezer had only one mechanism of

View File

@ -27,17 +27,6 @@ https://samba.anu.edu.au/rsync/.
import collections import collections
import hashlib import hashlib
import six
from six.moves import range
if six.PY2:
# Python 2.x compatibility
def bytes(var, *args):
try:
return ''.join(map(chr, var))
except TypeError:
return map(ord, var)
__all__ = ["rollingchecksum", "weakchecksum", "rsyncdelta", __all__ = ["rollingchecksum", "weakchecksum", "rsyncdelta",
"blockchecksums"] "blockchecksums"]

View File

@ -19,15 +19,15 @@ import getpass
import grp import grp
import os import os
import pwd import pwd
import queue
import re import re
import stat import stat
import sys import sys
import threading import threading
from io import StringIO
from oslo_log import log from oslo_log import log
from oslo_serialization import jsonutils as json from oslo_serialization import jsonutils as json
from six.moves import cStringIO
from six.moves import queue
from freezer.engine import engine from freezer.engine import engine
from freezer.engine.rsync import pyrsync from freezer.engine.rsync import pyrsync
@ -256,7 +256,7 @@ class RsyncEngine(engine.BackupEngine):
len_deltas = 0 len_deltas = 0
old_signature = old_file_meta['signature'] old_signature = old_file_meta['signature']
# Get changed blocks index only # Get changed blocks index only
all_changed_indexes = cStringIO() all_changed_indexes = StringIO()
file_path_fd.seek(0) file_path_fd.seek(0)
previous_index = -1 previous_index = -1
modified_blocks = [] modified_blocks = []

View File

@ -18,8 +18,10 @@ Freezer rsync incremental engine
import fnmatch import fnmatch
import getpass import getpass
import grp import grp
import io
import os import os
import pwd import pwd
import queue
import shutil import shutil
import stat import stat
import sys import sys
@ -27,9 +29,7 @@ import threading
import msgpack import msgpack
from oslo_log import log from oslo_log import log
import six
from six.moves import queue
from freezer.engine import engine from freezer.engine import engine
from freezer.engine.rsyncv2 import pyrsync from freezer.engine.rsyncv2 import pyrsync
@ -222,7 +222,7 @@ class Rsyncv2Engine(engine.BackupEngine):
files_meta = msgpack.load(data_stream) files_meta = msgpack.load(data_stream)
except msgpack.ExtraData as e: except msgpack.ExtraData as e:
files_meta = e.unpacked files_meta = e.unpacked
data_stream = six.BytesIO(e.extra) data_stream = io.BytesIO(e.extra)
break break
except msgpack.OutOfData: except msgpack.OutOfData:
data_stream.write(data_gen.next().read()) data_stream.write(data_gen.next().read())
@ -349,14 +349,14 @@ class Rsyncv2Engine(engine.BackupEngine):
data_chunk += read_pipe.recv_bytes() data_chunk += read_pipe.recv_bytes()
continue continue
if data_chunk: if data_chunk:
yield six.BytesIO(data_chunk) yield io.BytesIO(data_chunk)
data_chunk = read_pipe.recv_bytes() data_chunk = read_pipe.recv_bytes()
except EOFError: except EOFError:
LOG.info("[*] EOF from pipe. Flushing buffer.") LOG.info("[*] EOF from pipe. Flushing buffer.")
data_chunk = decompressor.flush() data_chunk = decompressor.flush()
if data_chunk: if data_chunk:
yield six.BytesIO(data_chunk) yield io.BytesIO(data_chunk)
@staticmethod @staticmethod
def _process_backup_data(data, compressor, encryptor, do_compress=True): def _process_backup_data(data, compressor, encryptor, do_compress=True):
@ -574,7 +574,7 @@ class Rsyncv2Engine(engine.BackupEngine):
""" """
file_name = os.path.basename(file_path) file_name = os.path.basename(file_path)
for fn in six.iterkeys(old_files): for fn in iter(old_files.keys()):
base_name = os.path.basename(fn) base_name = os.path.basename(fn)
if fnmatch.fnmatch(base_name, '*' + file_name + '*'): if fnmatch.fnmatch(base_name, '*' + file_name + '*'):
return base_name return base_name
@ -704,7 +704,7 @@ class Rsyncv2Engine(engine.BackupEngine):
counts['total_files'] += 1 counts['total_files'] += 1
# Check for deleted files # Check for deleted files
for del_file in (f for f in six.iterkeys(old_fs_meta_struct) if for del_file in (f for f in iter(old_fs_meta_struct.keys()) if
f not in files_meta['files']): f not in files_meta['files']):
backup_header.append({'path': del_file, 'deleted': True}) backup_header.append({'path': del_file, 'deleted': True})

View File

@ -24,7 +24,6 @@ import time
from oslo_config import cfg from oslo_config import cfg
from oslo_log import log from oslo_log import log
from oslo_utils import importutils from oslo_utils import importutils
import six
from freezer.common import client_manager from freezer.common import client_manager
from freezer.openstack import admin from freezer.openstack import admin
@ -39,8 +38,7 @@ CONF = cfg.CONF
LOG = log.getLogger(__name__) LOG = log.getLogger(__name__)
@six.add_metaclass(abc.ABCMeta) class Job(metaclass=abc.ABCMeta):
class Job(object):
""" """
:type storage: freezer.storage.base.Storage :type storage: freezer.storage.base.Storage
:type engine: freezer.engine.engine.BackupEngine :type engine: freezer.engine.engine.BackupEngine

View File

@ -32,7 +32,6 @@ import signal
import socket import socket
import sys import sys
import six
class DaemonError(Exception): class DaemonError(Exception):
@ -171,7 +170,7 @@ class DaemonContext(object):
""" """
if not handler: if not handler:
result = signal.SIG_IGN result = signal.SIG_IGN
elif isinstance(handler, six.string_types): elif isinstance(handler, str):
result = getattr(self, handler) result = getattr(self, handler)
else: else:
result = handler result = handler

View File

@ -13,11 +13,9 @@
# limitations under the License. # limitations under the License.
import abc import abc
import six
@six.add_metaclass(abc.ABCMeta) class Mode(metaclass=abc.ABCMeta):
class Mode(object):
@abc.abstractproperty @abc.abstractproperty
def name(self): def name(self):
pass pass

View File

@ -13,6 +13,7 @@
# limitations under the License. # limitations under the License.
import configparser
import datetime import datetime
import os import os
import subprocess import subprocess
@ -23,7 +24,6 @@ from freezer.utils import utils
from oslo_config import cfg from oslo_config import cfg
from oslo_log import log from oslo_log import log
from oslo_serialization import jsonutils as json from oslo_serialization import jsonutils as json
from six.moves import configparser
CONF = cfg.CONF CONF = cfg.CONF

View File

@ -19,15 +19,13 @@ import tempfile
from oslo_log import log from oslo_log import log
from oslo_serialization import jsonutils as json from oslo_serialization import jsonutils as json
import six
from freezer.utils import utils from freezer.utils import utils
LOG = log.getLogger(__name__) LOG = log.getLogger(__name__)
@six.add_metaclass(abc.ABCMeta) class Storage(metaclass=abc.ABCMeta):
class Storage(object):
""" """
Any freezer storage implementation should be inherited from this abstract Any freezer storage implementation should be inherited from this abstract
class. class.

View File

@ -13,15 +13,13 @@
# limitations under the License. # limitations under the License.
import abc import abc
import six
from oslo_serialization import jsonutils as json from oslo_serialization import jsonutils as json
from freezer.storage import physical from freezer.storage import physical
@six.add_metaclass(abc.ABCMeta) class FsLikeStorage(physical.PhysicalStorage, metaclass=abc.ABCMeta):
class FsLikeStorage(physical.PhysicalStorage):
_type = 'fslike' _type = 'fslike'
def __init__(self, storage_path, def __init__(self, storage_path,

View File

@ -14,7 +14,7 @@
from oslo_log import log from oslo_log import log
# PyCharm will not recognize queue. Puts red squiggle line under it. That's OK. # PyCharm will not recognize queue. Puts red squiggle line under it. That's OK.
from six.moves import queue import queue
from freezer.storage import base from freezer.storage import base
from freezer.storage import exceptions from freezer.storage import exceptions

View File

@ -16,14 +16,12 @@
import abc import abc
import os import os
import six
from freezer.storage import base from freezer.storage import base
from freezer.utils import utils from freezer.utils import utils
@six.add_metaclass(abc.ABCMeta) class PhysicalStorage(base.Storage, metaclass=abc.ABCMeta):
class PhysicalStorage(base.Storage):
""" """
Backup like Swift, SSH or Local. Something that represents real storage. Backup like Swift, SSH or Local. Something that represents real storage.
For example MultipleStorage is not physical. For example MultipleStorage is not physical.

View File

@ -27,7 +27,6 @@ from oslo_serialization import jsonutils as json
import paramiko import paramiko
from six.moves import range
FREEZERC = distutils.spawn.find_executable('freezer-agent') FREEZERC = distutils.spawn.find_executable('freezer-agent')

View File

@ -14,14 +14,14 @@
import unittest import unittest
import six import io
from freezer.engine.rsync import pyrsync from freezer.engine.rsync import pyrsync
class TestPyrsync(unittest.TestCase): class TestPyrsync(unittest.TestCase):
def test_blockcheksum(self): def test_blockcheksum(self):
instream = six.BytesIO(b'aae9dd83aa45f906' instream = io.BytesIO(b'aae9dd83aa45f906'
b'a4629f42e97eac99' b'a4629f42e97eac99'
b'b9882284dc7030ca' b'b9882284dc7030ca'
b'427ad365fedd2a55') b'427ad365fedd2a55')
@ -34,7 +34,7 @@ class TestPyrsync(unittest.TestCase):
self.assertEqual((weak, strong), (exp_weak, exp_strong)) self.assertEqual((weak, strong), (exp_weak, exp_strong))
def test_rsyncdelta(self): def test_rsyncdelta(self):
datastream = six.BytesIO(b'addc830058f917ae' datastream = io.BytesIO(b'addc830058f917ae'
b'a1be5ab4d899b570' b'a1be5ab4d899b570'
b'85c9534c64d8d71c' b'85c9534c64d8d71c'
b'1f32cde9c71e5b6d') b'1f32cde9c71e5b6d')

View File

@ -12,12 +12,12 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import io
import sys import sys
import unittest import unittest
import mock import mock
from mock import patch from mock import patch
from six import moves
from freezer.utils.checksum import CheckSum from freezer.utils.checksum import CheckSum
@ -31,7 +31,7 @@ class TestChecksum(unittest.TestCase):
self.hello_world_sha256sum = ('17b949eb67acf16bbf2605d57a01f7af4ff4b5' self.hello_world_sha256sum = ('17b949eb67acf16bbf2605d57a01f7af4ff4b5'
'7e200259de63fcebf20e75bbf5') '7e200259de63fcebf20e75bbf5')
self.fake_file = moves.StringIO(u"hello world\n") self.fake_file = io.StringIO(u"hello world\n")
self.increment_hash_one = self.hello_world_sha256sum self.increment_hash_one = self.hello_world_sha256sum
self.increment_hash_multi = ('1b4bc4ff41172a5f29eaeffb7e9fc24c683c693' self.increment_hash_multi = ('1b4bc4ff41172a5f29eaeffb7e9fc24c683c693'
'9ab30132ad5d93a1e4a6b16e8') '9ab30132ad5d93a1e4a6b16e8')

View File

@ -12,10 +12,9 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import io
import unittest import unittest
from six import moves
from freezer.utils import config from freezer.utils import config
@ -47,7 +46,7 @@ password = 'aNiceQuotedPassword'
password2 = "aNiceQuotedPassword" password2 = "aNiceQuotedPassword"
spaced = value""" spaced = value"""
fd = moves.cStringIO(string) fd = io.StringIO(string)
res = config.ini_parse(fd) res = config.ini_parse(fd)
self.assertEqual('127.0.0.1', res['host']) self.assertEqual('127.0.0.1', res['host'])
self.assertEqual('openstack', res['user']) self.assertEqual('openstack', res['user'])

View File

@ -15,8 +15,7 @@
import hashlib import hashlib
import os import os
import six import io
from six import moves
from freezer.utils import utils from freezer.utils import utils
@ -119,11 +118,7 @@ class CheckSum(object):
# Need to use string-escape for Python 2 non-unicode strings. For # Need to use string-escape for Python 2 non-unicode strings. For
# Python 2 unicode strings and all Python 3 strings, we need to use # Python 2 unicode strings and all Python 3 strings, we need to use
# unicode-escape. The effect of them is the same. # unicode-escape. The effect of them is the same.
if six.PY2 and isinstance(buf, str): if isinstance(buf, str):
buf = buf.encode('string-escape')
elif six.PY2 and not isinstance(buf, str):
buf = buf.encode('unicode-escape')
elif six.PY3 and isinstance(buf, six.string_types):
buf = buf.encode('unicode-escape') buf = buf.encode('unicode-escape')
self.hasher.update(buf) self.hasher.update(buf)
@ -134,7 +129,7 @@ class CheckSum(object):
""" """
:return: the hash for a given string :return: the hash for a given string
""" """
fd = moves.StringIO(string) fd = io.StringIO(string)
return self.hashfile(fd) return self.hashfile(fd)
def compute(self): def compute(self):

View File

@ -12,12 +12,11 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import configparser
import os import os
import re import re
from oslo_log import log from oslo_log import log
import six
from six.moves import configparser
from freezer.utils import utils from freezer.utils import utils
@ -41,10 +40,7 @@ class Config(object):
raise Exception("Configuration file {0} not found !".format( raise Exception("Configuration file {0} not found !".format(
config_path)) config_path))
# SafeConfigParser was deprecated in Python 3.2 # SafeConfigParser was deprecated in Python 3.2
if six.PY3:
config = configparser.ConfigParser() config = configparser.ConfigParser()
else:
config = configparser.SafeConfigParser()
config.read([config_path]) config.read([config_path])
sections = config.sections() sections = config.sections()
storages = [] storages = []

View File

@ -20,7 +20,7 @@ Freezer general utils functions
import threading import threading
from oslo_log import log from oslo_log import log
from six.moves import queue import queue
LOG = log.getLogger(__name__) LOG = log.getLogger(__name__)

View File

@ -18,6 +18,7 @@
Freezer general utils functions Freezer general utils functions
""" """
import configparser
import datetime import datetime
import errno import errno
import fnmatch as fn import fnmatch as fn
@ -31,7 +32,6 @@ from distutils import spawn as distspawn
from freezer.exceptions import utils from freezer.exceptions import utils
from functools import wraps from functools import wraps
from oslo_log import log from oslo_log import log
from six.moves import configparser
logging.getLogger('botocore').setLevel(logging.WARNING) logging.getLogger('botocore').setLevel(logging.WARNING)

View File

@ -107,7 +107,6 @@ rfc3986==1.1.0
Routes==2.4.1 Routes==2.4.1
setuptools==21.0.0 setuptools==21.0.0
simplejson==3.13.2 simplejson==3.13.2
six==1.10.0
snowballstemmer==1.2.1 snowballstemmer==1.2.1
Sphinx==1.6.2 Sphinx==1.6.2
sphinxcontrib-websupport==1.0.1 sphinxcontrib-websupport==1.0.1

View File

@ -23,7 +23,6 @@ cryptography>=2.1 # Apache-2.0
PyMySQL>=0.7.6 # MIT License PyMySQL>=0.7.6 # MIT License
pymongo!=3.1,>=3.0.2 # Apache-2.0 pymongo!=3.1,>=3.0.2 # Apache-2.0
paramiko>=2.0.0 # LGPLv2.1+ paramiko>=2.0.0 # LGPLv2.1+
six>=1.10.0 # MIT
apscheduler>=3.0.5 # MIT License apscheduler>=3.0.5 # MIT License
psutil>=3.2.2 # BSD psutil>=3.2.2 # BSD