Skip to content

Commit

Permalink
Remove Python SIX usage
Browse files Browse the repository at this point in the history
We stopped caring about Python 2 support long time ago and with
libblockdev 3.0 which is Python 3 only it wouldn't even be
possible to support Python 2 so we should finally remove it.
  • Loading branch information
vojtechtrefny committed Feb 1, 2024
1 parent 53dfc31 commit 8a2e395
Show file tree
Hide file tree
Showing 65 changed files with 203 additions and 427 deletions.
4 changes: 1 addition & 3 deletions blivet/actionlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

import copy
from functools import wraps
from six import add_metaclass

from .callbacks import callbacks as _callbacks
from .deviceaction import ActionCreateDevice
Expand Down Expand Up @@ -53,8 +52,7 @@ def wrapped_func(obj, *args, **kwargs):
return run_func_with_flag_attr_set


@add_metaclass(SynchronizedMeta)
class ActionList(object):
class ActionList(object, metaclass=SynchronizedMeta):
_unsynchronized_methods = ['process']

def __init__(self, addfunc=None, removefunc=None):
Expand Down
4 changes: 1 addition & 3 deletions blivet/blivet.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import contextlib
import time
import functools
import six

from .storage_log import log_method_call, log_exception_info
from .devices import BTRFSSubVolumeDevice, BTRFSVolumeDevice
Expand Down Expand Up @@ -59,8 +58,7 @@
FSTAB_PATH = "/etc/fstab"


@six.add_metaclass(SynchronizedMeta)
class Blivet(object):
class Blivet(object, metaclass=SynchronizedMeta):

""" Top-level class for managing storage configuration. """

Expand Down
10 changes: 2 additions & 8 deletions blivet/deviceaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@

import copy

from six import add_metaclass

from . import util
from . import udev
from .errors import DependencyError, PartitioningError
Expand Down Expand Up @@ -108,8 +106,7 @@ def resize_type_from_string(type_string):
return k


@add_metaclass(SynchronizedMeta)
class DeviceAction(util.ObjectID):
class DeviceAction(util.ObjectID, metaclass=SynchronizedMeta):

""" An action that will be carried out in the future on a Device.
Expand Down Expand Up @@ -295,10 +292,7 @@ def _to_string(self):
return s

def __str__(self):
return util.stringize(self._to_string())

def __unicode__(self):
return util.unicodeize(self._to_string())
return self._to_string()

def requires(self, action):
""" Return True if self requires action. """
Expand Down
8 changes: 3 additions & 5 deletions blivet/devicefactory.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
# Red Hat Author(s): David Lehman <[email protected]>
#

from six import raise_from

from .storage_log import log_method_call
from .errors import DeviceFactoryError, StorageError
from .devices import BTRFSDevice, DiskDevice
Expand Down Expand Up @@ -746,7 +744,7 @@ def _create_device(self):
except (StorageError, blockdev.BlockDevError) as e:
log.error("device post-create method failed: %s", e)
self.storage.destroy_device(device)
raise_from(StorageError(e), e)
raise StorageError(e) from e
else:
if not device.size:
self.storage.destroy_device(device)
Expand Down Expand Up @@ -941,7 +939,7 @@ def configure(self):
self._revert_devicetree()

if not isinstance(e, (StorageError, OverflowError)):
raise_from(DeviceFactoryError(e), e)
raise DeviceFactoryError(e) from e

raise

Expand Down Expand Up @@ -2189,7 +2187,7 @@ def _create_device(self):
except (StorageError, blockdev.BlockDevError) as e:
log.error("device post-create method failed: %s", e)
self.storage.destroy_device(device)
raise_from(StorageError(e), e)
raise StorageError(e) from e
else:
if not device.size:
self.storage.destroy_device(device)
Expand Down
8 changes: 2 additions & 6 deletions blivet/devicelibs/raid.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@

import abc

from six import add_metaclass

from ..errors import RaidError
from ..size import Size

Expand All @@ -38,8 +36,7 @@ def div_up(a, b):
return (a + (b - 1)) // b


@add_metaclass(abc.ABCMeta)
class RAIDLevel(object):
class RAIDLevel(object, metaclass=abc.ABCMeta):

"""An abstract class which is the parent of all classes which represent
a RAID level.
Expand Down Expand Up @@ -77,8 +74,7 @@ def __deepcopy__(self, memo):
return self


@add_metaclass(abc.ABCMeta)
class RAIDn(RAIDLevel):
class RAIDn(RAIDLevel, metaclass=abc.ABCMeta):

"""An abstract class which is the parent of classes which represent a
numeric RAID level. A better word would be classification, since 'level'
Expand Down
10 changes: 3 additions & 7 deletions blivet/devices/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,10 @@
"""

from six import add_metaclass
import abc


@add_metaclass(abc.ABCMeta)
class Cache(object):
class Cache(object, metaclass=abc.ABCMeta):

