1 # Copyright (C) 2006-2008 by the Free Software Foundation, Inc.
3 # This file is part of GNU Mailman.
5 # GNU Mailman is free software: you can redistribute it and/or modify it under
6 # the terms of the GNU General Public License as published by the Free
7 # Software Foundation, either version 3 of the License, or (at your option)
10 # GNU Mailman is distributed in the hope that it will be useful, but WITHOUT
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 # You should have received a copy of the GNU General Public License along with
16 # GNU Mailman. If not, see <http://www.gnu.org/licenses/>.
18 """Initialize all global state.
20 Every entrance into the Mailman system, be it by command line, mail program,
21 or cgi, must call the initialize function here in order for the system's
22 global state to be set up properly. Typically this is called after command
23 line argument parsing, since some of the initialization behavior is controlled
24 by the command line arguments.
29 from zope
.interface
.interface
import adapter_hooks
30 from zope
.interface
.verify
import verifyObject
32 import mailman
.config
.config
33 import mailman
.core
.logging
35 from mailman
.core
.plugins
import get_plugin
36 from mailman
.interfaces
import IDatabase
40 # These initialization calls are separated for the testing framework, which
41 # needs to do some internal calculations after config file loading and log
42 # initialization, but before database initialization. Generally all other
43 # code will just call initialize().
45 def initialize_1(config_path
, propagate_logs
):
46 """First initialization step.
48 * The configuration system
49 * Run-time directories
50 * The logging subsystem
52 :param config_path: The path to the configuration file.
53 :type config_path: string
54 :param propagate_logs: Should the log output propagate to stderr?
55 :type propagate_logs: boolean
57 # By default, set the umask so that only owner and group can read and
58 # write our files. Specifically we must have g+rw and we probably want
59 # o-rwx although I think in most cases it doesn't hurt if other can read
60 # or write the files. Note that the Pipermail archive has more
61 # restrictive permissions in order to handle private archives, but it
62 # handles that correctly.
64 mailman
.config
.config
.load(config_path
)
65 # Create the queue and log directories if they don't already exist.
66 mailman
.config
.config
.ensure_directories_exist()
67 mailman
.core
.logging
.initialize(propagate_logs
)
70 def initialize_2(debug
=False):
71 """Second initialization step.
79 :param debug: Should the database layer be put in debug mode?
82 database_plugin
= get_plugin('mailman.database')
83 # Instantiate the database plugin, ensure that it's of the right type, and
84 # initialize it. Then stash the object on our configuration object.
85 database
= database_plugin()
86 verifyObject(IDatabase
, database
)
87 database
.initialize(debug
)
88 mailman
.config
.config
.db
= database
89 # Initialize the rules and chains. Do the imports here so as to avoid
91 from mailman
.app
.commands
import initialize
as initialize_commands
92 from mailman
.archiving
import initialize
as initialize_archivers
93 from mailman
.core
.chains
import initialize
as initialize_chains
94 from mailman
.core
.pipelines
import initialize
as initialize_pipelines
95 from mailman
.core
.rules
import initialize
as initialize_rules
96 # Order here is somewhat important.
97 initialize_archivers()
100 initialize_pipelines()
101 initialize_commands()
105 """Third initialization step.
109 from mailman
.app
.registrar
import adapt_domain_to_registrar
110 adapter_hooks
.append(adapt_domain_to_registrar
)
114 def initialize(config_path
=None, propagate_logs
=False):
115 initialize_1(config_path
, propagate_logs
)