Skip to content

Commit

Permalink
Add a flag to ActionList to indicate in-progresss action processing.
Browse files Browse the repository at this point in the history
  • Loading branch information
dwlehman committed Jan 28, 2016
1 parent 255755c commit dc91b81
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions blivet/actionlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#

import copy
from functools import wraps

from .deviceaction import ActionCreateDevice
from .deviceaction import action_type_from_string, action_object_from_string
Expand All @@ -35,6 +36,21 @@
log = logging.getLogger("blivet")


def with_flag(flag_attr):
def run_func_with_flag_attr_set(func):
@wraps(func)
def wrapped_func(*args, **kwargs):

This comment has been minimized.

Copy link
@vpodzime

vpodzime Jan 29, 2016

I'd prefer here the (self, *args, **kwargs) argument list so that it is clear that this decorator should only be used on methods. Also some docstring would be nice even if just a single sentence.

setattr(args[0], flag_attr, True)
try:
return func(*args, **kwargs)
finally:
setattr(args[0], flag_attr, False)

return wrapped_func

return run_func_with_flag_attr_set


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

Expand All @@ -43,6 +59,7 @@ def __init__(self, addfunc=None, removefunc=None):
self._remove_func = removefunc
self._actions = []
self._completed_actions = []
self.processing = False

def __iter__(self):
return iter(self._actions)
Expand Down Expand Up @@ -278,6 +295,7 @@ def _find_active_devices_on_action_disks(self, devices=None):
devices = [a.name for a in active if any(d in disks for d in a.disks)]
return devices

@with_flag("processing")
def process(self, callbacks=None, devices=None, dry_run=None):
"""
Execute all registered actions.
Expand Down

0 comments on commit dc91b81

Please sign in to comment.