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

added multiple wsgi-app server scaffold

Comments (0)

Files changed (21)

ginsfsm/examples/wsgi/multiple_wsgi_server.ini

 
 [app:wsgi-server]
 use = call:ginsfsm.examples.wsgi.multiple_wsgi_server:main
-host = 0.0.0.0
-port = 8000
+wsgi-server.host = 0.0.0.0
+wsgi-server.port = 8000
 application = wsgi-application
 GSock.trace_dump = true
 GObj.trace_mach = true

ginsfsm/examples/wsgi/multiple_wsgi_server.py

 import logging
 logging.basicConfig(level=logging.DEBUG)
 
-from ginsfsm.globals import get_global_app
 from ginsfsm.gaplic import GAplic
+from ginsfsm.globals import get_global_app, set_global_app
 from ginsfsm.protocols.wsgi.server.c_wsgi_server import GWsgiServer
 #from ginsfsm.protocols.wsgi.common.urlmap import URLMap
 
 
 
 if __name__ == "__main__":
+    """ You can run directly this file, without gserve.
+    """
+    from ginsfsm.protocols.wsgi.common.urlmap import (
+        URLMap,
+        parse_path_expression,
+    )
+    local_conf = {
+        '/': application1,
+        '/app2': application2,
+        '/app3': application3,
+    }
+
+    urlmap = URLMap()
+    for path, app in local_conf.items():
+        path = parse_path_expression(path)
+        urlmap[path] = app
+
     local_conf = {
         'GObj.trace_mach': True,
         'GObj.logger': logging,
         'GSock.trace_dump': True,
-        'host': '0.0.0.0',
-        'port': 8002,
+        'wsgi-server.host': '0.0.0.0',
+        'wsgi-server.port': 8002,
+        'application': 'wsgi-application',
     }
+    set_global_app(
+        'wsgi-application',
+        urlmap,
+    )
+
     ga = main({}, **local_conf)
 
     try:

ginsfsm/examples/wsgi/simple_wsgi_server.ini

 
 [app:wsgi-server]
 use = call:ginsfsm.examples.wsgi.simple_wsgi_server:main
-host = 0.0.0.0
-port = 8000
+wsgi-server.host = 0.0.0.0
+wsgi-server.port = 8000
 application = wsgi-application
 GSock.trace_dump = true
 GObj.trace_mach = true

ginsfsm/examples/wsgi/simple_wsgi_server.py

 logging.basicConfig(level=logging.DEBUG)
 
 from ginsfsm.gaplic import GAplic
-from ginsfsm.globals import get_global_app
+from ginsfsm.globals import get_global_app, set_global_app
 from ginsfsm.protocols.wsgi.server.c_wsgi_server import GWsgiServer
 
 
         'GObj.trace_mach': True,
         'GObj.logger': logging,
         'GSock.trace_dump': True,
-        'host': '0.0.0.0',
-        'port': 8002,
+        'wsgi-server.host': '0.0.0.0',
+        'wsgi-server.port': 8002,
         'application': 'wsgi-application',
     }
+    set_global_app(
+        'wsgi-application',
+        paste_app_factory({}, **local_conf)
+    )
     ga = main({}, **local_conf)
 
     try:

ginsfsm/scaffolds/multiple_wsgi/+package+.ini_tmpl

+[composite:main]
+use = call:ginsfsm.gaplic:gaplic_factory
+main = wsgi-server
+wsgi = wsgi-application
+
+[app:wsgi-server]
+use = call:{{project}}.main:main
+wsgi-server.host = 0.0.0.0
+wsgi-server.port = 8000
+application = wsgi-application
+GSock.trace_dump = true
+GObj.trace_mach = true
+
+[composite:wsgi-application]
+use = call:ginsfsm.protocols.wsgi.common.urlmap:urlmap_factory
+/ = application1
+/app2 = application2
+/app3 = application3
+
+[app:application1]
+use = call:{{project}}.main:paste_app_factory1
+
+[app:application2]
+use = call:{{project}}.main:paste_app_factory2
+
+[app:application3]
+use = call:{{project}}.main:paste_app_factory3
+
+# 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/multiple_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/multiple_wsgi/+package+/apps.py_tmpl

