mirror of
https://github.com/frappe/gunicorn.git
synced 2026-01-14 11:09:11 +08:00
replace /bin/* py setup entry-points
This commit is contained in:
parent
ea9ccf0da1
commit
614a5d25c1
28
bin/gunicorn
28
bin/gunicorn
@ -1,28 +0,0 @@
|
|||||||
#! /usr/bin/env python
|
|
||||||
# -*- coding: utf-8 -
|
|
||||||
#
|
|
||||||
# This file is part of gunicorn released under the MIT license.
|
|
||||||
# See the NOTICE for more information.
|
|
||||||
|
|
||||||
|
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
|
|
||||||
sys.path.insert(0, os.getcwd())
|
|
||||||
|
|
||||||
from gunicorn.main import main
|
|
||||||
from gunicorn.util import import_app
|
|
||||||
|
|
||||||
__usage__ = "%prog [OPTIONS] APP_MODULE"
|
|
||||||
|
|
||||||
def get_app(parser, opts, args):
|
|
||||||
if len(args) != 1:
|
|
||||||
parser.error("No application module specified.")
|
|
||||||
|
|
||||||
try:
|
|
||||||
return import_app(args[0])
|
|
||||||
except:
|
|
||||||
parser.error("Failed to import application module.")
|
|
||||||
|
|
||||||
main(__usage__, get_app)
|
|
||||||
|
|
||||||
@ -1,34 +0,0 @@
|
|||||||
#! /usr/bin/env python
|
|
||||||
# -*- coding: utf-8 -
|
|
||||||
#
|
|
||||||
# This file is part of gunicorn released under the MIT license.
|
|
||||||
# See the NOTICE for more information.
|
|
||||||
|
|
||||||
|
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
|
|
||||||
from django.core.handlers.wsgi import WSGIHandler
|
|
||||||
from gunicorn.main import main
|
|
||||||
|
|
||||||
__usage__ = "%prog [OPTIONS]"
|
|
||||||
|
|
||||||
PROJECT_PATH = os.getcwd()
|
|
||||||
if not os.path.isfile(os.path.join(PROJECT_PATH, "settings.py")):
|
|
||||||
print >>sys.stderr, "settings file not found."
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
PROJECT_NAME = os.path.split(PROJECT_PATH)[-1]
|
|
||||||
|
|
||||||
sys.path.insert(0, PROJECT_PATH)
|
|
||||||
sys.path.append(os.path.join(PROJECT_PATH, os.pardir))
|
|
||||||
|
|
||||||
# set environ
|
|
||||||
os.environ['DJANGO_SETTINGS_MODULE'] = '%s.settings' % PROJECT_NAME
|
|
||||||
|
|
||||||
|
|
||||||
def get_app(parser, opts, args):
|
|
||||||
# django wsgi app
|
|
||||||
return WSGIHandler()
|
|
||||||
|
|
||||||
main(__usage__, get_app)
|
|
||||||
@ -1,59 +0,0 @@
|
|||||||
#! /usr/bin/env python
|
|
||||||
# -*- coding: utf-8 -
|
|
||||||
#
|
|
||||||
# This file is part of gunicorn released under the MIT license.
|
|
||||||
# See the NOTICE for more information.
|
|
||||||
|
|
||||||
|
|
||||||
import os
|
|
||||||
import pkg_resources
|
|
||||||
import re
|
|
||||||
import sys
|
|
||||||
from paste.deploy import loadapp, loadwsgi
|
|
||||||
from gunicorn.main import main
|
|
||||||
|
|
||||||
__usage__ = "%prog [OPTIONS] APP_MODULE"
|
|
||||||
|
|
||||||
_scheme_re = re.compile(r'^[a-z][a-z]+:', re.I)
|
|
||||||
|
|
||||||
|
|
||||||
def get_app(parser, opts, args):
|
|
||||||
if len(args) != 1:
|
|
||||||
parser.error("No applicantion name specified.")
|
|
||||||
|
|
||||||
config_file = os.path.abspath(os.path.normpath(
|
|
||||||
os.path.join(os.getcwd(), args[0])))
|
|
||||||
|
|
||||||
if not os.path.exists(config_file):
|
|
||||||
parser.error("Config file not found.")
|
|
||||||
|
|
||||||
config_url = 'config:%s' % config_file
|
|
||||||
relative_to = os.path.dirname(config_file)
|
|
||||||
|
|
||||||
# load module in sys path
|
|
||||||
sys.path.insert(0, relative_to)
|
|
||||||
|
|
||||||
# add to eggs
|
|
||||||
pkg_resources.working_set.add_entry(relative_to)
|
|
||||||
ctx = loadwsgi.loadcontext(loadwsgi.SERVER, config_url,
|
|
||||||
relative_to=relative_to)
|
|
||||||
|
|
||||||
if opts.workers:
|
|
||||||
workers = opts.workers
|
|
||||||
else:
|
|
||||||
workers = int(ctx.local_conf.get('workers', 1))
|
|
||||||
|
|
||||||
opts.host = opts.host or ctx.local_conf.get('host', '127.0.0.1')
|
|
||||||
opts.port = opts.port or int(ctx.local_conf.get('port', 8000))
|
|
||||||
|
|
||||||
debug = ctx.global_conf.get('debug') == "true"
|
|
||||||
if debug:
|
|
||||||
# we force to one worker in debug mode.
|
|
||||||
workers = 1
|
|
||||||
|
|
||||||
opts.workers=workers
|
|
||||||
|
|
||||||
app = loadapp(config_url, relative_to=relative_to)
|
|
||||||
return app
|
|
||||||
|
|
||||||
main(__usage__, get_app)
|
|
||||||
@ -7,11 +7,15 @@
|
|||||||
import logging
|
import logging
|
||||||
import optparse as op
|
import optparse as op
|
||||||
import os
|
import os
|
||||||
|
import pkg_resources
|
||||||
|
import re
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from gunicorn.arbiter import Arbiter
|
from gunicorn.arbiter import Arbiter
|
||||||
from gunicorn import util
|
from gunicorn import util
|
||||||
|
|
||||||
|
__usage__ = "%prog [OPTIONS]"
|
||||||
|
|
||||||
LOG_LEVELS = {
|
LOG_LEVELS = {
|
||||||
"critical": logging.CRITICAL,
|
"critical": logging.CRITICAL,
|
||||||
"error": logging.ERROR,
|
"error": logging.ERROR,
|
||||||
@ -150,3 +154,93 @@ def paste_server(app, global_conf=None, host="127.0.0.1", port=None,
|
|||||||
else:
|
else:
|
||||||
os.setpgrp()
|
os.setpgrp()
|
||||||
arbiter.run()
|
arbiter.run()
|
||||||
|
|
||||||
|
def run():
|
||||||
|
sys.path.insert(0, os.getcwd())
|
||||||
|
|
||||||
|
def get_app(parser, opts, args):
|
||||||
|
if len(args) != 1:
|
||||||
|
parser.error("No application module specified.")
|
||||||
|
|
||||||
|
try:
|
||||||
|
return util.import_app(args[0])
|
||||||
|
except:
|
||||||
|
parser.error("Failed to import application module.")
|
||||||
|
|
||||||
|
main(__usage__, get_app)
|
||||||
|
|
||||||
|
def run_django():
|
||||||
|
from django.core.handlers.wsgi import WSGIHandler
|
||||||
|
|
||||||
|
PROJECT_PATH = os.getcwd()
|
||||||
|
if not os.path.isfile(os.path.join(PROJECT_PATH, "settings.py")):
|
||||||
|
print >>sys.stderr, "settings file not found."
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
PROJECT_NAME = os.path.split(PROJECT_PATH)[-1]
|
||||||
|
|
||||||
|
sys.path.insert(0, PROJECT_PATH)
|
||||||
|
sys.path.append(os.path.join(PROJECT_PATH, os.pardir))
|
||||||
|
|
||||||
|
# set environ
|
||||||
|
os.environ['DJANGO_SETTINGS_MODULE'] = '%s.settings' % PROJECT_NAME
|
||||||
|
|
||||||
|
|
||||||
|
def get_app(parser, opts, args):
|
||||||
|
# django wsgi app
|
||||||
|
return WSGIHandler()
|
||||||
|
|
||||||
|
main(__usage__, get_app)
|
||||||
|
|
||||||
|
def run_paster():
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
|
from paste.deploy import loadapp, loadwsgi
|
||||||
|
|
||||||
|
__usage__ = "%prog [OPTIONS] APP_MODULE"
|
||||||
|
|
||||||
|
_scheme_re = re.compile(r'^[a-z][a-z]+:', re.I)
|
||||||
|
|
||||||
|
|
||||||
|
def get_app(parser, opts, args):
|
||||||
|
if len(args) != 1:
|
||||||
|
parser.error("No applicantion name specified.")
|
||||||
|
|
||||||
|
config_file = os.path.abspath(os.path.normpath(
|
||||||
|
os.path.join(os.getcwd(), args[0])))
|
||||||
|
|
||||||
|
if not os.path.exists(config_file):
|
||||||
|
parser.error("Config file not found.")
|
||||||
|
|
||||||
|
config_url = 'config:%s' % config_file
|
||||||
|
relative_to = os.path.dirname(config_file)
|
||||||
|
|
||||||
|
# load module in sys path
|
||||||
|
sys.path.insert(0, relative_to)
|
||||||
|
|
||||||
|
# add to eggs
|
||||||
|
pkg_resources.working_set.add_entry(relative_to)
|
||||||
|
ctx = loadwsgi.loadcontext(loadwsgi.SERVER, config_url,
|
||||||
|
relative_to=relative_to)
|
||||||
|
|
||||||
|
if opts.workers:
|
||||||
|
workers = opts.workers
|
||||||
|
else:
|
||||||
|
workers = int(ctx.local_conf.get('workers', 1))
|
||||||
|
|
||||||
|
opts.host = opts.host or ctx.local_conf.get('host', '127.0.0.1')
|
||||||
|
opts.port = opts.port or int(ctx.local_conf.get('port', 8000))
|
||||||
|
|
||||||
|
debug = ctx.global_conf.get('debug') == "true"
|
||||||
|
if debug:
|
||||||
|
# we force to one worker in debug mode.
|
||||||
|
workers = 1
|
||||||
|
|
||||||
|
opts.workers=workers
|
||||||
|
|
||||||
|
app = loadapp(config_url, relative_to=relative_to)
|
||||||
|
return app
|
||||||
|
|
||||||
|
main(__usage__, get_app)
|
||||||
|
|
||||||
9
setup.py
9
setup.py
@ -9,7 +9,7 @@ from setuptools import setup, find_packages
|
|||||||
|
|
||||||
setup(
|
setup(
|
||||||
name = 'gunicorn',
|
name = 'gunicorn',
|
||||||
version = '0.3',
|
version = '0.3.1',
|
||||||
|
|
||||||
description = 'WSGI HTTP Server for UNIX',
|
description = 'WSGI HTTP Server for UNIX',
|
||||||
long_description = file(
|
long_description = file(
|
||||||
@ -38,9 +38,14 @@ setup(
|
|||||||
|
|
||||||
packages = ['gunicorn'],
|
packages = ['gunicorn'],
|
||||||
include_package_data = True,
|
include_package_data = True,
|
||||||
scripts = ['bin/gunicorn', 'bin/gunicorn_django', 'bin/gunicorn_paste'],
|
|
||||||
|
|
||||||
entry_points="""
|
entry_points="""
|
||||||
|
|
||||||
|
[console_scripts]
|
||||||
|
gunicorn=gunicorn.main:run
|
||||||
|
gunicorn_django=gunicorn.main:run_django
|
||||||
|
gunicorn_paster=gunicorn.main:run_paster
|
||||||
|
|
||||||
[paste.server_runner]
|
[paste.server_runner]
|
||||||
main=gunicorn.main:paste_server
|
main=gunicorn.main:paste_server
|
||||||
""",
|
""",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user