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

added new scaffold: multi pyramid wsgi app

Comments (0)

Files changed (17)

ginsfsm/scaffolds/__init__.py

 
 class SimpleWsgiTemplate(GinsFSMTemplate):
     _template_dir = 'simple_wsgi'
-    summary = 'Create a simple WSGI proyect with pyramid.'
+    summary = 'Create a simple WSGI proyect.'
 
 
 class MultipleWsgiTemplate(GinsFSMTemplate):
     _template_dir = 'multiple_wsgi'
-    summary = 'Create a multiple WSGI proyect with pyramid.'
+    summary = 'Create a multiple WSGI proyect.'
 
+
+class MultiplePyramidWsgiTemplate(GinsFSMTemplate):
+    _template_dir = 'multi_pyramid_wsgi'
+    summary = 'Create a multiple WSGI proyect' \
+            ' with a Pyramid wsgi application.'

ginsfsm/scaffolds/multi_pyramid_wsgi/+package+.ini_tmpl

+[composite:main]
+use = call:ginsfsm.gaplic:gaplic_factory
+main = wsgi-server
+wsgi = wsgi-application
+
+[composite:wsgi-application]
+use = call:ginsfsm.protocols.wsgi.common.urlmap:urlmap_factory
+/ = admin
+/applic10 = applic10
+/applic20 = applic20
+
+[app:wsgi-server]
+#use = call:{{package}}.main:main
+use = egg:{{package}}#main
+gaplic_name = main_gaplic
+wsgi_server_name = wsgi-server
+
+wsgi-server.host = 0.0.0.0
+wsgi-server.port = 8000
+application = wsgi-application
+GSock.trace_dump = false
+GObj.trace_mach = false
+#GServerSock.use_named_clisrv = true
+
+[app:admin]
+#use = call:{{package}}.main:admin_paste_factory
+use = egg:{{package}}#admin
+gaplic = main_gaplic
+
+[app:applic10]
+#use = call:{{package}}.main:applic10_paste_factory
+use = egg:{{package}}#applic10
+gaplic = main_gaplic
+
+pyramid.reload_templates = true
+pyramid.debug_authorization = true
+pyramid.debug_notfound = false
+pyramid.debug_routematch = false
+pyramid.debug_templates = true
+pyramid.default_locale_name = en
+
+[app:applic20]
+#use = call:{{package}}.main:applic20_paste_factory
+use = egg:{{package}}#applic20
+gaplic = main_gaplic
+
+# 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/scaffolds/multi_pyramid_wsgi/+package+/__init__.py_tmpl

+# -*- encoding: utf-8 -*-
+
+__version__ = '0.0.0'
+
+
+# Set default logging handler to avoid "No handler found" warnings.
+import logging
+try:  # Python 2.7+
+    from logging import NullHandler
+except ImportError:
+    class NullHandler(logging.Handler):
+        def emit(self, record):
+            pass
+
+logging.getLogger(__name__).addHandler(NullHandler())

ginsfsm/scaffolds/multi_pyramid_wsgi/+package+/applic10/__init__.py_tmpl

+# -*- encoding: utf-8 -*-
+"""
+applic10
+========
+
+Applic 10
+
+"""
+from pyramid.config import Configurator
+
+from ginsfsm.globals import get_global_app
+
+from {{package}}.applic10.applic10_root import GApplic10
+
+
+#-------------------------------------------------#
+#       Paste entry point
+#       Pyramid wsgi-app configuration
+#-------------------------------------------------#
+def applic10_wsgi_app(global_config, **local_conf):
+    """ Returns a WSGI application.
+    """
+    if 'gaplic' in local_conf:
+        gaplic_name = local_conf.pop('gaplic')
+    else:
+        raise Exception('You must supply a gaplic name in ini file.')
+
+    gaplic = get_global_app(gaplic_name)
+    if not gaplic:
+        raise Exception("gaplic '%s' supplied for wsgi is invalid" %
+                        gaplic_name)
+
+    config = Configurator(
+        root_factory=get_root,
+        settings=local_conf,
+    )
+
+    # Set up views
+    config.scan("{{package}}.applic10")
+
+    # Now we have the gaplic and the config for make the root
+    make_root(gaplic, config)
+
+    return config.make_wsgi_app()
+
+
+#----------------------------------------------------------------------#
+#                           Pyramid root
+#----------------------------------------------------------------------#
+applic10_root = None
+
+
+def make_root(gaplic, config):
+    global applic10_root
+    if applic10_root is not None:
+        return applic10_root
+
+    applic10_root = gaplic.create_gobj(
+        'applic10',
+        GApplic10,
+        None,
+        config=config
+    )
+    return applic10_root
+
+
+def get_root(request):
+    return applic10_root

ginsfsm/scaffolds/multi_pyramid_wsgi/+package+/applic10/applic10_root.py_tmpl

