~azzar1/unity/add-show-desktop-key

1092.1.46 by Matt Giuca
setup: Removed 'config' mode. It's now standalone.
1
#!/usr/bin/python
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
2
# IVLE - Informatics Virtual Learning Environment
1092.1.1 by William Grant
[Uber-commit of holiday work because I lacked a local copy of the branch.]
3
# Copyright (C) 2007-2009 The University of Melbourne
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
4
#
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 2 of the License, or
8
# (at your option) any later version.
9
#
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, write to the Free Software
17
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
19
# Author: Matt Giuca, Refactored by David Coles
20
1092.1.1 by William Grant
[Uber-commit of holiday work because I lacked a local copy of the branch.]
21
'''Configures IVLE with machine-specific details, most notably, various paths.
22
Either prompts the administrator for these details or accepts them as
23
command-line args.
24
1092.1.51 by William Grant
Move trampoline UID configuration out of config.
25
Creates etc/ivle.conf
1092.1.1 by William Grant
[Uber-commit of holiday work because I lacked a local copy of the branch.]
26
'''
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
27
28
import optparse
29
import getopt
30
import os
819 by mattgiuca
setup/configure.py: Added "import sys".
31
import sys
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
32
import hashlib
33
import uuid
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
34
1092.1.34 by Matt Giuca
setup.configure: Replaced use of legacy conf.py for loading existing values.
35
import ivle.config
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
36
1092.1.11 by Matt Giuca
Replaced Python config files (conf.py) with new config files system, using
37
import configobj
38
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
39
class ConfigOption:
40
    """A configuration option; one of the things written to conf.py."""
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
41
    def __init__(self, option_name, default, prompt, comment, ask=True):
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
42
        """Creates a configuration option.
43
        option_name: Name of the variable in conf.py. Also name of the
44
            command-line argument to setup.py conf.
45
        default: Default value for this variable.
46
        prompt: (Short) string presented during the interactive prompt in
47
            setup.py conf.
48
        comment: (Long) comment string stored in conf.py. Each line of this
49
            string should begin with a '#'.
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
50
        ask: Whether to ask the question in the default config run.
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
51
        """
52
        self.option_name = option_name
53
        self.default = default
54
        self.prompt = prompt
55
        self.comment = comment
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
56
        self.ask = ask
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
57
58
# Configuration options, defaults and descriptions
59
config_options = []
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
60
1092.1.33 by Matt Giuca
setup.configure: Replaced all of the config option names with the new path
61
config_options.append(ConfigOption("urls/root", "/",
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
62
    """Root directory where IVLE is located (in URL space):""",
63
    """
64
# In URL space, where in the site is IVLE located. (All URLs will be prefixed
65
# with this).
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
66
# eg. "/" or "/ivle".""", ask=False))
67
1092.1.33 by Matt Giuca
setup.configure: Replaced all of the config option names with the new path
68
config_options.append(ConfigOption("paths/prefix", "/usr/local",
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
69
    """In the local file system, the prefix to the system directory where IVLE
70
is installed. (This should either be /usr or /usr/local):""",
71
    """
72
# In the local file system, the prefix to the system directory where IVLE is
73
# installed. This should either be '/usr' or '/usr/local'.
74
# ('/usr/local' for the usual install, '/usr' for distribution packages)""",
75
    ask=False))
76
1092.1.33 by Matt Giuca
setup.configure: Replaced all of the config option names with the new path
77
config_options.append(ConfigOption("paths/site_packages",
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
78
    None,
79
    """site-packages directory in Python, where Python libraries are to be
80
installed. May be left as the default, in which case the value will be
81
computed from prefix and the current Python version:""",
82
    """
83
# 'site-packages' directory in Python, where Python libraries are to be
1092.1.41 by Matt Giuca
setup.configure: Fixed "None" as the default - now writes nothing rather than
84
# installed. May be omitted (recommended), in which case the value will be
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
85
# computed from prefix and the current Python version.""", ask=False))
86
1092.1.33 by Matt Giuca
setup.configure: Replaced all of the config option names with the new path
87
config_options.append(ConfigOption("paths/data",
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
88
    "/var/lib/ivle",
89
    "In the local file system, where user-modifiable data files should be "
90
    "located:",
91
    """
92
# In the local file system, where user-modifiable data files should be
93
# located.""", ask=False))
94
1092.1.33 by Matt Giuca
setup.configure: Replaced all of the config option names with the new path
95
config_options.append(ConfigOption("paths/logs",
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
96
    "/var/log/ivle",
893 by dcoles
Dispatch: Now attempts to log unhandled exceptions to a log directory specified
97
    """Directory where IVLE log files are stored (on the local
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
98
file system). Note - this must be writable by the user the IVLE server 
99
process runs as (usually www-data):""",
893 by dcoles
Dispatch: Now attempts to log unhandled exceptions to a log directory specified
100
    """
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
101
# In the local file system, where IVLE error logs should be located.""",
102
    ask=False))
