[PATCH] Work around an old version of python-six.

Vratislav Podzimek vpodzime at redhat.com
Tue Sep 9 08:06:36 UTC 2014


On Wed, 2014-09-03 at 15:31 -0500, David Lehman wrote:
> Related: rhbz#1075561
> ---
>  blivet/devices.py |  2 +-
>  blivet/size.py    |  4 ++--
>  blivet/util.py    | 17 +++++++++++++++++
>  3 files changed, 20 insertions(+), 3 deletions(-)
> 
> diff --git a/blivet/devices.py b/blivet/devices.py
> index a0f8f56..5ff9f4a 100644
> --- a/blivet/devices.py
> +++ b/blivet/devices.py
> @@ -28,7 +28,7 @@ import abc
>  from decimal import Decimal
>  import re
>  
> -from six import add_metaclass
> +from util import add_metaclass
>  
>  # device backend modules
>  from .devicelibs import mdraid
> diff --git a/blivet/size.py b/blivet/size.py
> index b9f0089..2f4250f 100644
> --- a/blivet/size.py
> +++ b/blivet/size.py
> @@ -135,7 +135,7 @@ def _parseSpec(spec):
>      try:
>          # This will raise UnicodeDecodeError if specifier contains non-ascii
>          # characters
> -        if six.PY2:
> +        if not six.PY3:
>              spec_ascii = specifier.decode("ascii")
>              # Convert back to a str type to match the _bytes and _prefixes arrays
>              spec_ascii = str(spec_ascii)
> @@ -163,7 +163,7 @@ def _parseSpec(spec):
>  
>      # No English match found, try localized size specs. Accept any utf-8
>      # character and leave the result as a (unicode object.
> -    if six.PY2:
> +    if not six.PY3:
>          spec_local = specifier.decode("utf-8")
>      else:
>          # str = unicode in Python3
> diff --git a/blivet/util.py b/blivet/util.py
> index 1e28ddc..2dceed9 100644
> --- a/blivet/util.py
> +++ b/blivet/util.py
> @@ -438,3 +438,20 @@ def variable_copy(obj, memo, omit=None, shallow=None, duplicate=None):
>              setattr(new, attr, copy.deepcopy(value, memo))
>  
>      return new
> +
> +# Borrowed from python-six-1.6.1 for use in an environment which only has
> +# python-six-1.3.0, which does not provide add_metaclass.
> +def add_metaclass(metaclass):
> +    """Class decorator for creating a class with a metaclass."""
> +    def wrapper(cls):
> +        orig_vars = cls.__dict__.copy()
> +        orig_vars.pop('__dict__', None)
> +        orig_vars.pop('__weakref__', None)
> +        slots = orig_vars.get('__slots__')
> +        if slots is not None:
> +            if isinstance(slots, str):
> +                slots = [slots]
> +            for slots_var in slots:
> +                orig_vars.pop(slots_var)
> +        return metaclass(cls.__name__, cls.__bases__, orig_vars)
> +    return wrapper
A guy, that tried to make blivet-gui running on a RHEL 7 system sent me
the following patch containing some more changes:

> diff -up ./blivet/devicelibs/raid.py.rhel7 ./blivet/devicelibs/raid.py
> --- ./blivet/devicelibs/raid.py.rhel7	2014-08-29 04:50:52.000000000 +0200
> +++ ./blivet/devicelibs/raid.py	2014-09-08 17:38:56.199104927 +0200
> @@ -23,7 +23,7 @@
>  
>  import abc
>  
> -from six import add_metaclass
> +from .. util import add_metaclass
>  
>  from ..errors import RaidError
>  
> diff -up ./blivet/devices.py.rhel7 ./blivet/devices.py
> --- ./blivet/devices.py.rhel7	2014-08-29 04:50:52.000000000 +0200
> +++ ./blivet/devices.py	2014-09-08 17:37:51.309780874 +0200
> @@ -29,7 +29,7 @@ from decimal import Decimal
>  import re
>  import pyudev
>  
> -from six import add_metaclass
> +from util import add_metaclass
>  
>  # device backend modules
>  from .devicelibs import mdraid
> diff -up ./blivet/formats/fslabeling.py.rhel7 ./blivet/formats/fslabeling.py
> --- ./blivet/formats/fslabeling.py.rhel7	2014-08-29 04:50:52.000000000 +0200
> +++ ./blivet/formats/fslabeling.py	2014-09-08 17:39:06.525839405 +0200
> @@ -21,7 +21,7 @@
>  
>  import abc
>  
> -from six import add_metaclass
> +from .. util import add_metaclass
>  
>  from . import fslabel
>  
> diff -up ./blivet/formats/fslabel.py.rhel7 ./blivet/formats/fslabel.py
> --- ./blivet/formats/fslabel.py.rhel7	2014-08-29 04:50:52.000000000 +0200
> +++ ./blivet/formats/fslabel.py	2014-09-08 17:38:45.065393647 +0200
> @@ -22,7 +22,7 @@
>  import abc
>  import re
>  
> -from six import add_metaclass
> +from .. util import add_metaclass
>  
>  from .. import errors
>  
> diff -up ./blivet/size.py.rhel7 ./blivet/size.py
> --- ./blivet/size.py.rhel7	2014-08-29 04:50:52.000000000 +0200
> +++ ./blivet/size.py	2014-09-08 17:37:51.309780874 +0200
> @@ -135,7 +135,7 @@ def _parseSpec(spec):
>      try:
>          # This will raise UnicodeDecodeError if specifier contains non-ascii
>          # characters
> -        if six.PY2:
> +        if not six.PY3:
>              spec_ascii = specifier.decode("ascii")
>              # Convert back to a str type to match the _bytes and _prefixes arrays
>              spec_ascii = str(spec_ascii)
> @@ -163,7 +163,7 @@ def _parseSpec(spec):
>  
>      # No English match found, try localized size specs. Accept any utf-8
>      # character and leave the result as a (unicode object.
> -    if six.PY2:
> +    if not six.PY3:
>          spec_local = specifier.decode("utf-8")
>      else:
>          # str = unicode in Python3
> diff -up ./blivet/util.py.rhel7 ./blivet/util.py
> --- ./blivet/util.py.rhel7	2014-08-29 04:50:52.000000000 +0200
> +++ ./blivet/util.py	2014-09-08 17:37:51.310780847 +0200
> @@ -454,3 +454,20 @@ def variable_copy(obj, memo, omit=None,
>              setattr(new, attr, copy.deepcopy(value, memo))
>  
>      return new
> +
> +# Borrowed from python-six-1.6.1 for use in an environment which only has
> +# python-six-1.3.0, which does not provide add_metaclass.
> +def add_metaclass(metaclass):
> +    """Class decorator for creating a class with a metaclass."""
> +    def wrapper(cls):
> +        orig_vars = cls.__dict__.copy()
> +        orig_vars.pop('__dict__', None)
> +        orig_vars.pop('__weakref__', None)
> +        slots = orig_vars.get('__slots__')
> +        if slots is not None:
> +            if isinstance(slots, str):
> +                slots = [slots]
> +            for slots_var in slots:
> +                orig_vars.pop(slots_var)
> +        return metaclass(cls.__name__, cls.__bases__, orig_vars)
> +    return wrapper

-- 
Vratislav Podzimek

Anaconda Rider | RHCE | Red Hat, Inc. | Brno - Czech Republic




More information about the anaconda-patches mailing list