From 0abfe90eb36e1205ce4ccedfa3c389a66c744ddb Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Wed, 9 Oct 2013 17:33:12 -0700 Subject: [PATCH] Move toward python 3/2 compatible metaclass Change-Id: Ia7e07a7530e26c388c5da3e362510233b6a65aa6 --- taskflow/engines/action_engine/base_action.py | 5 +++-- taskflow/engines/base.py | 6 ++++-- taskflow/flow.py | 6 +++--- taskflow/jobs/job.py | 1 + taskflow/jobs/jobboard.py | 5 +++-- taskflow/listeners/base.py | 6 +++--- taskflow/persistence/backends/base.py | 10 ++++------ taskflow/storage.py | 8 +++++--- taskflow/task.py | 4 +--- 9 files changed, 27 insertions(+), 24 deletions(-) diff --git a/taskflow/engines/action_engine/base_action.py b/taskflow/engines/action_engine/base_action.py index 9cc3512a..211b18eb 100644 --- a/taskflow/engines/action_engine/base_action.py +++ b/taskflow/engines/action_engine/base_action.py @@ -19,10 +19,11 @@ import abc +import six -class Action(object): + +class Action(six.with_metaclass(abc.ABCMeta)): """Base action class""" - __metaclass__ = abc.ABCMeta @abc.abstractmethod def execute(self, engine): diff --git a/taskflow/engines/base.py b/taskflow/engines/base.py index ac51857b..b627af08 100644 --- a/taskflow/engines/base.py +++ b/taskflow/engines/base.py @@ -19,9 +19,11 @@ 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): self._flow = flow diff --git a/taskflow/flow.py b/taskflow/flow.py index 00a23e8d..049a173d 100644 --- a/taskflow/flow.py +++ b/taskflow/flow.py @@ -18,11 +18,13 @@ import abc +import six + from taskflow.openstack.common import uuidutils from taskflow.utils import reflection -class Flow(object): +class Flow(six.with_metaclass(abc.ABCMeta)): """The base abstract class of all flow implementations. It provides a name and an identifier (uuid or other) to the flow so that @@ -33,8 +35,6 @@ class Flow(object): - __len__ """ - __metaclass__ = abc.ABCMeta - def __init__(self, name, uuid=None): self._name = str(name) if uuid: diff --git a/taskflow/jobs/job.py b/taskflow/jobs/job.py index cf98fb74..93715950 100644 --- a/taskflow/jobs/job.py +++ b/taskflow/jobs/job.py @@ -35,6 +35,7 @@ class Job(object): so that the contained flows ownership can be transferred to the secondary entity for resumption/continuation/reverting. """ + def __init__(self, name, uuid=None): if uuid: self._uuid = uuid diff --git a/taskflow/jobs/jobboard.py b/taskflow/jobs/jobboard.py index 551227ce..b01fca0d 100644 --- a/taskflow/jobs/jobboard.py +++ b/taskflow/jobs/jobboard.py @@ -19,14 +19,15 @@ 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 can be posted, reposted, claimed and transferred. There can be multiple implementations of this job board, depending on the desired semantics and capabilities of the underlying jobboard implementation. """ - __metaclass__ = abc.ABCMeta def __init__(self, name): self._name = name diff --git a/taskflow/listeners/base.py b/taskflow/listeners/base.py index 15e86327..2ff98639 100644 --- a/taskflow/listeners/base.py +++ b/taskflow/listeners/base.py @@ -21,6 +21,8 @@ from __future__ import absolute_import import abc import logging +import six + from taskflow import states from taskflow.utils import misc @@ -31,15 +33,13 @@ LOG = logging.getLogger(__name__) 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 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 unregister with a given engine automatically when a context is entered and when it is exited. """ - __metaclass__ = abc.ABCMeta - def __init__(self, engine, listen_for=misc.TransitionNotifier.ANY): self._listen_for = listen_for diff --git a/taskflow/persistence/backends/base.py b/taskflow/persistence/backends/base.py index 070d7371..b405564e 100644 --- a/taskflow/persistence/backends/base.py +++ b/taskflow/persistence/backends/base.py @@ -18,12 +18,12 @@ import abc +import six -class Backend(object): + +class Backend(six.with_metaclass(abc.ABCMeta)): """Base class for persistence backends.""" - __metaclass__ = abc.ABCMeta - def __init__(self, conf): self._conf = conf @@ -38,11 +38,9 @@ class Backend(object): pass -class Connection(object): +class Connection(six.with_metaclass(abc.ABCMeta)): """Base class for backend connections.""" - __metaclass__ = abc.ABCMeta - @abc.abstractproperty def backend(self): """Returns the backend this connection is associated with.""" diff --git a/taskflow/storage.py b/taskflow/storage.py index 15bfa537..88f06901 100644 --- a/taskflow/storage.py +++ b/taskflow/storage.py @@ -19,12 +19,14 @@ import contextlib import logging +import six + from taskflow import exceptions from taskflow.openstack.common import uuidutils from taskflow.persistence import logbook from taskflow import states from taskflow.utils import misc -from taskflow.utils import threading_utils +from taskflow.utils import threading_utils as tu LOG = logging.getLogger(__name__) STATES_WITH_RESULTS = (states.SUCCESS, states.REVERTING, states.FAILURE) @@ -284,5 +286,5 @@ class Storage(object): return state -class ThreadSafeStorage(Storage): - __metaclass__ = threading_utils.ThreadSafeMeta +class ThreadSafeStorage(six.with_metaclass(tu.ThreadSafeMeta, Storage)): + pass diff --git a/taskflow/task.py b/taskflow/task.py index 300286eb..1e8512de 100644 --- a/taskflow/task.py +++ b/taskflow/task.py @@ -98,12 +98,10 @@ def _build_arg_mapping(task_name, reqs, rebind_args, function, do_infer): return result -class BaseTask(object): +class BaseTask(six.with_metaclass(abc.ABCMeta)): """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. """ - __metaclass__ = abc.ABCMeta - TASK_EVENTS = ('update_progress', ) def __init__(self, name, provides=None):