How to use fysom - 10 common examples

To help you get started, we’ve selected a few fysom examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ChristianTremblay / pyhaystack / pyhaystack / client / ops / vendor / niagara_scram.py View on Github external
self._username = None
        self._user_salt = None
        self._digest = None

        self._algorithm = None
        self._handshake_token = None
        self._server_first_msg  = None
        self._server_nonce = None
        self._server_salt = None
        self._server_iterations = None
        self._auth_token = None
        self._auth = None

        self._login_uri = '%s'   % \
                (session._client.uri)
        self._state_machine = fysom.Fysom(
                initial='init', final='done',
                events=[
                    # Event               Current State         New State
                    ('get_new_session',   'init',               'newsession'),
                    ('do_prelogin',       'newsession',         'prelogin'),
                    ('do_first_msg',      'prelogin',           'first_msg'),
                    ('do_second_msg',     'first_msg',          'second_msg'),
                    ('do_validate_login', 'second_msg',         'validate_login'),
                    ('login_done',        'validate_login',     'done'),
                    ('exception',         '*',                  'failed'),
                    ('retry',             'failed',             'newsession'),
                    ('abort',             'failed',             'done'),
                ], callbacks={
                    'onenternewsession':        self._do_new_session,
                    'onenterprelogin':          self._do_prelogin,
                    'onenterfirst_msg':         self._do_first_msg,
github Ulm-IQO / qudi / logic / generic_task.py View on Github external
{'name': 'pausingFinished',     'src': 'pausing',   'dst': 'paused'},
                {'name': 'finish',              'src': 'running',   'dst': 'finishing'},
                {'name': 'finishingFinished',   'src': 'finishing', 'dst': 'stopped'},
                {'name': 'resume',              'src': 'paused',    'dst': 'resuming'},
                {'name': 'resumingFinished',    'src': 'resuming',  'dst': 'running'},
                {'name': 'abort',               'src': 'pausing',   'dst': 'stopped'},
                {'name': 'abort',               'src': 'starting',  'dst': 'stopped'},
                {'name': 'abort',               'src': 'resuming',  'dst': 'stopped'}
            ],
            'callbacks': default_callbacks
        }
        if 'PyQt5' in sys.modules:
            super().__init__(cfg=_stateDict, **kwargs)
        else:
            QtCore.QObject.__init__(self)
            Fysom.__init__(self, _stateDict)

        self.lock = Mutex()
        self.name = name
        self.interruptable = False
        self.success = False
        self.runner = runner
        self.ref = references
        self.config = config

        self.sigDoStart.connect(self._doStart, QtCore.Qt.QueuedConnection)
        self.sigDoPause.connect(self._doPause, QtCore.Qt.QueuedConnection)
        self.sigDoResume.connect(self._doResume, QtCore.Qt.QueuedConnection)
        self.sigDoFinish.connect(self._doFinish, QtCore.Qt.QueuedConnection)
        self.sigNextTaskStep.connect(self._doTaskStep, QtCore.Qt.QueuedConnection)
github ourway / marmoolak / marmoolak / __init__.py View on Github external
__author__ = 'Farsheed Ashouri'


import hashlib
import redis
import os

REDIS_HOST = None
REDIS_PORT = None

from fysom import Fysom as _Fysom


class Machine(_Fysom):

    def __init__(self, name, version, *args, **kw):
        """ Usage: Machine("name", 1.0, *args, **kw)"""
        ''' Redis setup'''
        redis_host = REDIS_HOST or os.getenv('REDIS_HOST') or 'localhost'
        _redis_port = REDIS_PORT or os.getenv('REDIS_PORT') or '6379'
        redis_port = int(_redis_port)
        self.r = redis.StrictRedis(host=redis_host, port=redis_port)


        self.rhname = 'appido_core_fsm_{n}_{v}'.format(n=name, v=version)
        history = self.r.get(self.rhname).decode('utf-8')
        if history:
            args[0]['initial'] = history
        self.name = name
        self.version = version