+# -*- encoding: utf-8 -*-
+"""
+applic10
+=======
+
+Applic 10
+
+"""
+from pyramid.response import Response
+from pyramid.view import view_config
+from pyramid.security import (
+    Allow,
+    Authenticated,
+    Everyone,
+    DENY_ALL,
+)
+
+from ginsfsm.gobj import GObj
+from ginsfsm.c_timer import GTimer
+
+
+#----------------------------------------------------------------------#
+#                           Applic1
+#----------------------------------------------------------------------#
+
+#-------------------------------------------#
+#               Actions
+#-------------------------------------------#
+def ac_timeout(self, event):
+    self.counter += 1
+    self.send_event(self.timer, 'EV_SET_TIMER', seconds=self.seconds)
+
+
+GAPPLIC10_FSM = {
+    'event_list': (
+        'EV_SET_TIMER: bottom output',
+        'EV_TIMEOUT: bottom input',
+    ),
+    'state_list': (
+        'ST_IDLE',
+    ),
+    'machine': {
+        'ST_IDLE':
+        (
+            ('EV_TIMEOUT', ac_timeout, 'ST_IDLE'),
+        ),
+    }
+}
+
+GAPPLIC10_GCONFIG = {
+    'config': [None, None, 0, None, "Pyramid config, to create views,etc."],
+    'seconds': [int, 1, 0, None, "Timer to increment the counter."],
+    'counter': [int, 0, 0, None, "Counter to display."],
+}
+
+
+class GApplic10(GObj):
+    """  Root resource for Applic10.
+
+    .. ginsfsm::
+       :fsm: GAPPLIC10_FSM
+       :gconfig: GAPPLIC10_GCONFIG
+
+    *Input-Events:*
+        * :attr:`'EV_TIMEOUT'`: Timer over.
+
+    """
+    __acl__ = [
+        (Allow, Everyone, 'view'),
+        (DENY_ALL),
+    ]
+
+    def __init__(self):
+        GObj.__init__(self, GAPPLIC10_FSM, GAPPLIC10_GCONFIG)
+
+    def start_up(self):
+        """ Initialization zone.
+
+        # You could use declarative:
+        self.config.add_view(
+            default_view,
+            context=GApplic1,
+            permission='view',
+        )
+        """
+
+        self.timer = self.create_gobj(
+            None,       # unnamed gobj
+            GTimer,     # gclass
+            self        # parent
+        )
+        self.send_event(self.timer, 'EV_SET_TIMER', seconds=self.seconds)
+
+
+#-------------------------------------------#
+#               Views
+#-------------------------------------------#
+@view_config(context=GApplic10, permission='view')
+def default_view(self, request):
+    return Response('Counter = %d! <br/> Refresh me, please!!'% self.counter)

ginsfsm/scaffolds/multi_pyramid_wsgi/+package+/main.py_tmpl

+# -*- encoding: utf-8 -*-
+"""
+{{package}}
+{{len(package)*'='}}
+
+It uses :class:`ginsfsm.protocols.wsgi.server.c_wsgi_server.GWsgiServer`.
+
+.. autofunction:: main
+
+"""
+
+from ginsfsm.gaplic import GAplic
+from ginsfsm.globals import (
+    set_global_app,
+    set_global_main_gaplic,
+)
+from ginsfsm.protocols.wsgi.server.c_wsgi_server import GWsgiServer
+from {{package}}.applic10 import applic10_wsgi_app
+
+
+#===============================================================
+#       Paste app's factory.
+#       To run with gserve {{package}}.ini
+#===============================================================
+def admin_paste_factory(global_config, **local_conf):
+    """ TODO
+    """
+    def admin_wsgi(environ, start_response):
+        start_response('200 OK', [('Content-Type', 'text/plain')])
+        yield 'Hello Admin!\n'
+
+    return admin_wsgi
+
+
+def applic10_paste_factory(global_config, **local_conf):
+    """ Returns the applic10 WSGI application.
+    """
+    return applic10_wsgi_app(global_config, **local_conf)
+
+
+def applic20_paste_factory(global_config, **local_conf):
+    """ TODO
+    """
+    def applic20_wsgi(environ, start_response):
+        start_response('200 OK', [('Content-Type', 'text/plain')])
+        yield 'Hello applic20!\n'
+    return applic20_wsgi
+
+
+#===============================================================
+#                   Main
+#===============================================================
+def main(global_config, **local_conf):
+    """ Entry point to run with gserve (PasteDeploy)
+    """
+    if 'application' in local_conf:
+        application = local_conf.pop('application')
+    else:
+        raise Exception('You must supply a wsgi application in ini file.')
+
+    if 'gaplic_name' in local_conf:
+        gaplic_name = local_conf.pop('gaplic_name')
+    else:
+        raise Exception('You must supply a gaplic name in ini file.')
+
+    if 'wsgi_server_name' in local_conf:
+        wsgi_server_name = local_conf.pop('wsgi_server_name')
+    else:
+        raise Exception('You must supply a wsgi server name in ini file.')
+
+    ga = GAplic(gaplic_name, **local_conf)
+    set_global_main_gaplic(ga)
+    ga.create_gobj(
+        wsgi_server_name,
+        GWsgiServer,
+        None,
+        application=application,
+    )
+    return ga
+
+
+if __name__ == "__main__":
+    """ You can run directly this file as main, without gserve.
+    """
+    import logging
+    logging.basicConfig(level=logging.DEBUG)
+
+    # simulate running from ini file
+
+    from ginsfsm.protocols.wsgi.common.urlmap import (
+        URLMap,
+        parse_path_expression,
+    )
+
+    applic10_settings = {
+        'pyramid.reload_templates': True,
+        'pyramid.debug_authorization': False,
+        'pyramid.debug_notfound': False,
+        'pyramid.debug_routematch': False,
+        'pyramid.debug_templates': True,
+        'pyramid.default_locale_name': 'en',
+    }
+    route_apps = {
+        '/': admin_paste_factory({}),
+        '/applic10': applic10_paste_factory({}, **applic10_settings),
+        '/applic20': applic20_paste_factory({})
+    }
+
+    urlmap = URLMap()
+    for path, app in route_apps.items():
+        path = parse_path_expression(path)
+        urlmap[path] = app
+
+    set_global_app(
+        'wsgi-application',
+        urlmap,
+    )
+
+    local_conf = {
+        'GObj.trace_mach': True,
+        'GObj.logger': logging,
+        'GSock.trace_dump': True,
+        'host': '0.0.0.0',
+        'port': 8002,
+        'application': 'wsgi-application',
+    }
+
+    ga = main({}, **local_conf)
+
+    try:
+        ga.mt_process()
+    except (KeyboardInterrupt, SystemExit):
+        print('Program stopped')

