Merge pull request #271 from niphlod/enhancement/windows_build
fix building on windows. New handler for gevented webserver
This commit is contained in:
commit
8877eab977
3 files changed
+133
-7
No files matched your search
@@ -22,3 +22,6 @@ zip_filename = web2py_win
|
||||
#should the build, deposit & dist directories used by py2exe be removed?
|
||||
#if you created a zip file you likely don't need these directories anymore
|
||||
remove_build_files = Yes
|
||||
|
||||
#should the build include the gevented webserver (needs gevent)
|
||||
include_gevent = Yes
|
||||
@@ -64,16 +64,12 @@ copy_scripts = Config.getboolean("Setup", "copy_scripts")
|
||||
make_zip = Config.getboolean("Setup", "make_zip")
|
||||
zip_filename = Config.get("Setup", "zip_filename")
|
||||
remove_build_files = Config.getboolean("Setup", "remove_build_files")
|
||||
include_gevent = Config.getboolean("Setup", "include_gevent")
|
||||
|
||||
# Python base version
|
||||
python_version = sys.version_info[:3]
|
||||
|
||||
if python_version > (2,5):
|
||||
# Python26 compatibility: http://www.py2exe.org/index.cgi/Tutorial#Step52
|
||||
try:
|
||||
shutil.copytree('C:\Bin\Microsoft.VC90.CRT', 'dist/')
|
||||
except:
|
||||
print "You MUST copy Microsoft.VC90.CRT folder into the archive"
|
||||
|
||||
|
||||
if BUILD_MODE == 'py2exe':
|
||||
import py2exe
|
||||
@@ -117,14 +113,20 @@ elif BUILD_MODE == 'bbfreeze':
|
||||
modules = base_modules + contributed_modules
|
||||
from bbfreeze import Freezer
|
||||
f = Freezer(distdir="dist", includes=(modules))
|
||||
#f.addScript("web2py_gevent.py")
|
||||
f.addScript("web2py.py")
|
||||
#to make executable without GUI we need this trick
|
||||
shutil.copy("web2py.py", "web2py_no_console.py")
|
||||
f.addScript("web2py_no_console.py", gui_only=True)
|
||||
if include_gevent:
|
||||
#fetch the gevented webserver script and copy to root
|
||||
gevented_webserver = os.path.join("handlers", "web2py_on_gevent.py")
|
||||
shutil.copy(gevented_webserver, "web2py_on_gevent.py")
|
||||
f.addScript("web2py_on_gevent.py")
|
||||
f.setIcon('extras/icons/web2py.ico')
|
||||
f() # starts the freezing process
|
||||
os.unlink("web2py_no_console.py")
|
||||
if include_gevent:
|
||||
os.unlink("web2py_on_gevent.py")
|
||||
#add data_files
|
||||
for req in ['ABOUT', 'LICENSE', 'VERSION']:
|
||||
shutil.copy(req, os.path.join('dist', req))
|
||||
@@ -135,6 +137,14 @@ try:
|
||||
except:
|
||||
pass
|
||||
|
||||
#This need to happen after bbfreeze is run because Freezer() deletes distdir before starting!
|
||||
if python_version > (2,5):
|
||||
# Python26 compatibility: http://www.py2exe.org/index.cgi/Tutorial#Step52
|
||||
try:
|
||||
shutil.copytree('C:\Bin\Microsoft.VC90.CRT', 'dist/Microsoft.VC90.CRT/')
|
||||
except:
|
||||
print "You MUST copy Microsoft.VC90.CRT folder into the archive"
|
||||
|
||||
def copy_folders(source, destination):
|
||||
"""Copy files & folders from source to destination (within dist/)"""
|
||||
if os.path.exists(os.path.join('dist', destination)):
|
||||
|
||||
@@ -0,0 +1,113 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import sys
|
||||
import os
|
||||
import optparse
|
||||
|
||||
if '__file__' in globals():
|
||||
path = os.path.dirname(os.path.abspath(__file__))
|
||||
elif hasattr(sys, 'frozen'):
|
||||
path = os.path.dirname(os.path.abspath(sys.executable))
|
||||
else:
|
||||
path = os.getcwd()
|
||||
os.chdir(path)
|
||||
|
||||
sys.path = [path] + [p for p in sys.path if not p == path]
|
||||
|
||||
from gevent import pywsgi
|
||||
from gevent.pool import Pool
|
||||
from gevent import monkey
|
||||
monkey.patch_all()
|
||||
|
||||
def run(options):
|
||||
import gluon.main
|
||||
if options.password != '<recycle>':
|
||||
gluon.main.save_password(options.password, int(options.port))
|
||||
if options.logging:
|
||||
application = gluon.main.appfactory(wsgiapp=gluon.main.wsgibase,
|
||||
logfilename='httpserver.log',
|
||||
profiler_dir=profiler)
|
||||
else:
|
||||
application = gluon.main.wsgibase
|
||||
address = (options.ip, int(options.port))
|
||||
workers = options.workers
|
||||
spawn = workers and Pool(int(options.workers)) or 'default'
|
||||
ssl_args = dict()
|
||||
if options.ssl_private_key:
|
||||
ssl_args['keyfile'] = options.ssl_private_key
|
||||
if options.ssl_certificate:
|
||||
ssl_args['certfile'] = options.ssl_certificate
|
||||
server = pywsgi.WSGIServer(
|
||||
address, application,
|
||||
spawn=spawn, log=None,
|
||||
**ssl_args
|
||||
)
|
||||
server.serve_forever()
|
||||
|
||||
def main():
|
||||
usage = 'python web2py_gevent.py -i 127.0.0.1 -p 8000 -a "<recycle>"'
|
||||
try:
|
||||
version = open('VERSION','r')
|
||||
except IOError:
|
||||
version = ''
|
||||
parser = optparse.OptionParser(usage, None, optparse.Option, version)
|
||||
msg = ('password to be used for administration '
|
||||
'(use -a "<recycle>" to reuse the last password))')
|
||||
parser.add_option('-a',
|
||||
'--password',
|
||||
default='<recycle>',
|
||||
dest='password',
|
||||
help=msg)
|
||||
|
||||
parser.add_option('-c',
|
||||
'--ssl_certificate',
|
||||
default='',
|
||||
dest='ssl_certificate',
|
||||
help='file that contains ssl certificate')
|
||||
|
||||
parser.add_option('-k',
|
||||
'--ssl_private_key',
|
||||
default='',
|
||||
dest='ssl_private_key',
|
||||
help='file that contains ssl private key')
|
||||
|
||||
parser.add_option('-l',
|
||||
'--logging',
|
||||
action='store_true',
|
||||
default=False,
|
||||
dest='logging',
|
||||
help='log into httpserver.log')
|
||||
|
||||
parser.add_option('-F',
|
||||
'--profiler',
|
||||
dest='profiler_dir',
|
||||
default=None,
|
||||
help='profiler dir')
|
||||
|
||||
parser.add_option('-i',
|
||||
'--ip',
|
||||
default='127.0.0.1',
|
||||
dest='ip',
|
||||
help='ip address')
|
||||
|
||||
parser.add_option('-p',
|
||||
'--port',
|
||||
default='8000',
|
||||
dest='port',
|
||||
help='port number')
|
||||
|
||||
parser.add_option('-w',
|
||||
'--workers',
|
||||
default=None,
|
||||
dest='workers',
|
||||
help='number of workers')
|
||||
|
||||
(options, args) = parser.parse_args()
|
||||
print 'starting on %s:%s...' % (
|
||||
options.ip, options.port)
|
||||
run(options)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
Reference in new issue
Block a user