103
1092.1.33 by Matt Giuca
setup.configure: Replaced all of the config option names with the new path
104
config_options.append(ConfigOption("urls/public_host", "public.localhost",
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
105
    """Hostname which will cause the server to go into "public mode",
106
providing login-free access to student's published work:""",
107
    """
108
# The server goes into "public mode" if the browser sends a request with this
109
# host. This is for security reasons - we only serve public student files on a
110
# separate domain to the main IVLE site.
111
# Public mode does not use cookies, and serves only public content.
112
# Private mode (normal mode) requires login, and only serves files relevant to
113
# the logged-in user."""))
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
114
1092.1.33 by Matt Giuca
setup.configure: Replaced all of the config option names with the new path
115
config_options.append(ConfigOption("database/host", "localhost",
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
116
    """PostgreSQL Database config
117
==========================
118
Hostname of the DB server:""",
119
    """
120
# Database server hostname"""))
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
121
1092.1.33 by Matt Giuca
setup.configure: Replaced all of the config option names with the new path
122
config_options.append(ConfigOption("database/port", "5432",
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
123
    """Port of the DB server:""",
124
    """
125
# Database server port"""))
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
126
1092.1.33 by Matt Giuca
setup.configure: Replaced all of the config option names with the new path
127
config_options.append(ConfigOption("database/name", "ivle",
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
128
    """Database name:""",
129
    """
130
# Database name"""))
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
131
1092.1.33 by Matt Giuca
setup.configure: Replaced all of the config option names with the new path
132
config_options.append(ConfigOption("plugins/forum/dbname", "ivle_forum",
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
133
    """Forum Database name:""",
134
    """
135
# Forum Database name"""))
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
136
1092.1.33 by Matt Giuca
setup.configure: Replaced all of the config option names with the new path
137
config_options.append(ConfigOption("database/username", "postgres",
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
138
    """Username for DB server login:""",
139
    """
140
# Database username"""))
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
141
1092.1.33 by Matt Giuca
setup.configure: Replaced all of the config option names with the new path
142
config_options.append(ConfigOption("database/password", "",
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
143
    """Password for DB server login:
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
144
    (Caution: This password is stored in plaintext in ivle/conf/conf.py)""",
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
145
    """
146
# Database password"""))
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
147
1092.1.33 by Matt Giuca
setup.configure: Replaced all of the config option names with the new path
148
config_options.append(ConfigOption("auth/modules", "",
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
149
    """Authentication config
150
=====================
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
151
Comma-separated list of authentication modules.""",
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
152
    """
153
# Comma-separated list of authentication modules.
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
154
# Note that auth is always enabled against the local database, and NO OTHER
155
# auth is enabled by default. This section is for specifying additional auth
156
# modules.
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
157
# These refer to importable Python modules in the www/auth directory.
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
158
# Modules "ldap_auth" and "guest" are available in the source tree, but
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
159
# other modules may be plugged in to auth against organisation-specific
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
160
# auth backends.""", ask=False))
161
1092.1.33 by Matt Giuca
setup.configure: Replaced all of the config option names with the new path
162
config_options.append(ConfigOption("auth/ldap_url", "ldaps://www.example.com",
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
163
    """(LDAP options are only relevant if "ldap" is included in the list of
164
auth modules).
165
URL for LDAP authentication server:""",
166
    """
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
167
# URL for LDAP authentication server""", ask=False))
168
1092.1.33 by Matt Giuca
setup.configure: Replaced all of the config option names with the new path
169
config_options.append(ConfigOption("auth/ldap_format_string",
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
170
    "uid=%s,ou=users,o=example",
171
    """Format string for LDAP auth request:
172
    (Must contain a single "%s" for the user's login name)""",
173
    """
174
# Format string for LDAP auth request
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
175
# (Must contain a single "%s" for the user's login name)""", ask=False))
176
1092.1.33 by Matt Giuca
setup.configure: Replaced all of the config option names with the new path
177
config_options.append(ConfigOption("auth/subject_pulldown_modules", "",
819 by mattgiuca
setup/configure.py: Added "import sys".
178
    """Comma-separated list of subject pulldown modules.
179
Add proprietary modules to automatically enrol students in subjects.""",
180
    """
181
# Comma-separated list of subject pulldown modules.
182
# These refer to importable Python modules in the lib/pulldown_subj directory.
820 by mattgiuca
lib: Added new package pulldown_subj, a collection of modules designed to
183
# Only "dummy_subj" is available in the source tree (an example), but
819 by mattgiuca
setup/configure.py: Added "import sys".
184
# other modules may be plugged in to pulldown against organisation-specific
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
185
# pulldown backends.""", ask=False))
186
1092.1.33 by Matt Giuca
setup.configure: Replaced all of the config option names with the new path
187
config_options.append(ConfigOption("urls/svn_addr", "http://svn.localhost/",
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
188
    """Subversion config
189
=================
190
The base url for accessing subversion repositories:""",
191
    """
192
# The base url for accessing subversion repositories."""))
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
193
1092.1.33 by Matt Giuca
setup.configure: Replaced all of the config option names with the new path
194
config_options.append(ConfigOption("usrmgt/host", "localhost",
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
195
    """User Management Server config
196
============================
197
The hostname where the usrmgt-server runs:""",
198
    """
199
# The hostname where the usrmgt-server runs."""))
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
200
1092.1.33 by Matt Giuca
setup.configure: Replaced all of the config option names with the new path
201
config_options.append(ConfigOption("usrmgt/port", "2178",
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
202
    """The port where the usrmgt-server runs:""",
203
    """
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
204
# The port where the usrmgt-server runs.""", ask=False))
205
1092.1.33 by Matt Giuca
setup.configure: Replaced all of the config option names with the new path
206
config_options.append(ConfigOption("usrmgt/magic", None,
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
207
    """The password for the usrmgt-server:""",
208
    """
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
209
# The password for the usrmgt-server.""", ask=False))
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
210
1092.1.44 by Matt Giuca
setup.util: Moved query_user to setup.configure. (It's the only user of this
211
def query_user(default, prompt):
212
    """Prompts the user for a string, which is read from a line of stdin.
213
    Exits silently if EOF is encountered. Returns the string, with spaces
214
    removed from the beginning and end.
215
216
    Returns default if a 0-length line (after spaces removed) was read.
217
    """
218
    if default is None:
219
        # A default of None means the value will be computed specially, so we
220
        # can't really tell you what it is
221
        defaultstr = "computed"
222
    elif isinstance(default, basestring):
223
        defaultstr = '"%s"' % default
224
    else:
225
        defaultstr = repr(default)
226
    sys.stdout.write('%s\n    (default: %s)\n>' % (prompt, defaultstr))
227
    try:
228
        val = sys.stdin.readline()
229
    except KeyboardInterrupt:
230
        # Ctrl+C
231
        sys.stdout.write("\n")
232
        sys.exit(1)
233
    sys.stdout.write("\n")
234
    # If EOF, exit
235
    if val == '': sys.exit(1)
236
    # If empty line, return default
237
    val = val.strip()
238
    if val == '': return default
239
    return val
240
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
241
def configure(args):
242
    # Try importing existing conf, but if we can't just set up defaults
243
    # The reason for this is that these settings are used by other phases
244
    # of setup besides conf, so we need to know them.
245
    # Also this allows you to hit Return to accept the existing value.
1092.1.37 by Matt Giuca
setup.configure: Now handles the case of a missing config file.
246
    try:
247
        conf = ivle.config.Config()
248
    except ivle.config.ConfigError:
249
        # Couldn't find a config file anywhere.
250
        # Create a new blank config object (not yet bound to a file)
251
        # All lookups (below) will fail, so it will be initialised with all
252
        # the default values.
253
        conf = ivle.config.Config(blank=True)
254
1092.1.39 by Matt Giuca
setup.configure: Replaced the use of an intermediate dictionary for storing
255
    # Check that all the options are present, and if not, load the default
1092.1.34 by Matt Giuca
setup.configure: Replaced use of legacy conf.py for loading existing values.
256
    for opt in config_options:
257
        try:
1092.1.39 by Matt Giuca
setup.configure: Replaced the use of an intermediate dictionary for storing
258
            conf.get_by_path(opt.option_name)
1092.1.34 by Matt Giuca
setup.configure: Replaced use of legacy conf.py for loading existing values.
259
        except KeyError:
1092.1.41 by Matt Giuca
setup.configure: Fixed "None" as the default - now writes nothing rather than
260
            # If the default is None, omit it
261
            # Else ConfigObj will write the string 'None' to the conf file
262
            if opt.default is not None:
263
                conf.set_by_path(opt.option_name, opt.default)
1092.1.39 by Matt Giuca
setup.configure: Replaced the use of an intermediate dictionary for storing
264
265
    # Store comments in the conf object
266
    for opt in config_options:
1092.1.45 by Matt Giuca
setup.configure: Fixed bug if usrmgt_magic is None. Does not write comment if
267
        # Omitted if the key doesn't exist
1092.1.39 by Matt Giuca
setup.configure: Replaced the use of an intermediate dictionary for storing
268
        conf.set_by_path(opt.option_name, comment=opt.comment)
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
269
270
    # Set up some variables
271
    cwd = os.getcwd()
272
273
    # the files that will be created/overwritten
1092.1.11 by Matt Giuca
Replaced Python config files (conf.py) with new config files system, using
274
    conffile = os.path.join(cwd, "etc/ivle.conf")
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
275
    phpBBconffile = os.path.join(cwd, "www/php/phpBB3/config.php")
276
277
    # Get command-line arguments to avoid asking questions.
278
279
    optnames = []
280
    for opt in config_options:
281
        optnames.append(opt.option_name + "=")
282
    (opts, args) = getopt.gnu_getopt(args, "", optnames)
283
284
    if args != []:
285
        print >>sys.stderr, "Invalid arguments:", string.join(args, ' ')
286
        return 2
287
288
    if opts == []:
289
        # Interactive mode. Prompt the user for all the values.
290
291
        print """This tool will create the following files:
292
    %s
293
    %s
294
prompting you for details about your configuration. The file will be
295
overwritten if it already exists. It will *not* install or deploy IVLE.
296
297
Please hit Ctrl+C now if you do not wish to do this.
1092.1.51 by William Grant
Move trampoline UID configuration out of config.
298
""" % (conffile, phpBBconffile)
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
299
300
        # Get information from the administrator
301
        # If EOF is encountered at any time during the questioning, just exit
302
        # silently
303
304
        for opt in config_options:
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
305
            if opt.ask:
1092.1.39 by Matt Giuca
setup.configure: Replaced the use of an intermediate dictionary for storing
306
                conf.set_by_path(opt.option_name,
307
                    query_user(conf.get_by_path(opt.option_name), opt.prompt))
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
308
    else:
309
        opts = dict(opts)
310
        # Non-interactive mode. Parse the options.
311
        for opt in config_options:
312
            if '--' + opt.option_name in opts:
1092.1.39 by Matt Giuca
setup.configure: Replaced the use of an intermediate dictionary for storing
313
                conf.set_by_path(opt.option_name,
314
                                 opts['--' + opt.option_name])
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
315
316
    # Error handling on input values
317
    try:
1092.1.39 by Matt Giuca
setup.configure: Replaced the use of an intermediate dictionary for storing
318
        conf['database']['port'] = int(conf['database']['port'])
319
        if (conf['database']['port'] < 0
320
            or conf['database']['port'] >= 65536):
1092.1.30 by Matt Giuca
setup.configure: Replaced all uses of config-variable global variables with
321
            raise ValueError()
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
322
    except ValueError:
323
        print >>sys.stderr, (
324
        "Invalid DB port (%s).\n"
1092.1.32 by Matt Giuca
configure.py: Fixed missing reference to conf_options in error case.
325
        "Must be an integer between 0 and 65535." %
1092.1.39 by Matt Giuca
setup.configure: Replaced the use of an intermediate dictionary for storing
326
            repr(conf['database']['port']))
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
327
        return 1
328
    try:
1092.1.39 by Matt Giuca
setup.configure: Replaced the use of an intermediate dictionary for storing
329
        conf['usrmgt']['port'] = int(conf['usrmgt']['port'])
330
        if (conf['usrmgt']['port'] < 0 or conf['usrmgt']['port'] >= 65536):
1092.1.30 by Matt Giuca
setup.configure: Replaced all uses of config-variable global variables with
331
            raise ValueError()
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
332
    except ValueError:
333
        print >>sys.stderr, (
334
        "Invalid user management port (%s).\n"
1092.1.32 by Matt Giuca
configure.py: Fixed missing reference to conf_options in error case.
335
        "Must be an integer between 0 and 65535." %
1092.1.39 by Matt Giuca
setup.configure: Replaced the use of an intermediate dictionary for storing
336
            repr(conf['usrmgt']['port']))
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
337
        return 1
338
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
339
    # By default we generate the magic randomly.
1092.1.45 by Matt Giuca
setup.configure: Fixed bug if usrmgt_magic is None. Does not write comment if
340
    try:
341
        conf['usrmgt']['magic']     # Throw away; just check for KeyError
342
    except KeyError:
1092.1.39 by Matt Giuca
setup.configure: Replaced the use of an intermediate dictionary for storing
343
        conf['usrmgt']['magic'] = hashlib.md5(uuid.uuid4().bytes).hexdigest()
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
344
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
345
    # Generate the forum secret
346
    forum_secret = hashlib.md5(uuid.uuid4().bytes).hexdigest()
347
1092.1.37 by Matt Giuca
setup.configure: Now handles the case of a missing config file.
348
    # Write ./etc/ivle.conf (even if we loaded from a different filename)
1092.1.11 by Matt Giuca
Replaced Python config files (conf.py) with new config files system, using
349
    conf.filename = conffile
350
351
    conf.initial_comment = ["# IVLE Configuration File"]
352
1092.1.10 by Matt Giuca
setup/configure.py: Removed exception handling of IOErrors when writing conf.
353
    # Add the forum secret to the config file (regenerated each config)
1092.1.33 by Matt Giuca
setup.configure: Replaced all of the config option names with the new path
354
    config_options.append(ConfigOption('plugins/forum/secret', None, '', ''))
1092.1.39 by Matt Giuca
setup.configure: Replaced the use of an intermediate dictionary for storing
355
    conf['plugins']['forum']['secret'] = forum_secret
1092.1.11 by Matt Giuca
Replaced Python config files (conf.py) with new config files system, using
356
357
    conf.write()
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
358
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
359
    print "Successfully wrote %s" % conffile
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
360
361
    # Write www/php/phpBB3/config.php
362
1092.1.38 by Matt Giuca
setup.configure: There were a bunch of variables all called 'conf' which were
363
    conf_php = open(phpBBconffile, "w")
1092.1.10 by Matt Giuca
setup/configure.py: Removed exception handling of IOErrors when writing conf.
364
    
365
    # php-pg work around
1092.1.39 by Matt Giuca
setup.configure: Replaced the use of an intermediate dictionary for storing
366
    if conf['database']['host'] == 'localhost':
1092.1.10 by Matt Giuca
setup/configure.py: Removed exception handling of IOErrors when writing conf.
367
        forumdb_host = '127.0.0.1'
368
    else:
1092.1.39 by Matt Giuca
setup.configure: Replaced the use of an intermediate dictionary for storing
369
        forumdb_host = conf['database']['host']
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
370
1092.1.38 by Matt Giuca
setup.configure: There were a bunch of variables all called 'conf' which were
371
    conf_php.write( """<?php
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
372
// phpBB 3.0.x auto-generated configuration file
373
// Do not change anything in this file!
374
$dbms = 'postgres';
375
$dbhost = '""" + forumdb_host + """';
1092.1.39 by Matt Giuca
setup.configure: Replaced the use of an intermediate dictionary for storing
376
$dbport = '""" + str(conf['database']['port']) + """';
377
$dbname = '""" + conf['plugins']['forum']['dbname'] + """';
378
$dbuser = '""" + conf['database']['username'] + """';
379
$dbpasswd = '""" + conf['database']['password'] + """';
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
380
381
$table_prefix = 'phpbb_';
382
$acm_type = 'file';
383
$load_extensions = '';
384
@define('PHPBB_INSTALLED', true);
385
// @define('DEBUG', true);
386
//@define('DEBUG_EXTRA', true);
387
388
$forum_secret = '""" + forum_secret +"""';
389
?>"""   )
390
    
1092.1.38 by Matt Giuca
setup.configure: There were a bunch of variables all called 'conf' which were
391
    conf_php.close()
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
392
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
393
    print "Successfully wrote %s" % phpBBconffile
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
394
395
    print
396
    print "You may modify the configuration at any time by editing"
397
    print conffile
398
    print phpBBconffile
399
    print
400
    
401
    return 0
1092.1.46 by Matt Giuca
setup: Removed 'config' mode. It's now standalone.
402
403
def main(argv=None):
404
    if argv is None:
405
        argv = sys.argv
406
407
    # Print the opening spiel including the GPL notice
408
409
    print """IVLE - Informatics Virtual Learning Environment Setup
410
Copyright (C) 2007-2009 The University of Melbourne
411
IVLE comes with ABSOLUTELY NO WARRANTY.
412
This is free software, and you are welcome to redistribute it
413
under certain conditions. See LICENSE.txt for details.
414
415
IVLE Configuration
416
"""
417
418
    return configure(argv[1:])
419
420
if __name__ == "__main__":
421
    sys.exit(main())