annotate MoinMoin/web/frontend.py @ 4270:ab601d804f26

Factor out common frontend code
author Florian Krupicka <florian.krupicka@googlemail.com>
date Wed, 06 Aug 2008 23:21:31 +0200
parents
children d1be5f6846ca
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
ab601d804f26 Factor out common frontend code
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
11
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
ab601d804f26 Factor out common frontend code
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
22 parser.add_option("-d", "--debug", action="store_true",
ab601d804f26 Factor out common frontend code
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
23 help="Enable debug mode of server (show tracebacks)")
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 "
ab601d804f26 Factor out common frontend code
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
29 "static files. Default: /usr/share/moin/htdocs"))
ab601d804f26 Factor out common frontend code
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
30 parser.set_default('htdocs', '/usr/share/moin/htdocs')
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
ab601d804f26 Factor out common frontend code
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
36 if options.htdocs:
ab601d804f26 Factor out common frontend code
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
37 application = make_application(shared=options.htdocs)
ab601d804f26 Factor out common frontend code
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
38 else:
ab601d804f26 Factor out common frontend code
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
39 application = make_application()
ab601d804f26 Factor out common frontend code
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
40
ab601d804f26 Factor out common frontend code
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
41 try:
ab601d804f26 Factor out common frontend code
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
42 self.run_server(application, options)
ab601d804f26 Factor out common frontend code
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
43 except:
ab601d804f26 Factor out common frontend code
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
44 logging.error('Error while running %s', self.__class__.__name__)
ab601d804f26 Factor out common frontend code
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
45 raise
ab601d804f26 Factor out common frontend code
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
46
ab601d804f26 Factor out common frontend code
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
47 class ServerFrontEnd(FrontEnd):
ab601d804f26 Factor out common frontend code
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
48 def add_options(self):
ab601d804f26 Factor out common frontend code
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
49 super(ServerFrontEnd, self).add_options()
ab601d804f26 Factor out common frontend code
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
50 parser = self.parser
ab601d804f26 Factor out common frontend code
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
51 parser.add_option("-p", "--port", dest="port", type="int",
ab601d804f26 Factor out common frontend code
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
52 help="Set the port to listen on. Act as CGI/FCGI script otherwise")
ab601d804f26 Factor out common frontend code
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
53 parser.add_option("-i", "--interface", dest="interface",
ab601d804f26 Factor out common frontend code
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
54 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
55 "with '/' or './' it is interpreted as a path "
ab601d804f26 Factor out common frontend code
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
56 "to a unix socket. Default: localhost"))
ab601d804f26 Factor out common frontend code
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
57 parser.set_default('interface', 'localhost')