Zine

open source content publishing system


source: scripts/server @ 1340:9743d6a412bc

Revision 1340:9743d6a412bc, 3.0 KB checked in by mitsuhiko, 2 years ago (diff)

Updates for SA 0.6

  • Property exe set to *
Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3"""
4    Start a Zine Server
5    ~~~~~~~~~~~~~~~~~~~
6
7    This script opens a development server for Zine.
8
9    :copyright: (c) 2010 by the Zine Team, see AUTHORS for more details.
10    :license: BSD, see LICENSE for more details.
11"""
12import sys
13from os.path import abspath, join, pardir, isfile, dirname
14from optparse import OptionParser
15from werkzeug import run_simple, Response, DispatcherMiddleware
16
17
18sys.path.append(dirname(__file__))
19from _init_zine import find_instance
20from zine import get_wsgi_app
21
22
23def _make_root_app(real_location):
24    return Response('''
25    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
26    <title>Page Not Found</title>
27    <h2>Page Not Found</h2>
28    <p>
29      The blog was relocated to a different URL for testing purposes.
30    <ul>
31      <li><a href="%(blog)s">go to the blog</a></li>
32    </ul>
33    ''' % dict(blog=real_location), mimetype='text/html')
34
35
36def main():
37    parser = OptionParser(usage='%prog [options]')
38    parser.add_option('--hostname', '-a', dest='hostname', default='127.0.0.1')
39    parser.add_option('--port', '-p', dest='port', type='int', default=4000)
40    parser.add_option('--no-reloader', dest='reloader', action='store_false',
41                      default=True, help='Disable the reloader')
42    parser.add_option('--no-debugger', dest='debugger', action='store_false',
43                      default=True, help='Disable the debugger')
44    parser.add_option('--threaded', dest='threaded', action='store_true',
45                      default=False, help='Activate multithreading')
46    parser.add_option('--profile', dest='profile', action='store_true',
47                      help='Enable the profiler')
48    parser.add_option('--mount', dest='mount', default='/',
49                      help='If you want to mount the application somewhere '
50                      'outside the URL root.  This is useful for debugging '
51                      'URL generation problems.')
52    parser.add_option('--instance', '-I', dest='instance',
53                      help='Use the path provided as Zine instance.')
54    options, args = parser.parse_args()
55    if args:
56        parser.error('incorrect number of arguments')
57    instance = options.instance or find_instance()
58    if instance is None:
59        parser.error('instance not found.  Specify path to instance')
60
61    app = get_wsgi_app(instance)
62    if options.profile:
63        from werkzeug.contrib.profiler import ProfilerMiddleware
64        app = ProfilerMiddleware(app, stream=sys.stderr)
65
66    if options.mount != '/':
67        mountpoint = options.mount.rstrip('/')
68        if not mountpoint.startswith('/'):
69            parser.error('mount point has to start with a slash.')
70        app = DispatcherMiddleware(_make_root_app(mountpoint), {
71            mountpoint: app
72        })
73
74    run_simple(options.hostname, options.port, app, threaded=options.threaded,
75               use_reloader=options.reloader, use_debugger=options.debugger)
76
77
78if __name__ == '__main__':
79    main()
Note: See TracBrowser for help on using the repository browser.