annotate MoinMoin/server/__init__.py @ 3105:80e1a910a2f1

make logging more configurable and flexible, packages/modules shall call MoinMoin.server.getLogger
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sat, 23 Feb 2008 21:43:47 +0100
parents a78bf6977df8
children c6e39279f83b
rev   line source
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1 # -*- coding: iso-8859-1 -*-
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
2 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
3 MoinMoin server package
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
4
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
5 Supply common server utilities.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
6
1918
bb2e053067fb fixing copyright headers: remove umlauts (encoding troubles), make epydoc compatible, reformat
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1585
diff changeset
7 @copyright: 2004 Nir Soffer
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
8 @license: GNU GPL, see COPYING for details.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
9 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
10
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
11 import os
3105
80e1a910a2f1 make logging more configurable and flexible, packages/modules shall call MoinMoin.server.getLogger
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3102
diff changeset
12 from StringIO import StringIO
1585
a843bc5793fb introduce stdlib's logging module
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1584
diff changeset
13
1582
f37b49b6313d url_prefix_static: move default to MoinMoin.config, use matching defaults for Twisted/standalone
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 988
diff changeset
14 from MoinMoin import config
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
15
3105
80e1a910a2f1 make logging more configurable and flexible, packages/modules shall call MoinMoin.server.getLogger
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3102
diff changeset
16 import logging as _logging
80e1a910a2f1 make logging more configurable and flexible, packages/modules shall call MoinMoin.server.getLogger
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3102
diff changeset
17
80e1a910a2f1 make logging more configurable and flexible, packages/modules shall call MoinMoin.server.getLogger
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3102
diff changeset
18 def configureLogging(conf, defaults):
80e1a910a2f1 make logging more configurable and flexible, packages/modules shall call MoinMoin.server.getLogger
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3102
diff changeset
19 from logging.config import fileConfig
80e1a910a2f1 make logging more configurable and flexible, packages/modules shall call MoinMoin.server.getLogger
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3102
diff changeset
20 fileConfig(StringIO(conf), defaults)
80e1a910a2f1 make logging more configurable and flexible, packages/modules shall call MoinMoin.server.getLogger
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3102
diff changeset
21
80e1a910a2f1 make logging more configurable and flexible, packages/modules shall call MoinMoin.server.getLogger
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3102
diff changeset
22 def getLogger(name):
80e1a910a2f1 make logging more configurable and flexible, packages/modules shall call MoinMoin.server.getLogger
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3102
diff changeset
23 logger = _logging.getLogger(name)
80e1a910a2f1 make logging more configurable and flexible, packages/modules shall call MoinMoin.server.getLogger
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3102
diff changeset
24 for levelnumber, levelname in _logging._levelNames.items():
80e1a910a2f1 make logging more configurable and flexible, packages/modules shall call MoinMoin.server.getLogger
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3102
diff changeset
25 if isinstance(levelnumber, int): # that list has also the reverse mapping...
80e1a910a2f1 make logging more configurable and flexible, packages/modules shall call MoinMoin.server.getLogger
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3102
diff changeset
26 setattr(logger, levelname, levelnumber)
80e1a910a2f1 make logging more configurable and flexible, packages/modules shall call MoinMoin.server.getLogger
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3102
diff changeset
27 return logger
80e1a910a2f1 make logging more configurable and flexible, packages/modules shall call MoinMoin.server.getLogger
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3102
diff changeset
28
80e1a910a2f1 make logging more configurable and flexible, packages/modules shall call MoinMoin.server.getLogger
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3102
diff changeset
29 logging = getLogger('')
80e1a910a2f1 make logging more configurable and flexible, packages/modules shall call MoinMoin.server.getLogger
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3102
diff changeset
30
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
31 def switchUID(uid, gid):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
32 """ Switch identity to safe user and group
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
33
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
34 Does not support Windows, because the necessary calls are not available.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
35 TODO: can we use win32api calls to achieve the same effect on Windows?
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
36
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
37 Raise RuntimeError if can't switch or trying to switch to root.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
38 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
39 if uid == 0 or gid == 0:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
40 # We will not run as root. If you like to run a web
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
41 # server as root, then hack this code.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
42 raise RuntimeError('will not run as root!')
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
43
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
44 try:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
45 os.setgid(gid)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
46 os.setuid(uid)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
47 except (OSError, AttributeError):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
48 # Either we can't switch, or we are on windows, which does not have
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
49 # those calls.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
50 raise RuntimeError("can't change uid/gid to %s/%s" %
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
51 (uid, gid))
1585
a843bc5793fb introduce stdlib's logging module
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1584
diff changeset
52 logging.info("Running as uid/gid %d/%d" % (uid, gid))
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
53
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
54
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
55 class Config:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
56 """ Base class for server configuration
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
57
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
58 When you create a server, you should run it with a Config
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
59 instance. Sub class to define the default values.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
60
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
61 This class does all error checking needed for config values, and will
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
62 raise a RuntimeError on any fatal error.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
63 """
1582
f37b49b6313d url_prefix_static: move default to MoinMoin.config, use matching defaults for Twisted/standalone
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 988
diff changeset
64 # some defaults that should be common for all servers:
f37b49b6313d url_prefix_static: move default to MoinMoin.config, use matching defaults for Twisted/standalone
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 988
diff changeset
65 url_prefix_static = config.url_prefix_static
1584
1a1d6e0fe14f make moin.cgi work similar to the standalone/Twisted start scripts
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1582
diff changeset
66 docs = None # document root (if supported)
1a1d6e0fe14f make moin.cgi work similar to the standalone/Twisted start scripts
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1582
diff changeset
67 user = None # user we shall use for running (if supported)
1a1d6e0fe14f make moin.cgi work similar to the standalone/Twisted start scripts
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1582
diff changeset
68 group = None # group ...
1a1d6e0fe14f make moin.cgi work similar to the standalone/Twisted start scripts
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1582
diff changeset
69 port = None # tcp port number (if supported)
988
65dc979761f0 whitespace only and style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 0
diff changeset
70
3105
80e1a910a2f1 make logging more configurable and flexible, packages/modules shall call MoinMoin.server.getLogger
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3102
diff changeset
71 # Here you can configure the default logging used when running moin,
80e1a910a2f1 make logging more configurable and flexible, packages/modules shall call MoinMoin.server.getLogger
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3102
diff changeset
72 # see http://www.python.org/doc/lib/logging-config-fileformat.html
80e1a910a2f1 make logging more configurable and flexible, packages/modules shall call MoinMoin.server.getLogger
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3102
diff changeset
73 # We just use moin.log in current directory by default, if you want
80e1a910a2f1 make logging more configurable and flexible, packages/modules shall call MoinMoin.server.getLogger
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3102
diff changeset
74 # anything else, override logging_conf in your server script's Config class.
80e1a910a2f1 make logging more configurable and flexible, packages/modules shall call MoinMoin.server.getLogger
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3102
diff changeset
75 logging_defaults = {
80e1a910a2f1 make logging more configurable and flexible, packages/modules shall call MoinMoin.server.getLogger
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3102
diff changeset
76 'logdir': '.',
80e1a910a2f1 make logging more configurable and flexible, packages/modules shall call MoinMoin.server.getLogger
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3102
diff changeset
77 'loglevel': 'DEBUG',
80e1a910a2f1 make logging more configurable and flexible, packages/modules shall call MoinMoin.server.getLogger
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3102
diff changeset
78 }
80e1a910a2f1 make logging more configurable and flexible, packages/modules shall call MoinMoin.server.getLogger
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3102
diff changeset
79 logging_config = """\
80e1a910a2f1 make logging more configurable and flexible, packages/modules shall call MoinMoin.server.getLogger
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3102
diff changeset
80 [loggers]
80e1a910a2f1 make logging more configurable and flexible, packages/modules shall call MoinMoin.server.getLogger
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3102
diff changeset
81 keys=root
80e1a910a2f1 make logging more configurable and flexible, packages/modules shall call MoinMoin.server.getLogger
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3102
diff changeset
82
80e1a910a2f1 make logging more configurable and flexible, packages/modules shall call MoinMoin.server.getLogger
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3102
diff changeset
83 [handlers]
80e1a910a2f1 make logging more configurable and flexible, packages/modules shall call MoinMoin.server.getLogger
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3102
diff changeset
84 keys=logfile
80e1a910a2f1 make logging more configurable and flexible, packages/modules shall call MoinMoin.server.getLogger
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3102
diff changeset
85
80e1a910a2f1 make logging more configurable and flexible, packages/modules shall call MoinMoin.server.getLogger
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3102
diff changeset
86 [formatters]
80e1a910a2f1 make logging more configurable and flexible, packages/modules shall call MoinMoin.server.getLogger
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3102
diff changeset
87 keys=logfile
80e1a910a2f1 make logging more configurable and flexible, packages/modules shall call MoinMoin.server.getLogger
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3102
diff changeset
88
80e1a910a2f1 make logging more configurable and flexible, packages/modules shall call MoinMoin.server.getLogger
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3102
diff changeset
89 [logger_root]
80e1a910a2f1 make logging more configurable and flexible, packages/modules shall call MoinMoin.server.getLogger
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3102
diff changeset
90 level=%(loglevel)s
80e1a910a2f1 make logging more configurable and flexible, packages/modules shall call MoinMoin.server.getLogger
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3102
diff changeset
91 handlers=logfile
80e1a910a2f1 make logging more configurable and flexible, packages/modules shall call MoinMoin.server.getLogger
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3102
diff changeset
92
80e1a910a2f1 make logging more configurable and flexible, packages/modules shall call MoinMoin.server.getLogger
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3102
diff changeset
93 [handler_logfile]
80e1a910a2f1 make logging more configurable and flexible, packages/modules shall call MoinMoin.server.getLogger
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3102
diff changeset
94 class=StreamHandler
80e1a910a2f1 make logging more configurable and flexible, packages/modules shall call MoinMoin.server.getLogger
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3102
diff changeset
95 level=NOTSET
80e1a910a2f1 make logging more configurable and flexible, packages/modules shall call MoinMoin.server.getLogger
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3102
diff changeset
96 formatter=logfile
80e1a910a2f1 make logging more configurable and flexible, packages/modules shall call MoinMoin.server.getLogger
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3102
diff changeset
97 args=('%(logdir)s/moin.log', 'at')
80e1a910a2f1 make logging more configurable and flexible, packages/modules shall call MoinMoin.server.getLogger
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3102
diff changeset
98
80e1a910a2f1 make logging more configurable and flexible, packages/modules shall call MoinMoin.server.getLogger
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3102
diff changeset
99 [formatter_logfile]
80e1a910a2f1 make logging more configurable and flexible, packages/modules shall call MoinMoin.server.getLogger
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3102
diff changeset
100 format=%(asctime)s %(name)s %(levelname)s %(message)s
80e1a910a2f1 make logging more configurable and flexible, packages/modules shall call MoinMoin.server.getLogger
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3102
diff changeset
101 datefmt=
80e1a910a2f1 make logging more configurable and flexible, packages/modules shall call MoinMoin.server.getLogger
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3102
diff changeset
102 class=logging.Formatter
80e1a910a2f1 make logging more configurable and flexible, packages/modules shall call MoinMoin.server.getLogger
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3102
diff changeset
103 """
1585
a843bc5793fb introduce stdlib's logging module
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1584
diff changeset
104
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
105 def __init__(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
106 """ Validate and post process configuration values
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
107
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
108 Will raise RuntimeError for any wrong config value.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
109 """
1585
a843bc5793fb introduce stdlib's logging module
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1584
diff changeset
110 # First, initialize the logging
3105
80e1a910a2f1 make logging more configurable and flexible, packages/modules shall call MoinMoin.server.getLogger
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3102
diff changeset
111 configureLogging(self.logging_config, self.logging_defaults)
1585
a843bc5793fb introduce stdlib's logging module
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1584
diff changeset
112
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
113 # Check that docs path is accessible
1584
1a1d6e0fe14f make moin.cgi work similar to the standalone/Twisted start scripts
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1582
diff changeset
114 if self.docs:
1a1d6e0fe14f make moin.cgi work similar to the standalone/Twisted start scripts
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1582
diff changeset
115 self.docs = os.path.normpath(os.path.abspath(self.docs))
1a1d6e0fe14f make moin.cgi work similar to the standalone/Twisted start scripts
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1582
diff changeset
116 if not os.access(self.docs, os.F_OK | os.R_OK | os.X_OK):
1a1d6e0fe14f make moin.cgi work similar to the standalone/Twisted start scripts
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1582
diff changeset
117 raise RuntimeError("Can't access docs directory '%s'. Check docs "
1a1d6e0fe14f make moin.cgi work similar to the standalone/Twisted start scripts
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1582
diff changeset
118 "setting and permissions." % self.docs)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
119
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
120 # Don't check uid and gid on windows, those calls are not available.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
121 if os.name == 'nt':
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
122 self.uid = self.gid = 0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
123 return
988
65dc979761f0 whitespace only and style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 0
diff changeset
124
1584
1a1d6e0fe14f make moin.cgi work similar to the standalone/Twisted start scripts
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1582
diff changeset
125 self.uid = os.getuid()
1a1d6e0fe14f make moin.cgi work similar to the standalone/Twisted start scripts
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1582
diff changeset
126 self.gid = os.getgid()
1a1d6e0fe14f make moin.cgi work similar to the standalone/Twisted start scripts
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1582
diff changeset
127
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
128 # If serving privileged port, we must run as root to bind the port.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
129 # we will give up root privileges later
1584
1a1d6e0fe14f make moin.cgi work similar to the standalone/Twisted start scripts
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1582
diff changeset
130 if self.port and self.port < 1024 and self.uid != 0:
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
131 raise RuntimeError('Must run as root to serve port number under 1024. '
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
132 'Run as root or change port setting.')
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
133
1584
1a1d6e0fe14f make moin.cgi work similar to the standalone/Twisted start scripts
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1582
diff changeset
134 if self.user and self.group and self.uid == 0:
1a1d6e0fe14f make moin.cgi work similar to the standalone/Twisted start scripts
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1582
diff changeset
135 # If we run as root to serve privileged port, we change user and group
1a1d6e0fe14f make moin.cgi work similar to the standalone/Twisted start scripts
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1582
diff changeset
136 # to a safe setting. Get the uid and gid now, switch later.
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
137 import pwd, grp
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
138 try:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
139 self.uid = pwd.getpwnam(self.user)[2]
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
140 except KeyError:
1584
1a1d6e0fe14f make moin.cgi work similar to the standalone/Twisted start scripts
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1582
diff changeset
141 raise RuntimeError("Unknown user: '%s', check user setting" % self.user)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
142 try:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
143 self.gid = grp.getgrnam(self.group)[2]
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
144 except KeyError:
1584
1a1d6e0fe14f make moin.cgi work similar to the standalone/Twisted start scripts
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1582
diff changeset
145 raise RuntimeError("Unknown group: '%s', check group setting" % self.group)
988
65dc979761f0 whitespace only and style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 0
diff changeset
146