Permalink
Browse files

init commit. version 1.0

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

0 comments on commit 93f3ecb

Please sign in to comment.