Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

init commit. version 1.0

  • Loading branch information...
commit 93f3ecb1bdeb4ccd68945839b9f3f5a6e2882b8e 0 parents
Miroslav Shubernetskiy authored
80 README.rst
Source Rendered
... ... @@ -0,0 +1,80 @@
  1 +Gevent Deploy
  2 +=============
  3 +
  4 +This library adds a simple hook into Django's ``manage.py`` to be able to start gevent's WSGI
  5 +server to serve the Django project.
  6 +
  7 +Install
  8 +-------
  9 +
  10 +Install the library into your Python installation via ``pip``::
  11 +
  12 + pip install django-gevent-deploy
  13 +
  14 +Then add the library into ``INSTALLED_APPS`` within Django's project ``settings.py``::
  15 +
  16 + INSTALLED_APPS = (
  17 + ...
  18 + 'gevent_deploy',
  19 + )
  20 +
  21 +Configuration
  22 +-------------
  23 +
  24 +You may add two settings to your ``settings.py``:
  25 +
  26 +:``GEVENT_ADDR_PORT``:
  27 + Specifies what address and what port should be used for the gevent's WSGI server.
  28 + Must be a string and of the ``[[addr:]port]`` format::
  29 +
  30 + 8000 # default
  31 + localhost:8000
  32 + 127.0.0.1:8000
  33 +
  34 +:``GEVENT_POOL_SIZE``:
  35 + Specifies the number of greenlets gevent can spawn for the server. Can be ``None``
  36 + or an integer value::
  37 +
  38 + None # default
  39 + 1
  40 + 100
  41 +
  42 +Usage
  43 +-----
  44 +
  45 +To start the gevent's WSGI server, simply call ``rungevent`` in ``manage.py``. The command
  46 +accepts optional argumets which are the same as described in `Configuration`_ section.
  47 +If the arguments are not provided, then the configuration from the ``settings.py`` is used,
  48 +or default if ``settings.py`` is not configured.
  49 +
  50 + $ python manage.py rungevent [[addr]:port] [pool_size]
  51 +
  52 +Credits
  53 +-------
  54 +
  55 +* Miroslav Shubernetskiy
  56 +
  57 +License
  58 +-------
  59 +
  60 +This library is packaged with MIT license::
  61 +
  62 + Permission is hereby granted, free of charge, to any person obtaining
  63 + a copy of this software and associated documentation files (the
  64 + "Software"), to deal in the Software without restriction, including
  65 + without limitation the rights to use, copy, modify, merge, publish,
  66 + distribute, sublicense, and/or sell copies of the Software, and to
  67 + permit persons to whom the Software is furnished to do so, subject to
  68 + the following conditions:
  69 +
  70 + The above copyright notice and this permission notice shall be
  71 + included in all copies or substantial portions of the Software.
  72 +
  73 + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  74 + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  75 + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  76 + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  77 + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  78 + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  79 + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  80 +
2  django_gevent_deploy/__init__.py
... ... @@ -0,0 +1,2 @@
  1 +__version__ = '1.0'
  2 +__author__ = 'Miroslav Shubernetskiy'
0  django_gevent_deploy/management/__init__.py
No changes.
0  django_gevent_deploy/management/commands/__init__.py
No changes.
45 django_gevent_deploy/management/commands/rungevent.py
... ... @@ -0,0 +1,45 @@
  1 +from django.conf import settings
  2 +from django.core.management.base import BaseCommand, CommandError
  3 +from django.core.servers.basehttp import get_internal_wsgi_application
  4 +from gevent import wsgi
  5 +from gevent.pool import Pool
  6 +
  7 +
  8 +defaults = {
  9 + 'GEVENT_ADDR_PORT': '8000',
  10 + 'GEVENT_POOL_SIZE': None
  11 +}
  12 +
  13 +class Command(BaseCommand):
  14 + help = "Run gevent's WSGI serve Django project"
  15 + args = '[port number or ipaddr:port] [pool size]'
  16 +
  17 + def handle(self, addr_port=None, pool_size=None, *args, **options):
  18 + if args:
  19 + raise CommandError('Usage: [ipaddr:]addr_port pool_size')
  20 +
  21 + addr_port = addr_port or getattr(settings, 'GEVENT_ADDR_PORT', defaults['GEVENT_ADDR_PORT'])
  22 + pool_size = pool_size or getattr(settings, 'GEVENT_POOL_SIZE', defaults['GEVENT_POOL_SIZE'])
  23 +
  24 + try:
  25 + addr, port = addr_port.split(':')
  26 + except ValueError:
  27 + addr, port = '', addr_port
  28 +
  29 + try:
  30 + port = int(port)
  31 + except ValueError:
  32 + raise CommandError('Port must be an integer')
  33 +
  34 + if pool_size:
  35 + try:
  36 + pool_size = int(pool_size)
  37 + pool = Pool(pool_size)
  38 + except ValueError:
  39 + raise CommandError('Spawn pool size must be an integer')
  40 + else:
  41 + pool = None
  42 +
  43 + wsgi_application = get_internal_wsgi_application()
  44 + wsgi.WSGIServer((addr, port), wsgi_application, spawn=pool).serve_forever()
  45 +
