Пример #1
0
"""
from mpx_test import DefaultTestFixture, main

from mpx.lib import ReloadableSingletonFactory

class Incrementor:
    def __init__(self):
        self.__value = 0
        return
    def singleton_unload_hook(self):
        return
    def value(self):
        self.__value += 1
        return self.__value

INC = ReloadableSingletonFactory(Incrementor)

class TestCase(DefaultTestFixture):
    def test_load_1(self):
        if INC.value() != 1:
            raise "Singleton not reloaded."
        return
    def test_load_2(self):
        if INC.value() != 1:
            raise "Singleton not reloaded."
        return
    def test_load_3(self):
        if INC.value() != 1:
            raise "Singleton not reloaded."
        return
Пример #2
0
        if self._did_save:
            self._data.save()

    def _path_is_parent(self, path, node):
        # If they are the same, we aren't talking a parent/child relationship here
        if path == node:
            return 0
        strind = string.find(node, path)
        if strind == -1:
            return 0
        if strind == 0:
            return 1
        # If we got something other than -1 or 0 here, strange things are
        # happening.  Dump a message to msglog so that whatever is wrong
        # can be fixed.
        msglog.log(
            'garbage_collector',msglog.types.INFO,
            '_path_is_parent: Found %s at a weird spot in %s.' % (node,
                                                                  parent)
            )
        return 1
    ##
    # Return a tuple of dict()s describing all the registered PDOs.
    # @note DO NOT MODIFY THE DICT()s IN THE TUPLE!
    def registered_pdo_tuple(self):
        return self._registered

# Create the garbage handler singleton
from mpx.lib import ReloadableSingletonFactory
GARBAGE_COLLECTOR = ReloadableSingletonFactory(GarbageCollector)
Пример #3
0
                )
        return self.__device
    
    device = property(_get_device)

class OverrideDecorator(OverrideMixin, NodeDecorator):
    _PREFIX = 'ovr_decorator_'
    def __init__(self, *args, **kw):
        OverrideMixin.__init__(self)
        NodeDecorator.__init__(self)
        
    def start(self):
        # OverrideDecorators manage the override behavior of their parent node.
        #directly_provides(self.parent, IOverridable)
        self._set_target = self.parent
        for attr in ['override', 'release' 'get_override', 'set_default', 'get_default']:
            self.set_attribute(attr, getattr(self, attr), {}, strict=False)
                
def add_override(node, **kw):
    assert is_settable(node), (
        'Node\'s must support the set method before adding override behavior.'
        )
    cd = {'name':'__override__',
          'parent':node}
    ovr = OverrideDecorator(kw)
    ovr.configure(cd)
    ovr.start()
    
OVERRIDE_MANAGER = ReloadableSingletonFactory(OverrideManager)

Пример #4
0
        self._put_entry('fail_list', nodepath, fail_list)

    def get_sync_state(self, nodepath):
        return self._get_entry('sync_state', nodepath)

    def put_sync_state(self, nodepath, sync_state):
        self._put_entry('sync_state', nodepath, sync_state)

    def get_override(self, nodepath):
        return self._get_entry('override', nodepath)

    def put_override(self, nodepath, override):
        self._put_entry('override', nodepath, override)

    def _get_entry(self, ptype, nodepath):
        return self.get_sched(normalize_nodepath(nodepath))[ptype]

    def _put_entry(self, ptype, nodepath, value):
        nodepath = normalize_nodepath(nodepath)
        sched = self.get_sched(nodepath)
        assert sched, \
        'A schedule must exist before data can be stored against it.'
        sched[ptype] = value
        self._persisted_data.notify_changed(nodepath)

    def singleton_unload_hook(self):
        pass


PERSISTANCE_MANAGER = ReloadableSingletonFactory(PersistanceManager)
Пример #5
0
                if not from_path.endswith('/'):
                    # adding slash to avoid bad replaces.  They are urls
                    # so a trailing / is safer.
                    from_path += '/'
                to_path = mp.as_node_url()
                if not to_path.endswith('/'):
                    to_path += '/'
        except:
            pass
        return [from_path, to_path]

    def singleton_unload_hook(self):
        pass


ENTITY_MANAGER = ReloadableSingletonFactory(Manager)


def manager_factory():
    return ENTITY_MANAGER


class ProxyMixin(object):
    implements(IAliasNode)

    def __init__(self):
        self.__subject_url = None
        self.__subject = None
        self.__mount_point = None

    def set_mount_point(self, mount_point):
Пример #6
0
    def poll_changed(self, entity_path, group_name, poll_id):
        return self.get_group_instance(entity_path,
                                       group_name).poll_changed(poll_id)

    def singleton_unload_hook(self):
        pass

    def _get_qm(self):
        if self._qm is None:
            self._qm = as_node('/services/Query Manager')
        return self._qm

    qm = property(_get_qm)


GSP_MANAGER = ReloadableSingletonFactory(GlobalSetpointManager)


def manager_factory():
    return GSP_MANAGER


##
# The GlobalSetpointGroupContainer is a container\holder for instances of
# the GlobalSetpointGroup class.
class GlobalSetpointGroupContainer(CompositeNode):
    @do_persist
    def configure(self, config):
        super(GlobalSetpointGroupContainer, self).configure(config)

Пример #7
0
    def enqueue(self, command_set):
        self._transactions[command_set.tid] = command_set
        self._worker_thread.queue_noresult(command_set)

    def get_push_values_progress(self, transaction_id):
        try:
            return self._transactions[transaction_id].get_status()
        except KeyError:
            raise ENotFound()

    def singleton_unload_hook(self):
        pass


COMMAND_MANAGER = ReloadableSingletonFactory(CommandManager)


class CommandSet(object):
    def __init__(self, commands, operation='execute'):
        self.tid = UUID()
        self._commands = []
        for cmd in commands:
            if isinstance(cmd, CommandIface):
                self._commands.append(cmd)
        self._completed = 0
        self._num_commands = len(self._commands)
        self._errors = 0
        self._operation = operation
        value_map = {
            'completed': False,