Ginés Martínez Sánchez avatar Ginés Martínez Sánchez committed c34440b Draft

writing inter_event example

Comments (0)

Files changed (34)

ginsfsm/examples/inter_event/banco/banco/main.py

 
     ga = GAplic(
         name=gaplic_name,
-        roles=('banco', 'financiera', 'bolsa', 'publicidad'),
+        roles=('banco', '*financiera', '*bolsa', '*publicidad'),
         **local_conf)
     set_global_main_gaplic(ga)
     ga.create_gobj(

ginsfsm/examples/inter_event/bolsa/CHANGES.txt

+0.0.0
+-----
+
+-  Initial version

ginsfsm/examples/inter_event/bolsa/MANIFEST.in

+prune .hg
+exclude push.sh
+include *.txt *.ini *.cfg *.rst
+recursive-include bolsa *.ico *.png *.css *.gif *.jpg *.pt *.txt *.mak *.mako *.js *.html *.xml

ginsfsm/examples/inter_event/bolsa/README.rst

+bolsa
+=====
+
+License
+-------
+
+Copyright (c) 2013
+
+bolsa is released under terms of The MIT
+License MIT <http://www.opensource.org/licenses/mit-license>.
+
+Authors
+-------
+
+Your name
Add a comment to this file

ginsfsm/examples/inter_event/bolsa/__init__.py

Empty file removed.

ginsfsm/examples/inter_event/bolsa/bolsa.ini

+[composite:main]
+use = call:ginsfsm.gaplic:gaplic_factory
+main = websocket-server
+
+[app:websocket-server]
+use = egg:bolsa#main
+gaplic-name = Madrid
+router_enabled = true
+GRouter.server = true
+GRouter.localhost_route_ports = 8003
+GRouter.trace_router = true
+GObj.trace_mach = true
+GObj.trace_creation = false
+GObj.trace_traverse = true
+GObj.trace_subscription = false
+GSock.trace_dump = true
+
+
+# Begin logging configuration
+
+[loggers]
+keys = root, ginsfsm
+
+[handlers]
+keys = console
+
+[formatters]
+keys = generic
+
+[logger_root]
+level = DEBUG
+handlers = console
+
+[logger_ginsfsm]
+level = DEBUG
+handlers =
+qualname = ginsfsm
+
+[handler_console]
+class = StreamHandler
+args = (sys.stderr,)
+level = NOTSET
+formatter = generic
+
+[formatter_generic]
+format = %(message)s
+
+# End logging configuration

ginsfsm/examples/inter_event/bolsa/bolsa/__init__.py

+# -*- encoding: utf-8 -*-
+
+__version__ = '0.0.0'

ginsfsm/examples/inter_event/bolsa/bolsa/c_acciones.py

+# -*- encoding: utf-8 -*-
+""" GAcciones GObj
+
+.. autoclass:: GAcciones
+    :members: start_up
+
+"""
+
+from ginsfsm.gobj import GObj
+
+
+def ac_sample(self, event):
+    """ Event attributes:
+        * :attr:`data`: example.
+
+    """
+    if self.output_event_name is not None:
+        self.broadcast_event(self.output_event_name, data=event.data)
+
+
+GACCIONES_FSM = {
+    'event_list': (
+        'EV_INPUT_EVENT:top input',
+        'EV_OUTPUT_EVENT:top output',
+    ),
+    'state_list': (
+        'ST_IDLE',
+    ),
+    'machine': {
+        'ST_IDLE':
+        (
+            ('EV_INPUT_EVENT',      ac_sample,      None),
+        ),
+    }
+}
+
+GACCIONES_GCONFIG = {
+    'subscriber': [
+        None, None, 0, None,
+        "subcriber of all output-events."
+        "Default is ``None``, i.e., the parent"
+    ],
+
+    # If some name is None then the parent don't want receive it.
+    'output_event_name': [
+        str, 'EV_OUTPUT_EVENT', 0, None,
+        "Name of the *sample output* event."
+        " ``None`` if you want ignore the event"
+    ],
+}
+
+
+class GAcciones(GObj):
+    """  GAcciones GObj.
+    A Sample gobj.
+
+    .. ginsfsm::
+       :fsm: GACCIONES_FSM
+       :gconfig: GACCIONES_GCONFIG
+
+    *Input-Events:*
+        * :attr:`'EV_INPUT_EVENT'`: sample input event.
+
+          Event attributes:
+
+              * ``data``: sample event attribute.
+
+    *Output-Events:*
+        * :attr:`'EV_OUTPUT_EVENT'`: sample output event.
+
+          Event attributes:
+
+              * ``data``: sample event attribute.
+
+    """
+    def __init__(self):
+        GObj.__init__(self, GACCIONES_FSM, GACCIONES_GCONFIG)
+
+    def start_up(self):
+        """ Initialization zone.
+        """
+        if self.config.subscriber is None:
+            self.config.subscriber = self.parent
+        self.subscribe_event(None, self.config.subscriber)

ginsfsm/examples/inter_event/bolsa/bolsa/main.py

+# -*- encoding: utf-8 -*-
+"""
+bolsa
+=====
+
+It uses :class:`ginsfsm.protocols.wsgi.server.c_wsgi_server.GWsgiServer`.
+
+.. autofunction:: main
+
+"""
+
+from ginsfsm.gaplic import GAplic
+from ginsfsm.globals import (
+    set_global_main_gaplic,
+)
+from bolsa.c_acciones import GAcciones
+
+
+#===============================================================
+#                   Main
+#       Paste app factory.
+#       To run with gserve bolsa.ini
+#===============================================================
+def main(global_config, **local_conf):
+    """ Entry point to run with gserve (PasteDeploy)
+    """
+    if 'gaplic-name' in local_conf:
+        gaplic_name = local_conf.pop('gaplic-name')
+    else:
+        raise Exception('You must supply an gaplic name ("gaplic-name")')
+
+    ga = GAplic(name=gaplic_name, roles='bolsa', **local_conf)
+    set_global_main_gaplic(ga)
+
+    ga.create_gobj(
+        'acciones',
+        GAcciones,
+        ga,
+        __unique_name__=True,
+    )
+    return ga
+
+
+if __name__ == "__main__":
+    """ You can run directly this file, without gserve.
+    """
+    import logging
+    logging.basicConfig(level=logging.DEBUG)
+
+    # simulate running from ini file
+    local_conf = {
+        'gaplic-name': 'bolsa',
+        'router_enabled':  True,
+        'GRouter.server':  True,
+        'GRouter.localhost_route_ports':  8002,
+        'GRouter.trace_router':  True,
+        'GObj.trace_mach':  True,
+        'GObj.trace_creation':  False,
+        'GObj.trace_traverse':  True,
+        'GObj.trace_subscription':  False,
+        'GSock.trace_dump':  True,
+    }
+    ga = main({}, **local_conf)
+
+    try:
+        ga.start()
+    except (KeyboardInterrupt, SystemExit):
+        print('Program stopped')

ginsfsm/examples/inter_event/bolsa/bolsa/tests/__init__.py

+#

ginsfsm/examples/inter_event/bolsa/bolsa/tests/test_bolsa.py

+import unittest
+
Add a comment to this file

ginsfsm/examples/inter_event/bolsa/docs/DejaVuSans.ttf

Binary file added.

ginsfsm/examples/inter_event/bolsa/docs/README.txt

+Create a sphinx project
+=======================
+
+To build the documentation you must create a sphinx project in this directory
+with the 'sphinx-quickstart' command, with 'autodoc' extension enabled.
+I like the 'viewcode' extension too.
+
+
+Include the sphinx extensions
+=============================
+
+In order to build the ginsfsm documentation with svg graphics of smachine
+you must too add the extension 'ginsfsm.sphinxext' to the created conf.py file.
+
+The final result can be:
+
+extensions = ['sphinx.ext.autodoc', 'sphinx.ext.viewcode', 'ginsfsm.sphinxext']
+
+
+Include the generated rst file
+==============================
+
+You must include the generated api_xxx.rst in the Contents of index.rst:
+
+.. toctree::
+   :maxdepth: 2
+
+   api_xxx
+
+being xxx the name of the created project.
+
+
+Don't compile sphinx?
+=====================
+
+If make html fails with the message:
+
+   "Could not import extension ginsfsm.sphinxext"
+
+check if the next modules are installed:
+
+   * docutils
+   * svgwrite
+   * PIL
+     Better install `pillow`, with pip.
+     `pillow` will need libfreetype*dev and libjpeg*dev libs to compile.

ginsfsm/examples/inter_event/bolsa/docs/api_bolsa.rst

+bolsa
+=====
+
+This is the main index page of your documentation. It should be written in
+`reStructuredText format <http://docutils.sourceforge.net/rst.html>`_.
+
+
+:mod:`bolsa`
+------------
+
+.. automodule:: bolsa

ginsfsm/examples/inter_event/bolsa/setup.cfg

+[nosetests]
+match = ^test
+nocapture = 1
+cover-package = bolsa
+with-coverage = 1
+cover-erase = 1
+
+[egg_info]
+tag_build =
+tag_svn_revision = false
+tag_date = 0
+
+[easy_install]
+zip_ok = false

ginsfsm/examples/inter_event/bolsa/setup.py

+# -*- encoding: utf-8 -*-
+
+import os
+import sys
+import bolsa
+
+from setuptools import setup, find_packages
+
+if sys.version_info[:2] < (2, 6):
+    raise RuntimeError('Requires Python 2.6 or better')
+
+here = os.path.abspath(os.path.dirname(__file__))
+try:
+    README = open(os.path.join(here, 'README.rst')).read()
+    CHANGES = open(os.path.join(here, 'CHANGES.txt')).read()
+except IOError:
+    README = CHANGES = ''
+
+requires = ['ginsfsm']
+
+setup(name='bolsa',
+    version=bolsa.__version__,
+    description='bolsa',
+    long_description=README + '\n\n' + CHANGES,
+    classifiers=[
+        "Programming Language :: Python",
+    ],
+    author='',
+    author_email='',
+    url='',
+    license='MIT License',
+    keywords='gobj ginsfsm finite state machine fsm wsgi',
+    packages=find_packages(),
+    include_package_data=True,
+    zip_safe=False,
+    install_requires=requires,
+    tests_require=requires,
+    test_suite="bolsa.tests",
+    entry_points="""\
+    [paste.app_factory]
+    main = bolsa.main:main
+    """,
+)

ginsfsm/examples/inter_event/financiera/financiera.ini

 
 [app:websocket-server]
 use = egg:financiera#main
-gaplic-name = financiera
+gaplic-name = RobberA
 router_enabled = true
 GRouter.server = true
 GRouter.localhost_route_ports = 8002
 GObj.trace_subscription = false
 GSock.trace_dump = true
 
+GRouter.static_routes =
+    Madrid, bolsa, http://localhost:8003;
+    Enganabobos, publicidad, http://localhost:8004;
+
 
 # Begin logging configuration
 

ginsfsm/examples/inter_event/financiera/financiera/main.py

 
     ga = GAplic(
         name=gaplic_name,
-        roles='financiera, bolsa, publicidad',
+        roles='financiera, *bolsa, *publicidad',
         **local_conf)
     set_global_main_gaplic(ga)
 
     ga.create_gobj(
-        'financiera',
+        'prestamos',
         GPrestamos,
         ga,
         __unique_name__=True,

ginsfsm/examples/inter_event/publicidad/CHANGES.txt

+0.0.0
+-----
+
+-  Initial version

ginsfsm/examples/inter_event/publicidad/MANIFEST.in

+prune .hg
+exclude push.sh
+include *.txt *.ini *.cfg *.rst
+recursive-include publicidad *.ico *.png *.css *.gif *.jpg *.pt *.txt *.mak *.mako *.js *.html *.xml

ginsfsm/examples/inter_event/publicidad/README.rst

+publicidad
+==========
+
+License
+-------
+
+Copyright (c) 2013
+
+publicidad is released under terms of The MIT
+License MIT <http://www.opensource.org/licenses/mit-license>.
+
+Authors
+-------
+
+Your name
Add a comment to this file

ginsfsm/examples/inter_event/publicidad/__init__.py

Empty file removed.

Add a comment to this file

ginsfsm/examples/inter_event/publicidad/docs/DejaVuSans.ttf

Binary file added.

ginsfsm/examples/inter_event/publicidad/docs/README.txt

+Create a sphinx project
+=======================
+
+To build the documentation you must create a sphinx project in this directory
+with the 'sphinx-quickstart' command, with 'autodoc' extension enabled.
+I like the 'viewcode' extension too.
+
+
+Include the sphinx extensions
+=============================
+
+In order to build the ginsfsm documentation with svg graphics of smachine
+you must too add the extension 'ginsfsm.sphinxext' to the created conf.py file.
+
+The final result can be:
+
+extensions = ['sphinx.ext.autodoc', 'sphinx.ext.viewcode', 'ginsfsm.sphinxext']
+
+
+Include the generated rst file
+==============================
+
+You must include the generated api_xxx.rst in the Contents of index.rst:
+
+.. toctree::
+   :maxdepth: 2
+
+   api_xxx
+
+being xxx the name of the created project.
+
+
+Don't compile sphinx?
+=====================
+
+If make html fails with the message:
+
+   "Could not import extension ginsfsm.sphinxext"
+
+check if the next modules are installed:
+
+   * docutils
+   * svgwrite
+   * PIL
+     Better install `pillow`, with pip.
+     `pillow` will need libfreetype*dev and libjpeg*dev libs to compile.

ginsfsm/examples/inter_event/publicidad/docs/api_publicidad.rst

+publicidad
+==========
+
+This is the main index page of your documentation. It should be written in
+`reStructuredText format <http://docutils.sourceforge.net/rst.html>`_.
+
+
+:mod:`publicidad`
+-----------------
+
+.. automodule:: publicidad

ginsfsm/examples/inter_event/publicidad/publicidad.ini

+[composite:main]
+use = call:ginsfsm.gaplic:gaplic_factory
+main = websocket-server
+
+[app:websocket-server]
+use = egg:publicidad#main
+gaplic-name = Enganabobos
+router_enabled = true
+GRouter.server = true
+GRouter.localhost_route_ports = 8004
+GRouter.trace_router = true
+GObj.trace_mach = true
+GObj.trace_creation = false
+GObj.trace_traverse = true
+GObj.trace_subscription = false
+GSock.trace_dump = true
+
+
+# Begin logging configuration
+
+[loggers]
+keys = root, ginsfsm
+
+[handlers]
+keys = console
+
+[formatters]
+keys = generic
+
+[logger_root]
+level = DEBUG
+handlers = console
+
+[logger_ginsfsm]
+level = DEBUG
+handlers =
+qualname = ginsfsm
+
+[handler_console]
+class = StreamHandler
+args = (sys.stderr,)
+level = NOTSET
+formatter = generic
+
+[formatter_generic]
+format = %(message)s
+
+# End logging configuration

ginsfsm/examples/inter_event/publicidad/publicidad/__init__.py

+# -*- encoding: utf-8 -*-
+
+__version__ = '0.0.0'

ginsfsm/examples/inter_event/publicidad/publicidad/c_sorteo.py

+# -*- encoding: utf-8 -*-
+""" GSorteo GObj
+
+.. autoclass:: GSorteo
+    :members: start_up
+
+"""
+
+from ginsfsm.gobj import GObj
+
+
+def ac_sample(self, event):
+    """ Event attributes:
+        * :attr:`data`: example.
+
+    """
+    if self.output_event_name is not None:
+        self.broadcast_event(self.output_event_name, data=event.data)
+
+
+GSORTEO_FSM = {
+    'event_list': (
+        'EV_INPUT_EVENT:top input',
+        'EV_OUTPUT_EVENT:top output',
+    ),
+    'state_list': (
+        'ST_IDLE',
+    ),
+    'machine': {
+        'ST_IDLE':
+        (
+            ('EV_INPUT_EVENT',      ac_sample,      None),
+        ),
+    }
+}
+
+GSORTEO_GCONFIG = {
+    'subscriber': [
+        None, None, 0, None,
+        "subcriber of all output-events."
+        "Default is ``None``, i.e., the parent"
+    ],
+
+    # If some name is None then the parent don't want receive it.
+    'output_event_name': [
+        str, 'EV_OUTPUT_EVENT', 0, None,
+        "Name of the *sample output* event."
+        " ``None`` if you want ignore the event"
+    ],
+}
+
+
+class GSorteo(GObj):
+    """  GSorteo GObj.
+    A Sample gobj.
+
+    .. ginsfsm::
+       :fsm: GSORTEO_FSM
+       :gconfig: GSORTEO_GCONFIG
+
+    *Input-Events:*
+        * :attr:`'EV_INPUT_EVENT'`: sample input event.
+
+          Event attributes:
+
+              * ``data``: sample event attribute.
+
+    *Output-Events:*
+        * :attr:`'EV_OUTPUT_EVENT'`: sample output event.
+
+          Event attributes:
+
+              * ``data``: sample event attribute.
+
+    """
+    def __init__(self):
+        GObj.__init__(self, GSORTEO_FSM, GSORTEO_GCONFIG)
+
+    def start_up(self):
+        """ Initialization zone.
+        """
+        if self.config.subscriber is None:
+            self.config.subscriber = self.parent
+        self.subscribe_event(None, self.config.subscriber)

ginsfsm/examples/inter_event/publicidad/publicidad/main.py

+# -*- encoding: utf-8 -*-
+"""
+publicidad
+==========
+
+It uses :class:`ginsfsm.protocols.wsgi.server.c_wsgi_server.GWsgiServer`.
+
+.. autofunction:: main
+
+"""
+
+from ginsfsm.gaplic import GAplic
+from ginsfsm.globals import (
+    set_global_main_gaplic,
+)
+from publicidad.c_sorteo import GSorteo
+
+
+#===============================================================
+#                   Main
+#       Paste app factory.
+#       To run with gserve publicidad.ini
+#===============================================================
+def main(global_config, **local_conf):
+    """ Entry point to run with gserve (PasteDeploy)
+    """
+    if 'gaplic-name' in local_conf:
+        gaplic_name = local_conf.pop('gaplic-name')
+    else:
+        raise Exception('You must supply an gaplic name ("gaplic-name")')
+
+    ga = GAplic(name=gaplic_name, roles='publicidad', **local_conf)
+    set_global_main_gaplic(ga)
+
+    ga.create_gobj(
+        'sorteo',
+        GSorteo,
+        ga,
+        __unique_name__=True,
+    )
+    return ga
+
+
+if __name__ == "__main__":
+    """ You can run directly this file, without gserve.
+    """
+    import logging
+    logging.basicConfig(level=logging.DEBUG)
+
+    # simulate running from ini file
+    local_conf = {
+        'gaplic-name': 'publicidad',
+        'router_enabled':  True,
+        'GRouter.server':  True,
+        'GRouter.localhost_route_ports':  8002,
+        'GRouter.trace_router':  True,
+        'GObj.trace_mach':  True,
+        'GObj.trace_creation':  False,
+        'GObj.trace_traverse':  True,
+        'GObj.trace_subscription':  False,
+        'GSock.trace_dump':  True,
+    }
+    ga = main({}, **local_conf)
+
+    try:
+        ga.start()
+    except (KeyboardInterrupt, SystemExit):
+        print('Program stopped')

ginsfsm/examples/inter_event/publicidad/publicidad/tests/__init__.py

+#

ginsfsm/examples/inter_event/publicidad/publicidad/tests/test_publicidad.py

+import unittest
+

ginsfsm/examples/inter_event/publicidad/setup.cfg

+[nosetests]
+match = ^test
+nocapture = 1
+cover-package = publicidad
+with-coverage = 1
+cover-erase = 1
+
+[egg_info]
+tag_build =
+tag_svn_revision = false
+tag_date = 0
+
+[easy_install]
+zip_ok = false

ginsfsm/examples/inter_event/publicidad/setup.py

+# -*- encoding: utf-8 -*-
+
+import os
+import sys
+import publicidad
+
+from setuptools import setup, find_packages
+
+if sys.version_info[:2] < (2, 6):
+    raise RuntimeError('Requires Python 2.6 or better')
+
+here = os.path.abspath(os.path.dirname(__file__))
+try:
+    README = open(os.path.join(here, 'README.rst')).read()
+    CHANGES = open(os.path.join(here, 'CHANGES.txt')).read()
+except IOError:
+    README = CHANGES = ''
+
+requires = ['ginsfsm']
+
+setup(name='publicidad',
+    version=publicidad.__version__,
+    description='publicidad',
+    long_description=README + '\n\n' + CHANGES,
+    classifiers=[
+        "Programming Language :: Python",
+    ],
+    author='',
+    author_email='',
+    url='',
+    license='MIT License',
+    keywords='gobj ginsfsm finite state machine fsm wsgi',
+    packages=find_packages(),
+    include_package_data=True,
+    zip_safe=False,
+    install_requires=requires,
+    tests_require=requires,
+    test_suite="publicidad.tests",
+    entry_points="""\
+    [paste.app_factory]
+    main = publicidad.main:main
+    """,
+)
Add a comment to this file

ginsfsm/examples/inter_event/schema.svg

Old
Old image
New
New image
          sodipodi:role="line"
          id="tspan3096"
          x="308.32877"
-         y="219.54665">EV_ACCION</tspan></text>
+         y="219.54665">EV_ACCIONES</tspan></text>
     <text
        xml:space="preserve"
        style="font-size:14px;font-style:normal;font-weight:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#0000ff;fill-opacity:1;stroke:none;font-family:Sans"
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.