github Ulm-IQO / qudi / logic / generic_task.py View on Github external
          @param dict config: configuration parameter dictionary
        """
        _default_callbacks = {'onprerun': self._pre, 'onpostrun': self._post}
        _stateList = {
            'initial': 'stopped',
            'events': [
                {'name': 'prerun', 'src': 'stopped', 'dst': 'paused'},
                {'name': 'postrun', 'src': 'paused', 'dst': 'stopped'}
            ],
            'callbacks': _default_callbacks
        }
        if 'PyQt5' in sys.modules:
            super().__init__(cfg=_stateList, **kwargs)
        else:
            QtCore.QObject.__init__(self)
            Fysom.__init__(self, _stateList)
        self.lock = Mutex()
        self.name = name
        self.runner = runner
        self.ref = references
        self.config = config
github muminoff / devon / devon / devon.py View on Github external
def do_stem(self, word):
        fsm = Fysom(initial='start', events=self.events)
        # FIXME: uncomment below and make sanitize functions support
        # both Python 2 and 3 versions
        # word = WordProcessor.sanitize(word)
        i = len(word) - 1
        j = len(word)

        while(True):
            if i <= 0:
                break
            v = word[i:j]
            # print v
            res = fsm.can(v)
            if (res):
                if v == 'i' and fsm.can(word[i-1:j]):
                    i = i - 1
                    continue
github box / ClusterRunner / app / master / build_fsm.py View on Github external
def _create_state_machine(self):
        """
        Create the Fysom object and set up transitions and states. Note that the first transition
        (none ==> initial) is triggered immediately on instantiation.
        :rtype: Fysom
        """
        return Fysom({
            'initial': BuildState.QUEUED,
            'events': [
                {'name': BuildEvent.START_PREPARE,
                 'src': BuildState.QUEUED,
                 'dst': BuildState.PREPARING},

                {'name': BuildEvent.FINISH_PREPARE,
                 'src': BuildState.PREPARING,
                 'dst': BuildState.PREPARED},

                {'name': BuildEvent.START_BUILDING,
                 'src': BuildState.PREPARED,
                 'dst': BuildState.BUILDING},

                {'name': BuildEvent.POSTBUILD_TASKS_COMPLETE,
                 'src': [
github ChristianTremblay / pyhaystack / pyhaystack / client / entity / ops / crud.py View on Github external
def __init__(self, entity, updates):
        """
        Initialise a request for the named IDs.

        :param session: Haystack HTTP session object.
        """
        super(EntityTagUpdateOperation, self).__init__(result_copy=False)
        self._log = entity._session._log.getChild('update_tags')
        self._entity = entity
        self._updates = updates

        self._state_machine = fysom.Fysom(
                initial='init', final='done',
                events=[
                    # Event             Current State       New State
                    ('do_update',       'init',             'update'),
                    ('update_done',     'update',           'done'),
                    ('exception',       '*',                'done'),
                ], callbacks={
                    'onenterdone':      self._do_done,
                })
github Ulm-IQO / qudi / core / module.py View on Github external
status_vars[key] = value.copy(var_name=key)

        attrs.update(connectors)
        attrs.update(config_options)
        attrs.update(status_vars)

        # create a new class with the new dictionaries
        new_class = super().__new__(mcs, name, bases, attrs)
        new_class._conn = connectors
        new_class._config_options = config_options
        new_class._stat_vars = status_vars

        return new_class


class BaseMixin(Fysom, metaclass=ModuleMeta):
    """
    Base class for all loadable modules

    * Ensure that the program will not die during the load of modules in any case,
      and therefore do nothing!!!
    * Initialize modules
    * Provides a self identification of the used module
    * Output redirection (instead of print)
    * Provides a self de-initialization of the used module
    * Reload the module with code changes
    * Get your own configuration (for save)
    * Get name of status variables
    * Get status variables
    * Reload module data (from saved variables)
    """
github Ulm-IQO / qudi / qudi / core / task.py View on Github external
pass

    @abc.abstractmethod
    def resumeTask(self):
        """ Implement the operations necessary to resume your task from being paused here.
        """
        pass

    @abc.abstractmethod
    def cleanupTask(self):
        """ If your task leaves behind any undesired state, take care to remove it in this function.
            It is called after a task has finished.
        """
        pass

class PrePostTask(QtCore.QObject, Fysom, metaclass=TaskMetaclass):
    """ Represents a task that creates the necessary conditions for a different task
        and reverses its own actions afterwards.
    """

    sigPreExecStart = QtCore.Signal()
    sigPreExecFinish = QtCore.Signal()
    sigPostExecStart = QtCore.Signal()
    sigPostExecFinish = QtCore.Signal()
    sigStateChanged = QtCore.Signal(object)

    requiredModules = []

    def __init__(self, name, runner, references, config, **kwargs):
        """ Create a PrePostTask.
          @param str name: unique name of the task
          @param object runner: TaskRunner that manages this task
github ChristianTremblay / pyhaystack / pyhaystack / client / ops / vendor / widesky.py View on Github external
session._client_secret]).encode('utf-8')
                        ).decode('us-ascii')
                    ).encode('us-ascii'),
                'Accept': 'application/json',
                'Content-Type': 'application/json',
        }
        self._auth_body = json.dumps({
            'username': session._username,
            'password': session._password,
            'grant_type': 'password',
        }).encode('utf-8')
        self._session = session
        self._retries = retries
        self._auth_result = None

        self._state_machine = fysom.Fysom(
                initial='init', final='done',
                events=[
                    # Event             Current State       New State
                    ('do_login',        ['init', 'failed'], 'login'),
                    ('login_done',      'login',            'done'),
                    ('exception',       '*',                'failed'),
                    ('retry',           'failed',           'login'),
                    ('abort',           'failed',           'done'),
                ], callbacks={
                    'onenterlogin':         self._do_login,
                    'onenterfailed':        self._do_fail_retry,
                    'onenterdone':          self._do_done,
                })

fysom

pYthOn Finite State Machine

MIT
Latest version published 3 years ago

Package Health Score

55 / 100
Full package analysis

Similar packages