annotate MoinMoin/web/frontend.py @ 6076:f4ec84967c27

add colon to make log_attempt even more parseable
author 'Karl O. Pinc' <kop@meme.com>
date Mon, 15 Sep 2014 22:10:45 -0500
parents b95d34820bc8
children
rev   line source
4270
ab601d804f26 Factor out common frontend code
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
1 # -*- coding: iso-8859-1 -*-
ab601d804f26 Factor out common frontend code
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
2 """
ab601d804f26 Factor out common frontend code
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
3 MoinMoin - Common code for frontends (CGI/FCGI/SCGI)
ab601d804f26 Factor out common frontend code
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
4
ab601d804f26 Factor out common frontend code
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
5 @copyright: 2008 MoinMoin:FlorianKrupicka
ab601d804f26 Factor out common frontend code
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
6 @license: GNU GPL, see COPYING for details.
ab601d804f26 Factor out common frontend code
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
7 """
ab601d804f26 Factor out common frontend code
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
8 import optparse
ab601d804f26 Factor out common frontend code
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
9
ab601d804f26 Factor out common frontend code
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
10 from MoinMoin.web.serving import make_application
4525
b29b90a71625 revert (wrong) frontend related changesets (see below for details)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4520
diff changeset
11
4270
ab601d804f26 Factor out common frontend code
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
12 from MoinMoin import log
ab601d804f26 Factor out common frontend code
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
13 logging = log.getLogger(__name__)
ab601d804f26 Factor out common frontend code
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
14
ab601d804f26 Factor out common frontend code
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
15 class FrontEnd(object):
ab601d804f26 Factor out common frontend code
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
16 def __init__(self):
ab601d804f26 Factor out common frontend code
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
17 self.parser = optparse.OptionParser()
ab601d804f26 Factor out common frontend code
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
18 self.add_options()
ab601d804f26 Factor out common frontend code
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
19
ab601d804f26 Factor out common frontend code
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
20 def add_options(self):
ab601d804f26 Factor out common frontend code
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
21 parser = self.parser
4653
4d01cd04af70 support --debug=off/external/web or MOIN_DEBUGGER for flup frontend, default to off
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4613
diff changeset
22 parser.add_option("-d", "--debug", dest="debug",
4d01cd04af70 support --debug=off/external/web or MOIN_DEBUGGER for flup frontend, default to off
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4613
diff changeset
23 help="Debug mode of server (off/web/external, default is to use MOIN_DEBUGGER env var)")
4270
ab601d804f26 Factor out common frontend code
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
24 parser.add_option("-c", "--config-dir", dest="config_dir", metavar="DIR",
ab601d804f26 Factor out common frontend code
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
25 help=("Path to the directory containing the wiki "
ab601d804f26 Factor out common frontend code
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
26 "configuration files. Default: current directory"))
ab601d804f26 Factor out common frontend code
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
27 parser.add_option("--htdocs", dest="htdocs",
ab601d804f26 Factor out common frontend code
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
28 help=("Path to the directory containing Moin's "
4613
e7f1cf9eeb96 Static file serving built-in (see details below).
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4611
diff changeset
29 "static files. Default: use builtin MoinMoin/web/static/htdocs"))
e7f1cf9eeb96 Static file serving built-in (see details below).
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4611
diff changeset
30 parser.set_default('htdocs', True)
4270
ab601d804f26 Factor out common frontend code
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
31
ab601d804f26 Factor out common frontend code
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
32 def run(self, args=None):
ab601d804f26 Factor out common frontend code
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
33 options, args = self.parser.parse_args(args)
ab601d804f26 Factor out common frontend code
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
34 logging.debug('Options: %r', options)
ab601d804f26 Factor out common frontend code
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
35
4611
c6e4ccbbb1b3 simplified shared/htdocs processing
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4532
diff changeset
36 application = make_application(shared=options.htdocs)
4525
b29b90a71625 revert (wrong) frontend related changesets (see below for details)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4520
diff changeset
37
4270
ab601d804f26 Factor out common frontend code
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
38 try:
4525
b29b90a71625 revert (wrong) frontend related changesets (see below for details)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4520
diff changeset
39 self.run_server(application, options)
4526
1d06e13ce1ee web.frontend: the flup CGIRequest uses sys.exit(0) to terminate so we should not run into an exception by that.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 4525
diff changeset
40 except SystemExit, err:
1d06e13ce1ee web.frontend: the flup CGIRequest uses sys.exit(0) to terminate so we should not run into an exception by that.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 4525
diff changeset
41 # the flup CGIRequest uses sys.exit(0) to terminate
1d06e13ce1ee web.frontend: the flup CGIRequest uses sys.exit(0) to terminate so we should not run into an exception by that.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 4525
diff changeset
42 if err.code: # log a non-zero exit status (0 means no error)
1d06e13ce1ee web.frontend: the flup CGIRequest uses sys.exit(0) to terminate so we should not run into an exception by that.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 4525
diff changeset
43 logging.exception('A SystemExit(%d) exception occurred.' % err.code)
1d06e13ce1ee web.frontend: the flup CGIRequest uses sys.exit(0) to terminate so we should not run into an exception by that.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 4525
diff changeset
44 raise # exit now with this exit status
4270
ab601d804f26 Factor out common frontend code
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
45 except:
4526
1d06e13ce1ee web.frontend: the flup CGIRequest uses sys.exit(0) to terminate so we should not run into an exception by that.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 4525
diff changeset
46 logging.exception('An exception occurred while running %s' % self.__class__.__name__)
4270
ab601d804f26 Factor out common frontend code
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
47
ab601d804f26 Factor out common frontend code
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
48 class ServerFrontEnd(FrontEnd):
ab601d804f26 Factor out common frontend code
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
49 def add_options(self):
ab601d804f26 Factor out common frontend code
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
50 super(ServerFrontEnd, self).add_options()
ab601d804f26 Factor out common frontend code
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
51 parser = self.parser
ab601d804f26 Factor out common frontend code
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
52 parser.add_option("-p", "--port", dest="port", type="int",
5378
b95d34820bc8 flup_frontend: fix wrapper class init to work for scgi and ajp (details below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4653
diff changeset
53 help="Set the port to listen on.")
4270
ab601d804f26 Factor out common frontend code
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
54 parser.add_option("-i", "--interface", dest="interface",
ab601d804f26 Factor out common frontend code
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
55 help=("Set the interface/socket to listen on. If starts "
ab601d804f26 Factor out common frontend code
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
56 "with '/' or './' it is interpreted as a path "
5378
b95d34820bc8 flup_frontend: fix wrapper class init to work for scgi and ajp (details below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4653
diff changeset
57 "to a unix socket."))
4532
65c0426f2b1f flup cgi/fcgi adaptor: use None as interface default
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4526
diff changeset
58 # Note: interface default MUST be None, do not set it to something else!
65c0426f2b1f flup cgi/fcgi adaptor: use None as interface default
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4526
diff changeset
59 # Otherwise CGI (and also when the FCGI process is spawned by the web server) won't work.
4287
d1be5f6846ca Aggregated flup-based servers into single file and added server-type config (threaded/forked/single)
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4270
diff changeset
60
4289
f4b16fe11eaf Added several checks for availablity/features of flup
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4287
diff changeset
61 class FrontEndNotAvailable(Exception):
f4b16fe11eaf Added several checks for availablity/features of flup
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4287
diff changeset
62 """ Raised if a frontend is not available for one reason or another. """
4517
47eee6dfcdec web.frontend: syntactically pass statement added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 4289
diff changeset
63 pass