"""Abstract base class for cache objects providing the cache-related
functionality on cached devices. Instances of this class are not expected to
Expand Down Expand Up @@ -74,8 +72,7 @@ def detach(self):
"""


@add_metaclass(abc.ABCMeta)
class CacheStats(object):
class CacheStats(object, metaclass=abc.ABCMeta):

"""Abstract base class for common statistics of caches (cached
devices). Inheriting classes are expected to add (cache-)type-specific
Expand Down Expand Up @@ -109,8 +106,7 @@ def misses(self):
"""number of misses"""


@add_metaclass(abc.ABCMeta)
class CacheRequest(object):
class CacheRequest(object, metaclass=abc.ABCMeta):

"""Abstract base class for cache requests specifying cache parameters for a
cached device
Expand Down
5 changes: 1 addition & 4 deletions blivet/devices/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@

import abc

from six import add_metaclass

from .. import errors
from ..storage_log import log_method_call
from ..formats import get_device_format_class
Expand All @@ -34,8 +32,7 @@
from .storage import StorageDevice


@add_metaclass(SynchronizedABCMeta)
class ContainerDevice(StorageDevice):
class ContainerDevice(StorageDevice, metaclass=SynchronizedABCMeta):

""" A device that aggregates a set of member devices.
Expand Down
9 changes: 2 additions & 7 deletions blivet/devices/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#

import pprint
from six import add_metaclass

from .. import util
from ..storage_log import log_method_call
Expand All @@ -33,8 +32,7 @@
from .lib import ParentList


@add_metaclass(SynchronizedMeta)
class Device(util.ObjectID):
class Device(util.ObjectID, metaclass=SynchronizedMeta):

""" A generic device.
Expand Down Expand Up @@ -118,10 +116,7 @@ def _to_string(self):
return s

def __str__(self):
return util.stringize(self._to_string())

def __unicode__(self):
return util.unicodeize(self._to_string())
return self._to_string()

def _add_parent(self, parent):
""" Called before adding a parent to this device.
Expand Down
9 changes: 4 additions & 5 deletions blivet/devices/lvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
from collections import namedtuple, defaultdict
from functools import wraps
from enum import Enum
import six

import gi
gi.require_version("BlockDev", "3.0")
Expand Down Expand Up @@ -1825,8 +1824,8 @@ def _create(self):
extra["profile"] = profile_name
if self.chunk_size:
extra["chunksize"] = str(int(self.chunk_size))
data_lv = six.next(lv for lv in self._internal_lvs if lv.int_lv_type == LVMInternalLVtype.data)
meta_lv = six.next(lv for lv in self._internal_lvs if lv.int_lv_type == LVMInternalLVtype.meta)
data_lv = next(lv for lv in self._internal_lvs if lv.int_lv_type == LVMInternalLVtype.data)
meta_lv = next(lv for lv in self._internal_lvs if lv.int_lv_type == LVMInternalLVtype.meta)
try:
blockdev.lvm.thpool_convert(self.vg.name, data_lv.lvname, meta_lv.lvname, self.lvname, **extra)
except blockdev.LVMError as err:
Expand Down Expand Up @@ -2346,8 +2345,8 @@ def _create(self):
if self.mode:
# we need the string here, it will be passed directly to he lvm command
extra["cachemode"] = self._cache_mode
data_lv = six.next(lv for lv in self._internal_lvs if lv.int_lv_type == LVMInternalLVtype.data)
meta_lv = six.next(lv for lv in self._internal_lvs if lv.int_lv_type == LVMInternalLVtype.meta)
data_lv = next(lv for lv in self._internal_lvs if lv.int_lv_type == LVMInternalLVtype.data)
meta_lv = next(lv for lv in self._internal_lvs if lv.int_lv_type == LVMInternalLVtype.meta)
try:
blockdev.lvm.cache_pool_convert(self.vg.name, data_lv.lvname, meta_lv.lvname, self.lvname, **extra)
except blockdev.LVMError as err:
Expand Down
5 changes: 2 additions & 3 deletions blivet/devices/md.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@

import math
import os
import six
import time

from six.moves import reduce
from functools import reduce

import gi
gi.require_version("BlockDev", "3.0")
Expand Down Expand Up @@ -355,7 +354,7 @@ def _get_member_devices(self):
return self._member_devices

def _set_member_devices(self, number):
if not isinstance(number, six.integer_types):
if not isinstance(number, int):
raise ValueError("member_devices must be an integer")

if not self.exists and number > self.total_devices:
Expand Down
5 changes: 1 addition & 4 deletions blivet/devices/raid.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,14 @@

import abc

from six import add_metaclass

from .. import errors
from ..i18n import _, P_
from ..threads import SynchronizedABCMeta

from .storage import StorageDevice


@add_metaclass(SynchronizedABCMeta)
class RaidDevice(StorageDevice):
class RaidDevice(StorageDevice, metaclass=SynchronizedABCMeta):

""" Metaclass for devices that support RAID in some form. """
members = abc.abstractproperty(lambda s: [],
Expand Down
26 changes: 12 additions & 14 deletions blivet/devicetree.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import os
import pprint
import re
import six

import gi
gi.require_version("BlockDev", "3.0")
Expand Down Expand Up @@ -52,8 +51,7 @@
_LVM_DEVICE_CLASSES = (LVMLogicalVolumeDevice, LVMVolumeGroupDevice)


@six.add_metaclass(SynchronizedMeta)
class DeviceTreeBase(object):
class DeviceTreeBase(object, metaclass=SynchronizedMeta):
""" A quasi-tree that represents the devices in the system.
The tree contains a list of :class:`~.devices.StorageDevice` instances,
Expand Down Expand Up @@ -500,7 +498,7 @@ def get_device_by_sysfs_path(self, path, incomplete=False, hidden=False):
result = None
if path:
devices = self._filter_devices(incomplete=incomplete, hidden=hidden)
result = six.next((d for d in devices if d.sysfs_path == path), None)
result = next((d for d in devices if d.sysfs_path == path), None)
log_method_return(self, result)
return result

