Move toward python 3/2 compatible metaclass

Change-Id: Ia7e07a7530e26c388c5da3e362510233b6a65aa6
This commit is contained in:
Joshua Harlow
2013-10-09 17:33:12 -07:00
parent b2c82c8dce
commit 0abfe90eb3
9 changed files with 27 additions and 24 deletions

View File

@@ -19,10 +19,11 @@
import abc import abc
import six
class Action(object):
class Action(six.with_metaclass(abc.ABCMeta)):
"""Base action class""" """Base action class"""
__metaclass__ = abc.ABCMeta
@abc.abstractmethod @abc.abstractmethod
def execute(self, engine): def execute(self, engine):

View File

@@ -19,9 +19,11 @@
import abc import abc
import six
class EngineBase(object):
__metaclass__ = abc.ABCMeta class EngineBase(six.with_metaclass(abc.ABCMeta)):
"""Base for all engines implementations"""
def __init__(self, flow, flow_detail, backend, conf): def __init__(self, flow, flow_detail, backend, conf):
self._flow = flow self._flow = flow

View File

@@ -18,11 +18,13 @@
import abc import abc
import six
from taskflow.openstack.common import uuidutils from taskflow.openstack.common import uuidutils
from taskflow.utils import reflection from taskflow.utils import reflection
class Flow(object): class Flow(six.with_metaclass(abc.ABCMeta)):
"""The base abstract class of all flow implementations. """The base abstract class of all flow implementations.
It provides a name and an identifier (uuid or other) to the flow so that It provides a name and an identifier (uuid or other) to the flow so that
@@ -33,8 +35,6 @@ class Flow(object):
- __len__ - __len__
""" """
__metaclass__ = abc.ABCMeta
def __init__(self, name, uuid=None): def __init__(self, name, uuid=None):
self._name = str(name) self._name = str(name)
if uuid: if uuid:

View File

@@ -35,6 +35,7 @@ class Job(object):
so that the contained flows ownership can be transferred to the secondary so that the contained flows ownership can be transferred to the secondary
entity for resumption/continuation/reverting. entity for resumption/continuation/reverting.
""" """
def __init__(self, name, uuid=None): def __init__(self, name, uuid=None):
if uuid: if uuid:
self._uuid = uuid self._uuid = uuid

View File

@@ -19,14 +19,15 @@
import abc import abc
import six
class JobBoard(object):
class JobBoard(six.with_metaclass(abc.ABCMeta)):
"""A jobboard is an abstract representation of a place where jobs """A jobboard is an abstract representation of a place where jobs
can be posted, reposted, claimed and transferred. There can be multiple can be posted, reposted, claimed and transferred. There can be multiple
implementations of this job board, depending on the desired semantics and implementations of this job board, depending on the desired semantics and
capabilities of the underlying jobboard implementation. capabilities of the underlying jobboard implementation.
""" """
__metaclass__ = abc.ABCMeta
def __init__(self, name): def __init__(self, name):
self._name = name self._name = name

View File

@@ -21,6 +21,8 @@ from __future__ import absolute_import
import abc import abc
import logging import logging
import six
from taskflow import states from taskflow import states
from taskflow.utils import misc from taskflow.utils import misc
@@ -31,15 +33,13 @@ LOG = logging.getLogger(__name__)
FINISH_STATES = (states.FAILURE, states.SUCCESS) FINISH_STATES = (states.FAILURE, states.SUCCESS)
class LoggingBase(object): class LoggingBase(six.with_metaclass(abc.ABCMeta)):
"""This provides a simple listener that can be attached to an engine which """This provides a simple listener that can be attached to an engine which
can be derived from to log the received actions to some logging backend. It can be derived from to log the received actions to some logging backend. It
provides a useful context manager access to be able to register and provides a useful context manager access to be able to register and
unregister with a given engine automatically when a context is entered and unregister with a given engine automatically when a context is entered and
when it is exited. when it is exited.
""" """
__metaclass__ = abc.ABCMeta
def __init__(self, engine, def __init__(self, engine,
listen_for=misc.TransitionNotifier.ANY): listen_for=misc.TransitionNotifier.ANY):
self._listen_for = listen_for self._listen_for = listen_for

View File

@@ -18,12 +18,12 @@
import abc import abc
import six
class Backend(object):
class Backend(six.with_metaclass(abc.ABCMeta)):
"""Base class for persistence backends.""" """Base class for persistence backends."""
__metaclass__ = abc.ABCMeta
def __init__(self, conf): def __init__(self, conf):
self._conf = conf self._conf = conf
@@ -38,11 +38,9 @@ class Backend(object):
pass pass
class Connection(object): class Connection(six.with_metaclass(abc.ABCMeta)):
"""Base class for backend connections.""" """Base class for backend connections."""
__metaclass__ = abc.ABCMeta
@abc.abstractproperty @abc.abstractproperty
def backend(self): def backend(self):
"""Returns the backend this connection is associated with.""" """Returns the backend this connection is associated with."""

View File

@@ -19,12 +19,14 @@
import contextlib import contextlib
import logging import logging
import six
from taskflow import exceptions from taskflow import exceptions
from taskflow.openstack.common import uuidutils from taskflow.openstack.common import uuidutils
from taskflow.persistence import logbook from taskflow.persistence import logbook
from taskflow import states from taskflow import states
from taskflow.utils import misc from taskflow.utils import misc
from taskflow.utils import threading_utils from taskflow.utils import threading_utils as tu
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
STATES_WITH_RESULTS = (states.SUCCESS, states.REVERTING, states.FAILURE) STATES_WITH_RESULTS = (states.SUCCESS, states.REVERTING, states.FAILURE)
@@ -284,5 +286,5 @@ class Storage(object):
return state return state
class ThreadSafeStorage(Storage): class ThreadSafeStorage(six.with_metaclass(tu.ThreadSafeMeta, Storage)):
__metaclass__ = threading_utils.ThreadSafeMeta pass

View File

@@ -98,12 +98,10 @@ def _build_arg_mapping(task_name, reqs, rebind_args, function, do_infer):
return result return result
class BaseTask(object): class BaseTask(six.with_metaclass(abc.ABCMeta)):
"""An abstraction that defines a potential piece of work that can be """An abstraction that defines a potential piece of work that can be
applied and can be reverted to undo the work as a single unit. applied and can be reverted to undo the work as a single unit.
""" """
__metaclass__ = abc.ABCMeta
TASK_EVENTS = ('update_progress', ) TASK_EVENTS = ('update_progress', )
def __init__(self, name, provides=None): def __init__(self, name, provides=None):