Commits

Ginés Martínez Sánchez committed 71b30b4 Draft

added simple_wsgi scaffold

  • Participants
  • Parent commits 2840ec1

Comments (0)

Files changed (18)

ginsfsm/examples/wsgi/multiple_wsgi_server.py

 
 
 #===============================================================
-#                   Server
+#                   Wsgi apps
 #===============================================================
 def application1(environ, start_response):
     start_response('200 OK', [('Content-Type', 'text/plain')])

ginsfsm/examples/wsgi/simple_wsgi_server.py

 
 
 #===============================================================
-#                   Server
+#                   Wsgi app
 #===============================================================
 def application(environ, start_response):
     start_response('200 OK', [('Content-Type', 'text/plain')])

ginsfsm/scaffolds/__init__.py

 class SimpleGObjTemplate(GinsFSMTemplate):
     _template_dir = 'simple_gobj'
     summary = 'Create a simple GObj proyect.'
+
+
+class SimpleWsgiTemplate(GinsFSMTemplate):
+    _template_dir = 'simple_wsgi'
+    summary = 'Create a simple WSGI proyect with pyramid.'
+
+
+class MultipleWsgiTemplate(GinsFSMTemplate):
+    _template_dir = 'multiple_wsgi'
+    summary = 'Create a multiple WSGI proyect with pyramid.'
+

ginsfsm/scaffolds/simple_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
+host = 0.0.0.0
+port = 8000
+application = wsgi-application
+GSock.trace_dump = true
+GObj.trace_mach = true
+
+[app:wsgi-application]
+use = call:{{project}}.main:paste_app_factory
+
+# 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/simple_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/simple_wsgi/+package+/app.py_tmpl

+# -*- encoding: utf-8 -*-
+""" Sample wsgi application.
+"""
+
+
+def wsgi_application(environ, start_response):
+    start_response('200 OK', [('Content-Type', 'text/plain')])
+    yield 'Hello World\n'
+

ginsfsm/scaffolds/simple_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 factory.
+#       To run with gserve {{package}}.ini
+#===============================================================
+from {{package}}.app import wsgi_application
+
+def paste_app_factory(global_config, **local_conf):
+    return wsgi_application
+
+
+#===============================================================
+#                   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
+    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',
+		paste_app_factory({}, **local_conf)
+	)
+    ga = main({}, **local_conf)
+
+    try:
+        ga.mt_process()
+    except (KeyboardInterrupt, SystemExit):
+        print('Program stopped')

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

+#

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

+import unittest
+

ginsfsm/scaffolds/simple_wsgi/CHANGES.txt_tmpl

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

ginsfsm/scaffolds/simple_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/simple_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

ginsfsm/scaffolds/simple_wsgi/docs/DejaVuSans.ttf

Binary file added.

ginsfsm/scaffolds/simple_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/simple_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/simple_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/simple_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='{{project}}',
+    version={{package}}.__version__,
+    description='{{project}}',
+    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="""\
+    """,
+)
     entry_points="""
         [ginsfsm.scaffold]
         simple_gobj=ginsfsm.scaffolds:SimpleGObjTemplate
+        simple_wsgi=ginsfsm.scaffolds:SimpleWsgiTemplate
+        multiple_wsgi=ginsfsm.scaffolds:MultipleWsgiTemplate
 
         [console_scripts]
         gcreate = ginsfsm.scripts.gcreate:main