annotate MoinMoin/server/__init__.py @ 3107:c6e39279f83b

refactor logging usage
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sat, 23 Feb 2008 22:59:30 +0100
parents 80e1a910a2f1
children 4cd113328476
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):
3107
c6e39279f83b refactor logging usage
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3105
diff changeset
23 # do we want to strip MoinMoin. from the name?
c6e39279f83b refactor logging usage
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3105
diff changeset
24 #if name.startswith('MoinMoin.'):
c6e39279f83b refactor logging usage
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3105
diff changeset
25 # name = name[9:]
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
26 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
27 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
28 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
29 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
30 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
31
3107
c6e39279f83b refactor logging usage
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3105
diff changeset
32 logging = getLogger(__name__)
c6e39279f83b refactor logging usage
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3105
diff changeset
33
c6e39279f83b refactor logging usage
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3105
diff changeset
34 # use this to temporarily and selectively enable debug logging for this module
c6e39279f83b refactor logging usage
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3105
diff changeset
35 #logging.setLevel(logging.DEBUG)
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
36
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
37 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
38 """ 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
39
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
40 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
41 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
42
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
43 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
44 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
45 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
46 # 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
47 # 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
48 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
49
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
50 try:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
51 os.setgid(gid)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
52 os.setuid(uid)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
53 except (OSError, AttributeError):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
54 # 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
55 # those calls.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
56 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
57 (uid, gid))
1585
a843bc5793fb introduce stdlib's logging module
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1584
diff changeset
58 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
59
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 class Config:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
62 """ 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
63
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
64 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
65 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
66
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
67 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
68 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
69 """
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
70 # 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
71 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
72 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
73 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
74 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
75 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
76
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
77 # 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
78 # 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
79 # 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
80 # 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
81 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
82 '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
83 '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
84 }
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 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
86 [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
87 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
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 [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
90 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
91
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 [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
93 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
94
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 [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
96 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
97 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
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 [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
100 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
101 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
102 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
103 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
104
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
105 [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
106 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
107 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
108 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
109 """
1585
a843bc5793fb introduce stdlib's logging module
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1584
diff changeset
110
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
111 def __init__(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
112 """ 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
113
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
114 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
115 """
1585
a843bc5793fb introduce stdlib's logging module
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1584
diff changeset
116 # 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
117 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
118
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
119 # 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
120 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
121 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
122 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
123 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
124 "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
125
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
126 # 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
127 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
128 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
129 return
988
65dc979761f0 whitespace only and style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 0
diff changeset
130
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
131 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
132 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
133
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
134 # 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
135 # 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
136 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
137 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
138 '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
139
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
140 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
141 # 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
142 # 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
143 import pwd, grp
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
144 try:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
145 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
146 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
147 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
148 try:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
149 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
150 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
151 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
152