0  django_gevent_deploy/models.py
No changes.
0  django_gevent_deploy/views.py
No changes.
100 setup.py
... ... @@ -0,0 +1,100 @@
  1 +"""
  2 +Based entirely on Django's own ``setup.py``.
  3 +"""
  4 +import os
  5 +import sys
  6 +from distutils.command.install_data import install_data
  7 +from distutils.command.install import INSTALL_SCHEMES
  8 +try:
  9 + from setuptools import setup
  10 +except ImportError:
  11 + from distutils.core import setup # NOQA
  12 +
  13 +from django_gevent_deploy import __version__, __author__
  14 +
  15 +
  16 +class osx_install_data(install_data):
  17 + # On MacOS, the platform-specific lib dir is at:
  18 + # /System/Library/Framework/Python/.../
  19 + # which is wrong. Python 2.5 supplied with MacOS 10.5 has an Apple-specific
  20 + # fix for this in distutils.command.install_data#306. It fixes install_lib
  21 + # but not install_data, which is why we roll our own install_data class.
  22 +
  23 + def finalize_options(self):
  24 + # By the time finalize_options is called, install.install_lib is set to
  25 + # the fixed directory, so we set the installdir to install_lib. The
  26 + # install_data class uses ('install_data', 'install_dir') instead.
  27 + self.set_undefined_options('install', ('install_lib', 'install_dir'))
  28 + install_data.finalize_options(self)
  29 +
  30 +if sys.platform == "darwin":
  31 + cmdclasses = {'install_data': osx_install_data}
  32 +else:
  33 + cmdclasses = {'install_data': install_data}
  34 +
  35 +
  36 +def fullsplit(path, result=None):
  37 + """
  38 + Split a pathname into components (the opposite of os.path.join) in a
  39 + platform-neutral way.
  40 + """
  41 + if result is None:
  42 + result = []
  43 + head, tail = os.path.split(path)
  44 + if head == '':
  45 + return [tail] + result
  46 + if head == path:
  47 + return result
  48 + return fullsplit(head, [tail] + result)
  49 +
  50 +# Tell distutils to put the data_files in platform-specific installation
  51 +# locations. See here for an explanation:
  52 +# http://groups.google.com/group/comp.lang.python/browse_thread/thread/35ec7b2fed36eaec/2105ee4d9e8042cb
  53 +for scheme in INSTALL_SCHEMES.values():
  54 + scheme['data'] = scheme['purelib']
  55 +
  56 +# Compile the list of packages available, because distutils doesn't have
  57 +# an easy way to do this.
  58 +packages, data_files = [], []
  59 +root_dir = os.path.dirname(__file__)
  60 +if root_dir != '':
  61 + os.chdir(root_dir)
  62 +extensions_dir = 'django_gevent_deploy'
  63 +
  64 +for dirpath, dirnames, filenames in os.walk(extensions_dir):
  65 + # Ignore dirnames that start with '.'
  66 + if os.path.basename(dirpath).startswith("."):
  67 + continue
  68 + if '__init__.py' in filenames:
  69 + packages.append('.'.join(fullsplit(dirpath)))
  70 + elif filenames:
  71 + data_files.append([dirpath, [os.path.join(dirpath, f) for f in filenames]])
  72 +
  73 +def read(fname):
  74 + return open(os.path.join(os.path.dirname(__file__), fname)).read()
  75 +
  76 +
  77 +setup(
  78 + name = "django-gevent-deploy",
  79 + version = __version__,
  80 + author = __author__,
  81 + author_email = "miroslav@miki725.com",
  82 + description = ("Django manage.py hook for starting gevent's WSGI server"),
  83 + long_description = read('README.rst'),
  84 + license = "MIT",
  85 + keywords = "django",
  86 + url = "https://github.com/miki725/django-gevent-deploy",
  87 + packages = packages,
  88 + cmdclass = cmdclasses,
  89 + data_files = data_files,
  90 + install_requires = ['django'],
  91 + classifiers = [
  92 + "Development Status :: 3 - Alpha",
  93 + 'Framework :: Django',
  94 + 'Intended Audience :: Developers',
  95 + 'Operating System :: OS Independent',
  96 + 'Programming Language :: Python',
  97 + "Topic :: Utilities",
  98 + "License :: OSI Approved :: MIT License",
  99 + ],
  100 +)

0 comments on commit 93f3ecb

Please sign in to comment.
Something went wrong with that request. Please try again.