Expand All @@ -517,7 +515,7 @@ def get_device_by_uuid(self, uuid, incomplete=False, hidden=False):
result = None
if uuid:
devices = self._filter_devices(incomplete=incomplete, hidden=hidden)
result = six.next((d for d in devices if d.uuid == uuid or d.format.uuid == uuid), None)
result = next((d for d in devices if d.uuid == uuid or d.format.uuid == uuid), None)
log_method_return(self, result)
return result

Expand All @@ -534,7 +532,7 @@ def get_device_by_label(self, label, incomplete=False, hidden=False):
result = None
if label:
devices = self._filter_devices(incomplete=incomplete, hidden=hidden)
result = six.next((d for d in devices if getattr(d.format, "label", None) == label), None)
result = next((d for d in devices if getattr(d.format, "label", None) == label), None)
log_method_return(self, result)
return result

Expand All @@ -551,9 +549,9 @@ def get_device_by_name(self, name, incomplete=False, hidden=False):
result = None
if name:
devices = self._filter_devices(incomplete=incomplete, hidden=hidden)
result = six.next((d for d in devices if d.name == name or
(isinstance(d, _LVM_DEVICE_CLASSES) and d.name == name.replace("--", "-"))),
None)
result = next((d for d in devices if d.name == name or
(isinstance(d, _LVM_DEVICE_CLASSES) and d.name == name.replace("--", "-"))),
None)
log_method_return(self, result)
return result

Expand All @@ -577,9 +575,9 @@ def get_device_by_path(self, path, incomplete=False, hidden=False):
# The usual order of the devices list is one where leaves are at
# the end. So that the search can prefer leaves to interior nodes
# the list that is searched is the reverse of the devices list.
result = six.next((d for d in reversed(list(devices)) if d.path == path or
(isinstance(d, _LVM_DEVICE_CLASSES) and d.path == path.replace("--", "-"))),
None)
result = next((d for d in reversed(list(devices)) if d.path == path or
(isinstance(d, _LVM_DEVICE_CLASSES) and d.path == path.replace("--", "-"))),
None)

log_method_return(self, result)
return result
Expand All @@ -595,7 +593,7 @@ def get_device_by_id(self, id_num, incomplete=False, hidden=False):
"""
log_method_call(self, id_num=id_num, incomplete=incomplete, hidden=hidden)
devices = self._filter_devices(incomplete=incomplete, hidden=hidden)
result = six.next((d for d in devices if d.id == id_num), None)
result = next((d for d in devices if d.id == id_num), None)
log_method_return(self, result)
return result

Expand All @@ -610,7 +608,7 @@ def get_device_by_device_id(self, device_id, incomplete=False, hidden=False):
"""
log_method_call(self, device_id=device_id, incomplete=incomplete, hidden=hidden)
devices = self._filter_devices(incomplete=incomplete, hidden=hidden)
result = six.next((d for d in devices if d.device_id == device_id), None)
result = next((d for d in devices if d.device_id == device_id), None)
log_method_return(self, result)
return result

Expand Down
5 changes: 1 addition & 4 deletions blivet/events/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
# Red Hat Author(s): David Lehman <[email protected]>
#

from six import add_metaclass

from ..callbacks import callbacks
from ..errors import DeviceError, EventHandlingError
from ..devices import DM_MAJORS, MD_MAJORS
Expand All @@ -37,8 +35,7 @@
event_log = logging.getLogger("blivet.event")


@add_metaclass(SynchronizedMeta)
class EventHandlerMixin(object):
class EventHandlerMixin(object, metaclass=SynchronizedMeta):
def __init__(self):
event_manager.handler_cb = self.handle_event

Expand Down
Loading

0 comments on commit 8a2e395

Please sign in to comment.