comparison 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
comparison
equal deleted inserted replaced
4269:10ac3ad07faa 4270:ab601d804f26
1 # -*- coding: iso-8859-1 -*-
2 """
3 MoinMoin - Common code for frontends (CGI/FCGI/SCGI)
4
5 @copyright: 2008 MoinMoin:FlorianKrupicka
6 @license: GNU GPL, see COPYING for details.
7 """
8 import optparse
9
10 from MoinMoin.web.serving import make_application
11
12 from MoinMoin import log
13 logging = log.getLogger(__name__)
14
15 class FrontEnd(object):
16 def __init__(self):
17 self.parser = optparse.OptionParser()
18 self.add_options()
19
20 def add_options(self):
21 parser = self.parser
22 parser.add_option("-d", "--debug", action="store_true",
23 help="Enable debug mode of server (show tracebacks)")
24 parser.add_option("-c", "--config-dir", dest="config_dir", metavar="DIR",
25 help=("Path to the directory containing the wiki "
26 "configuration files. Default: current directory"))
27 parser.add_option("--htdocs", dest="htdocs",
28 help=("Path to the directory containing Moin's "
29 "static files. Default: /usr/share/moin/htdocs"))
30 parser.set_default('htdocs', '/usr/share/moin/htdocs')
31
32 def run(self, args=None):
33 options, args = self.parser.parse_args(args)
34 logging.debug('Options: %r', options)
35
36 if options.htdocs:
37 application = make_application(shared=options.htdocs)
38 else:
39 application = make_application()
40
41 try:
42 self.run_server(application, options)
43 except:
44 logging.error('Error while running %s', self.__class__.__name__)
45 raise
46
47 class ServerFrontEnd(FrontEnd):
48 def add_options(self):
49 super(ServerFrontEnd, self).add_options()
50 parser = self.parser
51 parser.add_option("-p", "--port", dest="port", type="int",
52 help="Set the port to listen on. Act as CGI/FCGI script otherwise")
53 parser.add_option("-i", "--interface", dest="interface",
54 help=("Set the interface/socket to listen on. If starts "
55 "with '/' or './' it is interpreted as a path "
56 "to a unix socket. Default: localhost"))
57 parser.set_default('interface', 'localhost')