+# -*- encoding: utf-8 -*-
+""" Sample wsgi application.
+"""
+
+#===============================================================
+#                   Wsgi apps
+#===============================================================
+
+def application1(environ, start_response):
+    start_response('200 OK', [('Content-Type', 'text/plain')])
+    yield 'Hello World ONE!\n'
+
+
+def application2(environ, start_response):
+    start_response('200 OK', [('Content-Type', 'text/plain')])
+    yield 'Hello World TWO!\n'
+
+
+def application3(environ, start_response):
+    start_response('200 OK', [('Content-Type', 'text/plain')])
+    yield 'Hello World THREE!\n'

ginsfsm/scaffolds/multiple_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 get_global_app, set_global_app
+from ginsfsm.protocols.wsgi.server.c_wsgi_server import GWsgiServer
+
+
+#===============================================================
+#       Paste app's factory.
+#       To run with gserve {{package}}.ini
+#===============================================================
+from {{package}}.apps import application1
+from {{package}}.apps import application2
+from {{package}}.apps import application3
+
+
+def paste_app_factory1(global_config, **local_conf):
+    return application1
+
+
+def paste_app_factory2(global_config, **local_conf):
+    return application2
+
+
+def paste_app_factory3(global_config, **local_conf):
+    return application3
+
+
+#===============================================================
+#                   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 an wsgi application.')
+    application = get_global_app(application)
+    ga = GAplic('Wsgi-Example', **local_conf)
+    ga.create_gobj(
+        'wsgi-server',
+        GWsgiServer,
+        None,
+        application=application,
+    )
+    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
+
+    from ginsfsm.protocols.wsgi.common.urlmap import (
+        URLMap,
+        parse_path_expression,
+    )
+    local_conf = {
+        '/': application1,
+        '/app2': application2,
+        '/app3': application3,
+    }
+
+    urlmap = URLMap()
+    for path, app in local_conf.items():
+        path = parse_path_expression(path)
+        urlmap[path] = app
+
+    local_conf = {
+        'GObj.trace_mach': True,
+        'GObj.logger': logging,
+        'GSock.trace_dump': True,
+        'host': '0.0.0.0',
+        'port': 8002,
+        'application': 'wsgi-application',
+    }
+    set_global_app(
+        'wsgi-application',
+        urlmap,
+    )
+
+    ga = main({}, **local_conf)
+
+    try:
+        ga.mt_process()
+    except (KeyboardInterrupt, SystemExit):
+        print('Program stopped')

ginsfsm/scaffolds/multiple_wsgi/+package+/tests/__init__.py

+#

ginsfsm/scaffolds/multiple_wsgi/+package+/tests/test_+package+.py_tmpl

+import unittest
+

ginsfsm/scaffolds/multiple_wsgi/CHANGES.txt_tmpl

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

ginsfsm/scaffolds/multiple_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/multiple_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/multiple_wsgi/docs/DejaVuSans.ttf

Binary file added.

ginsfsm/scaffolds/multiple_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/multiple_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/multiple_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/multiple_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']
+
+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="""\
+    """,
+)

ginsfsm/scaffolds/simple_wsgi/+package+.ini_tmpl

 
 [app:wsgi-server]
 use = call:{{project}}.main:main
-host = 0.0.0.0
-port = 8000
+wsgi-server.host = 0.0.0.0
+wsgi-server.port = 8000
 application = wsgi-application
 GSock.trace_dump = true
 GObj.trace_mach = true

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

         'GObj.trace_mach': True,
         'GObj.logger': logging,
         'GSock.trace_dump': True,
-        'host': '0.0.0.0',
-        'port': 8002,
-        'application': 'wsgi-application',
+        'wsgi-server.host': '0.0.0.0',
+        'wsgi-server.port': 8002,
+        'wsgi-server.application': 'wsgi-application',
     }
     set_global_app(
-		'wsgi-application',
-		paste_app_factory({}, **local_conf)
-	)
+        'wsgi-application',
+        paste_app_factory({}, **local_conf)
+    )
     ga = main({}, **local_conf)
 
     try:

ginsfsm/scaffolds/simple_wsgi/setup.py_tmpl

 
 requires = ['ginsfsm']
 
-setup(name='{{project}}',
+setup(name='{{package}}',
     version={{package}}.__version__,
-    description='{{project}}',
+    description='{{package}}',
     long_description=README + '\n\n' + CHANGES,
     classifiers=[
         "Programming Language :: Python",
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.