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:
parent
bcaac1e3c1
commit
02e435f0ed
|
@ -21,25 +21,20 @@ import time
|
|||
|
||||
from oslo_log import log
|
||||
from oslo_serialization import jsonutils as json
|
||||
import six
|
||||
# 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.storage import base
|
||||
from freezer.utils import streaming
|
||||
from freezer.utils import utils
|
||||
|
||||
if six.PY3:
|
||||
from multiprocessing import SimpleQueue
|
||||
else:
|
||||
from multiprocessing.queues import SimpleQueue
|
||||
from multiprocessing import SimpleQueue
|
||||
|
||||
LOG = log.getLogger(__name__)
|
||||
|
||||
|
||||
@six.add_metaclass(abc.ABCMeta)
|
||||
class BackupEngine(object):
|
||||
class BackupEngine(metaclass=abc.ABCMeta):
|
||||
"""
|
||||
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
|
||||
|
|
|
@ -27,17 +27,6 @@ https://samba.anu.edu.au/rsync/.
|
|||
import collections
|
||||
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",
|
||||
"blockchecksums"]
|
||||
|
|
|
@ -19,15 +19,15 @@ import getpass
|
|||
import grp
|
||||
import os
|
||||
import pwd
|
||||
import queue
|
||||
import re
|
||||
import stat
|
||||
import sys
|
||||
import threading
|
||||
|
||||
from io import StringIO
|
||||
from oslo_log import log
|
||||
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.rsync import pyrsync
|
||||
|
@ -256,7 +256,7 @@ class RsyncEngine(engine.BackupEngine):
|
|||
len_deltas = 0
|
||||
old_signature = old_file_meta['signature']
|
||||
# Get changed blocks index only
|
||||
all_changed_indexes = cStringIO()
|
||||
all_changed_indexes = StringIO()
|
||||
file_path_fd.seek(0)
|
||||
previous_index = -1
|
||||
modified_blocks = []
|
||||
|
|
|
@ -18,8 +18,10 @@ Freezer rsync incremental engine
|
|||
import fnmatch
|
||||
import getpass
|
||||
import grp
|
||||
import io
|
||||
import os
|
||||
import pwd
|
||||
import queue
|
||||
import shutil
|
||||
import stat
|
||||
import sys
|
||||
|
@ -27,9 +29,7 @@ import threading
|
|||
|
||||
import msgpack
|
||||
from oslo_log import log
|
||||
import six
|
||||
|
||||
from six.moves import queue
|
||||
|
||||
from freezer.engine import engine
|
||||
from freezer.engine.rsyncv2 import pyrsync
|
||||
|
@ -222,7 +222,7 @@ class Rsyncv2Engine(engine.BackupEngine):
|
|||
files_meta = msgpack.load(data_stream)
|
||||
except msgpack.ExtraData as e:
|
||||
files_meta = e.unpacked
|
||||
data_stream = six.BytesIO(e.extra)
|
||||
data_stream = io.BytesIO(e.extra)
|
||||
break
|
||||
except msgpack.OutOfData:
|
||||
data_stream.write(data_gen.next().read())
|
||||
|
@ -349,14 +349,14 @@ class Rsyncv2Engine(engine.BackupEngine):
|
|||
data_chunk += read_pipe.recv_bytes()
|
||||
continue
|
||||
if data_chunk:
|
||||
yield six.BytesIO(data_chunk)
|
||||
yield io.BytesIO(data_chunk)
|
||||
data_chunk = read_pipe.recv_bytes()
|
||||
|
||||
except EOFError:
|
||||
LOG.info("[*] EOF from pipe. Flushing buffer.")
|
||||
data_chunk = decompressor.flush()
|
||||
if data_chunk:
|
||||
yield six.BytesIO(data_chunk)
|
||||
yield io.BytesIO(data_chunk)
|
||||
|
||||
@staticmethod
|
||||
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)
|
||||
for fn in six.iterkeys(old_files):
|
||||
for fn in iter(old_files.keys()):
|
||||
base_name = os.path.basename(fn)
|
||||
if fnmatch.fnmatch(base_name, '*' + file_name + '*'):
|
||||
return base_name
|
||||
|
@ -704,7 +704,7 @@ class Rsyncv2Engine(engine.BackupEngine):
|
|||
counts['total_files'] += 1
|
||||
|
||||
# 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']):
|
||||
backup_header.append({'path': del_file, 'deleted': True})
|
||||
|
||||
|
|
|
@ -24,7 +24,6 @@ import time
|
|||
from oslo_config import cfg
|
||||
from oslo_log import log
|
||||
from oslo_utils import importutils
|
||||
import six
|
||||
|
||||
from freezer.common import client_manager
|
||||
from freezer.openstack import admin
|
||||
|
@ -39,8 +38,7 @@ CONF = cfg.CONF
|
|||
LOG = log.getLogger(__name__)
|
||||
|
||||
|
||||
@six.add_metaclass(abc.ABCMeta)
|
||||
class Job(object):
|
||||
class Job(metaclass=abc.ABCMeta):
|
||||
"""
|
||||
:type storage: freezer.storage.base.Storage
|
||||
:type engine: freezer.engine.engine.BackupEngine
|
||||
|
|
|
@ -32,7 +32,6 @@ import signal
|
|||
import socket
|
||||
import sys
|
||||
|
||||
import six
|
||||
|
||||
|
||||
class DaemonError(Exception):
|
||||
|
@ -171,7 +170,7 @@ class DaemonContext(object):
|
|||
"""
|
||||
if not handler:
|
||||
result = signal.SIG_IGN
|
||||
elif isinstance(handler, six.string_types):
|
||||
elif isinstance(handler, str):
|
||||
result = getattr(self, handler)
|
||||
else:
|
||||
result = handler
|
||||
|
|
|
@ -13,11 +13,9 @@
|
|||
# limitations under the License.
|
||||
|
||||
import abc
|
||||
import six
|
||||
|
||||
|
||||
@six.add_metaclass(abc.ABCMeta)
|
||||
class Mode(object):
|
||||
class Mode(metaclass=abc.ABCMeta):
|
||||
@abc.abstractproperty
|
||||
def name(self):
|
||||
pass
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
# limitations under the License.
|
||||
|
||||
|
||||
import configparser
|
||||
import datetime
|
||||
import os
|
||||
import subprocess
|
||||
|
@ -23,7 +24,6 @@ from freezer.utils import utils
|
|||
from oslo_config import cfg
|
||||
from oslo_log import log
|
||||
from oslo_serialization import jsonutils as json
|
||||
from six.moves import configparser
|
||||
|
||||
|
||||
CONF = cfg.CONF
|
||||
|
|
|
@ -19,15 +19,13 @@ import tempfile
|
|||
|
||||
from oslo_log import log
|
||||
from oslo_serialization import jsonutils as json
|
||||
import six
|
||||
|
||||
from freezer.utils import utils
|
||||
|
||||
LOG = log.getLogger(__name__)
|
||||
|
||||
|
||||
@six.add_metaclass(abc.ABCMeta)
|
||||
class Storage(object):
|
||||
class Storage(metaclass=abc.ABCMeta):
|
||||
"""
|
||||
Any freezer storage implementation should be inherited from this abstract
|
||||
class.
|
||||
|
|
|
@ -13,15 +13,13 @@
|
|||
# limitations under the License.
|
||||
|
||||
import abc
|
||||
import six
|
||||
|
||||
from oslo_serialization import jsonutils as json
|
||||
|
||||
from freezer.storage import physical
|
||||
|
||||
|
||||
@six.add_metaclass(abc.ABCMeta)
|
||||
class FsLikeStorage(physical.PhysicalStorage):
|
||||
class FsLikeStorage(physical.PhysicalStorage, metaclass=abc.ABCMeta):
|
||||
_type = 'fslike'
|
||||
|
||||
def __init__(self, storage_path,
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
from oslo_log import log
|
||||
# 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 exceptions
|
||||
|
|
|
@ -16,14 +16,12 @@
|
|||
import abc
|
||||
import os
|
||||
|
||||
import six
|
||||
|
||||
from freezer.storage import base
|
||||
from freezer.utils import utils
|
||||
|
||||
|
||||
@six.add_metaclass(abc.ABCMeta)
|
||||
class PhysicalStorage(base.Storage):
|
||||
class PhysicalStorage(base.Storage, metaclass=abc.ABCMeta):
|
||||
"""
|
||||
Backup like Swift, SSH or Local. Something that represents real storage.
|
||||
For example MultipleStorage is not physical.
|
||||
|
|
|
@ -27,7 +27,6 @@ from oslo_serialization import jsonutils as json
|
|||
|
||||
import paramiko
|
||||
|
||||
from six.moves import range
|
||||
|
||||
FREEZERC = distutils.spawn.find_executable('freezer-agent')
|
||||
|
||||
|
|
|
@ -14,14 +14,14 @@
|
|||
|
||||
import unittest
|
||||
|
||||
import six
|
||||
import io
|
||||
|
||||
from freezer.engine.rsync import pyrsync
|
||||
|
||||
|
||||
class TestPyrsync(unittest.TestCase):
|
||||
def test_blockcheksum(self):
|
||||
instream = six.BytesIO(b'aae9dd83aa45f906'
|
||||
instream = io.BytesIO(b'aae9dd83aa45f906'
|
||||
b'a4629f42e97eac99'
|
||||
b'b9882284dc7030ca'
|
||||
b'427ad365fedd2a55')
|
||||
|
@ -34,7 +34,7 @@ class TestPyrsync(unittest.TestCase):
|
|||
self.assertEqual((weak, strong), (exp_weak, exp_strong))
|
||||
|
||||
def test_rsyncdelta(self):
|
||||
datastream = six.BytesIO(b'addc830058f917ae'
|
||||
datastream = io.BytesIO(b'addc830058f917ae'
|
||||
b'a1be5ab4d899b570'
|
||||
b'85c9534c64d8d71c'
|
||||
b'1f32cde9c71e5b6d')
|
||||
|
|
|
@ -12,12 +12,12 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import io
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
import mock
|
||||
from mock import patch
|
||||
from six import moves
|
||||
|
||||
from freezer.utils.checksum import CheckSum
|
||||
|
||||
|
@ -31,7 +31,7 @@ class TestChecksum(unittest.TestCase):
|
|||
self.hello_world_sha256sum = ('17b949eb67acf16bbf2605d57a01f7af4ff4b5'
|
||||
'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_multi = ('1b4bc4ff41172a5f29eaeffb7e9fc24c683c693'
|
||||
'9ab30132ad5d93a1e4a6b16e8')
|
||||
|
|
|
@ -12,10 +12,9 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import io
|
||||
import unittest
|
||||
|
||||
from six import moves
|
||||
|
||||
from freezer.utils import config
|
||||
|
||||
|
||||
|
@ -47,7 +46,7 @@ password = 'aNiceQuotedPassword'
|
|||
password2 = "aNiceQuotedPassword"
|
||||
spaced = value"""
|
||||
|
||||
fd = moves.cStringIO(string)
|
||||
fd = io.StringIO(string)
|
||||
res = config.ini_parse(fd)
|
||||
self.assertEqual('127.0.0.1', res['host'])
|
||||
self.assertEqual('openstack', res['user'])
|
||||
|
|
|
@ -15,8 +15,7 @@
|
|||
import hashlib
|
||||
import os
|
||||
|
||||
import six
|
||||
from six import moves
|
||||
import io
|
||||
|
||||
from freezer.utils import utils
|
||||
|
||||
|
@ -119,11 +118,7 @@ class CheckSum(object):
|
|||
# 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
|
||||
# unicode-escape. The effect of them is the same.
|
||||
if six.PY2 and 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):
|
||||
if isinstance(buf, str):
|
||||
buf = buf.encode('unicode-escape')
|
||||
|
||||
self.hasher.update(buf)
|
||||
|
@ -134,7 +129,7 @@ class CheckSum(object):
|
|||
"""
|
||||
:return: the hash for a given string
|
||||
"""
|
||||
fd = moves.StringIO(string)
|
||||
fd = io.StringIO(string)
|
||||
return self.hashfile(fd)
|
||||
|
||||
def compute(self):
|
||||
|
|
|
@ -12,12 +12,11 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import configparser
|
||||
import os
|
||||
import re
|
||||
|
||||
from oslo_log import log
|
||||
import six
|
||||
from six.moves import configparser
|
||||
|
||||
from freezer.utils import utils
|
||||
|
||||
|
@ -41,10 +40,7 @@ class Config(object):
|
|||
raise Exception("Configuration file {0} not found !".format(
|
||||
config_path))
|
||||
# SafeConfigParser was deprecated in Python 3.2
|
||||
if six.PY3:
|
||||
config = configparser.ConfigParser()
|
||||
else:
|
||||
config = configparser.SafeConfigParser()
|
||||
config.read([config_path])
|
||||
sections = config.sections()
|
||||
storages = []
|
||||
|
|
|
@ -20,7 +20,7 @@ Freezer general utils functions
|
|||
import threading
|
||||
|
||||
from oslo_log import log
|
||||
from six.moves import queue
|
||||
import queue
|
||||
|
||||
|
||||
LOG = log.getLogger(__name__)
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
Freezer general utils functions
|
||||
"""
|
||||
|
||||
import configparser
|
||||
import datetime
|
||||
import errno
|
||||
import fnmatch as fn
|
||||
|
@ -31,7 +32,6 @@ from distutils import spawn as distspawn
|
|||
from freezer.exceptions import utils
|
||||
from functools import wraps
|
||||
from oslo_log import log
|
||||
from six.moves import configparser
|
||||
|
||||
logging.getLogger('botocore').setLevel(logging.WARNING)
|
||||
|
||||
|
|
|
@ -107,7 +107,6 @@ rfc3986==1.1.0
|
|||
Routes==2.4.1
|
||||
setuptools==21.0.0
|
||||
simplejson==3.13.2
|
||||
six==1.10.0
|
||||
snowballstemmer==1.2.1
|
||||
Sphinx==1.6.2
|
||||
sphinxcontrib-websupport==1.0.1
|
||||
|
|
|
@ -23,7 +23,6 @@ cryptography>=2.1 # Apache-2.0
|
|||
PyMySQL>=0.7.6 # MIT License
|
||||
pymongo!=3.1,>=3.0.2 # Apache-2.0
|
||||
paramiko>=2.0.0 # LGPLv2.1+
|
||||
six>=1.10.0 # MIT
|
||||
|
||||
apscheduler>=3.0.5 # MIT License
|
||||
psutil>=3.2.2 # BSD
|
||||
|
|
Loading…
Reference in New Issue