ginsfsm/scaffolds/multi_pyramid_wsgi/CHANGES.txt_tmpl

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

ginsfsm/scaffolds/multi_pyramid_wsgi/MANIFEST.in_tmpl

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

ginsfsm/scaffolds/multi_pyramid_wsgi/README.rst_tmpl

+{{project}}
+{{len(project)*'='}}
+
+License
+-------
+
+Copyright (c) 2013
+
+{{project}} 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/scaffolds/multi_pyramid_wsgi/docs/DejaVuSans.ttf

Binary file added.

ginsfsm/scaffolds/multi_pyramid_wsgi/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/scaffolds/multi_pyramid_wsgi/docs/api_+package+.rst_tmpl

+{{package}}
+{{len(package)*'='}}
+
+This is the main index page of your documentation. It should be written in
+`reStructuredText format <http://docutils.sourceforge.net/rst.html>`_.
+
+
+:mod:`{{package}}`
+{{(len(package) + 7) * '-'}}
+
+.. automodule:: {{package}}

ginsfsm/scaffolds/multi_pyramid_wsgi/setup.cfg_tmpl

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

ginsfsm/scaffolds/multi_pyramid_wsgi/setup.py_tmpl

+# -*- encoding: utf-8 -*-
+
+import os
+import sys
+import {{package}}
+
+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 >= 0.4.1',
+    'pyramid >= 1.4',
+]
+
+setup(name='{{package}}',
+    version={{package}}.__version__,
+    description='{{package}}',
+    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="{{package}}.tests",
+    entry_points="""\
+    [paste.app_factory]
+    main = {{package}}.main:main
+    admin = {{package}}.main:admin_paste_factory
+    applic10 = {{package}}.main:applic10_paste_factory
+    applic20 = {{package}}.main:applic20_paste_factory
+    """,
+)

ginsfsm/scaffolds/multiple_wsgi/+package+.ini_tmpl

 wsgi = wsgi-application
 
 [app:wsgi-server]
-use = call:{{project}}.main:main
+use = call:{{package}}.main:main
 wsgi-server.host = 0.0.0.0
 wsgi-server.port = 8000
 application = wsgi-application
 /app3 = application3
 
 [app:application1]
-use = call:{{project}}.main:paste_app_factory1
+use = call:{{package}}.main:paste_app_factory1
 
 [app:application2]
-use = call:{{project}}.main:paste_app_factory2
+use = call:{{package}}.main:paste_app_factory2
 
 [app:application3]
-use = call:{{project}}.main:paste_app_factory3
+use = call:{{package}}.main:paste_app_factory3
 
 # Begin logging configuration
 

ginsfsm/scaffolds/simple_wsgi/+package+.ini_tmpl

 wsgi = wsgi-application
 
 [app:wsgi-server]
-use = call:{{project}}.main:main
+use = call:{{package}}.main:main
 wsgi-server.host = 0.0.0.0
 wsgi-server.port = 8000
 application = wsgi-application
 GObj.trace_mach = true
 
 [app:wsgi-application]
-use = call:{{project}}.main:paste_app_factory
+use = call:{{package}}.main:paste_app_factory
 
 # Begin logging configuration
 
         simple_gobj=ginsfsm.scaffolds:SimpleGObjTemplate
         simple_wsgi=ginsfsm.scaffolds:SimpleWsgiTemplate
         multiple_wsgi=ginsfsm.scaffolds:MultipleWsgiTemplate
+        multi_pyramid_wsgi=ginsfsm.scaffolds:MultiplePyramidWsgiTemplate
 
         [console_scripts]
         gcreate = ginsfsm.scripts.gcreate:main
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.