# Path: charms/reactive/flags.py
# @cmdline.subcommand()
# @cmdline.test_command
# def any_flags_set(*desired_flags):
#     """Assert that any of the desired_flags are set"""
#     active_flags = get_flags()
#     return any(flag in active_flags for flag in desired_flags)
# 
# @cmdline.subcommand()
# @cmdline.test_command
# def all_flags_set(*desired_flags):
#     """Assert that all desired_flags are set"""
#     active_flags = get_flags()
#     return all(flag in active_flags for flag in desired_flags)
# 
# Path: charms/reactive/flags.py
# @cmdline.subcommand()
# @cmdline.test_command
# def is_state(state):
#     """
#     .. deprecated:: 0.5.0
#        Alias for :func:`is_flag_set`"""
#     return is_flag_set(state)
# 
# @cmdline.subcommand()
# @cmdline.test_command
# def all_states(*desired_states):
#     """
#     .. deprecated:: 0.5.0
#        Alias for :func:`all_flags_set`"""
#     return all_flags_set(*desired_states)
# 
# @cmdline.subcommand()
# @cmdline.test_command
# def any_states(*desired_states):
#     """
#     .. deprecated:: 0.5.0
#        Alias for :func:`any_flags_set`"""
#     return any_flags_set(*desired_states)


import re
import json
import hashlib
from charmhelpers.core import host
from charmhelpers.core import hookenv
from charmhelpers.core import unitdata
from charmhelpers.cli import cmdline
from charms.reactive.flags import any_flags_set, all_flags_set
from charms.reactive.flags import is_state, all_states, any_states  # noqa


def _hook(hook_patterns):
    dispatch_phase = unitdata.kv().get('reactive.dispatch.phase')
    return dispatch_phase == 'hooks' and any_hook(*hook_patterns)


def _restricted_hook(hook_name):
    current_hook = hookenv.hook_name()
    dispatch_phase = unitdata.kv().get('reactive.dispatch.phase')
    return dispatch_phase == 'restricted' and current_hook == hook_name


def _when_all(flags):
    dispatch_phase = unitdata.kv().get('reactive.dispatch.phase')
    return dispatch_phase == 'other' and all_flags_set(*flags)


def _when_any(flags):
    dispatch_phase = unitdata.kv().get('reactive.dispatch.phase')
    return dispatch_phase == 'other' and any_flags_set(*flags)


def _when_none(flags):
    dispatch_phase = unitdata.kv().get('reactive.dispatch.phase')
    return dispatch_phase == 'other' and not any_flags_set(*flags)


def _when_not_all(flags):
    dispatch_phase = unitdata.kv().get('reactive.dispatch.phase')

# Path: charms/reactive/flags.py
# @cmdline.subcommand()
# @cmdline.test_command
# def any_flags_set(*desired_flags):
#     """Assert that any of the desired_flags are set"""
#     active_flags = get_flags()
#     return any(flag in active_flags for flag in desired_flags)
# 
# @cmdline.subcommand()
# @cmdline.test_command
# def all_flags_set(*desired_flags):
#     """Assert that all desired_flags are set"""
#     active_flags = get_flags()
#     return all(flag in active_flags for flag in desired_flags)
# 
# Path: charms/reactive/flags.py
# @cmdline.subcommand()
# @cmdline.test_command
# def is_state(state):
#     """
#     .. deprecated:: 0.5.0
#        Alias for :func:`is_flag_set`"""
#     return is_flag_set(state)
# 
# @cmdline.subcommand()
# @cmdline.test_command
# def all_states(*desired_states):
#     """
#     .. deprecated:: 0.5.0
#        Alias for :func:`all_flags_set`"""
#     return all_flags_set(*desired_states)
# 
# @cmdline.subcommand()
# @cmdline.test_command
# def any_states(*desired_states):
#     """
#     .. deprecated:: 0.5.0
#        Alias for :func:`any_flags_set`"""
#     return any_flags_set(*desired_states)


# Path: charms/reactive/helpers.py
import re
import json
import hashlib
from charmhelpers.core import host
from charmhelpers.core import hookenv
from charmhelpers.core import unitdata
from charmhelpers.cli import cmdline
from charms.reactive.flags import any_flags_set, all_flags_set
from charms.reactive.flags import is_state, all_states, any_states  # noqa



def _hook(hook_patterns):
    dispatch_phase = unitdata.kv().get('reactive.dispatch.phase')
    return dispatch_phase == 'hooks' and any_hook(*hook_patterns)


def _restricted_hook(hook_name):
    current_hook = hookenv.hook_name()
    dispatch_phase = unitdata.kv().get('reactive.dispatch.phase')
    return dispatch_phase == 'restricted' and current_hook == hook_name


def _when_all(flags):
    dispatch_phase = unitdata.kv().get('reactive.dispatch.phase')
    return dispatch_phase == 'other' and all_flags_set(*flags)


def _when_any(flags):
    dispatch_phase = unitdata.kv().get('reactive.dispatch.phase')
    return dispatch_phase == 'other' and any_flags_set(*flags)


def _when_none(flags):
    dispatch_phase = unitdata.kv().get('reactive.dispatch.phase')
    return dispatch_phase == 'other' and not any_flags_set(*flags)


def _when_not_all(flags):
    dispatch_phase = unitdata.kv().get('reactive.dispatch.phase')

    return dispatch_phase == 'other' and not all_flags_set(*flags)