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

« back to all changes in this revision

Viewing changes to setup.py

  • Committer: mattgiuca
  • Date: 2008-01-31 01:44:30 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:345
Global CSS change: ivlebody no longer has 1em of padding (it has none).
This is because most apps were disabling it (and it had to change anyway for
other reasons -- see below).

Hence, all apps which WERE disabling the padding have had that removed, and
just work by default. (console, browser, tutorial)
All apps which WEREN'T disabling the padding (very few) now have to manually
include an extra div. This has been done on all such apps, and has been
heavily documented (both in the CSS file and doc/app_howto). (help, dummy,
debuginfo).

media/common/ivle.css: 
    The real change here (which isn't yet being used) is that ivlebody is now
    positioned absolutely and takes up all the space on the canvas. This is
    to be used for full-page layouts in console and browser.

Show diffs side-by-side

added added

removed removed

Lines of Context:
133
133
    '/etc/ld.so.conf.d': 'jail/etc/ld.so.conf.d',
134
134
}
135
135
 
136
 
class ConfigOption:
137
 
    """A configuration option; one of the things written to conf.py."""
138
 
    def __init__(self, option_name, default, prompt, comment):
139
 
        """Creates a configuration option.
140
 
        option_name: Name of the variable in conf.py. Also name of the
141
 
            command-line argument to setup.py conf.
142
 
        default: Default value for this variable.
143
 
        prompt: (Short) string presented during the interactive prompt in
144
 
            setup.py conf.
145
 
        comment: (Long) comment string stored in conf.py. Each line of this
146
 
            string should begin with a '#'.
147
 
        """
148
 
        self.option_name = option_name
149
 
        self.default = default
150
 
        self.prompt = prompt
151
 
        self.comment = comment
152
 
 
153
 
# Configuration options, defaults and descriptions
154
 
config_options = []
155
 
config_options.append(ConfigOption("root_dir", "/ivle",
156
 
    """Root directory where IVLE is located (in URL space):""",
157
 
    """
158
 
# In URL space, where in the site is IVLE located. (All URLs will be prefixed
159
 
# with this).
160
 
# eg. "/" or "/ivle"."""))
161
 
config_options.append(ConfigOption("ivle_install_dir", "/opt/ivle",
162
 
    'Root directory where IVLE will be installed (on the local file '
163
 
    'system):',
164
 
    """
165
 
# In the local file system, where IVLE is actually installed.
166
 
# This directory should contain the "www" and "bin" directories."""))
167
 
config_options.append(ConfigOption("jail_base", "/home/informatics/jails",
168
 
    """Root directory where the jails (containing user files) are stored
169
 
(on the local file system):""",
170
 
    """
171
 
# In the local file system, where are the student/user file spaces located.
172
 
# The user jails are expected to be located immediately in subdirectories of
173
 
# this location."""))
174
 
config_options.append(ConfigOption("subjects_base",
175
 
    "/home/informatics/subjects",
176
 
    """Root directory where the subject directories (containing worksheets
177
 
and other per-subject files) are stored (on the local file system):""",
178
 
    """
179
 
# In the local file system, where are the per-subject file spaces located.
180
 
# The individual subject directories are expected to be located immediately
181
 
# in subdirectories of this location."""))
182
 
config_options.append(ConfigOption("public_host", "public.localhost",
183
 
    """Hostname which will cause the server to go into "public mode",
184
 
providing login-free access to student's published work:""",
185
 
    """
186
 
# The server goes into "public mode" if the browser sends a request with this
187
 
# host. This is for security reasons - we only serve public student files on a
188
 
# separate domain to the main IVLE site.
189
 
# Public mode does not use cookies, and serves only public content.
190
 
# Private mode (normal mode) requires login, and only serves files relevant to
191
 
# the logged-in user."""))
192
 
config_options.append(ConfigOption("allowed_uids", "33",
193
 
    """UID of the web server process which will run IVLE.
194
 
Only this user may execute the trampoline. May specify multiple users as
195
 
a comma-separated list.
196
 
    (eg. "1002,78")""",
197
 
    """
198
 
# The User-ID of the web server process which will run IVLE, and any other
199
 
# users who are allowed to run the trampoline. This is stores as a string of
200
 
# comma-separated integers, simply because it is not used within Python, only
201
 
# used by the setup program to write to conf.h (see setup.py config)."""))
202
 
config_options.append(ConfigOption("db_host", "localhost",
203
 
    """PostgreSQL Database config
204
 
==========================
205
 
Hostname of the DB server:""",
206
 
    """
207
 
### PostgreSQL Database config ###
208
 
# Database server hostname"""))
209
 
config_options.append(ConfigOption("db_port", "5432",
210
 
    """Port of the DB server:""",
211
 
    """
212
 
# Database server port"""))
213
 
config_options.append(ConfigOption("db_dbname", "ivle",
214
 
    """Database name:""",
215
 
    """
216
 
# Database name"""))
217
 
config_options.append(ConfigOption("db_user", "postgres",
218
 
    """Username for DB server login:""",
219
 
    """
220
 
# Database username"""))
221
 
config_options.append(ConfigOption("db_password", "",
222
 
    """Password for DB server login:
223
 
    (Caution: This password is stored in plaintext in www/conf/conf.py)""",
224
 
    """
225
 
# Database password"""))
226
 
 
227
136
# Try importing existing conf, but if we can't just set up defaults
228
137
# The reason for this is that these settings are used by other phases
229
138
# of setup besides conf, so we need to know them.
230
139
# Also this allows you to hit Return to accept the existing value.
231
140
try:
232
141
    confmodule = __import__("www/conf/conf")
233
 
    for opt in config_options:
234
 
        try:
235
 
            globals()[opt.option_name] = confmodule.__dict__[opt.option_name]
236
 
        except:
237
 
            globals()[opt.option_name] = opt.default
 
142
    try:
 
143
        root_dir = confmodule.root_dir
 
144
    except:
 
145
        root_dir = "/ivle"
 
146
    try:
 
147
        ivle_install_dir = confmodule.ivle_install_dir
 
148
    except:
 
149
        ivle_install_dir = "/opt/ivle"
 
150
    try:
 
151
        public_host = confmodule.public_host
 
152
    except:
 
153
        public_host = "public.localhost"
 
154
    try:
 
155
        jail_base = confmodule.jail_base
 
156
    except:
 
157
        jail_base = "/home/informatics/jails"
 
158
    try:
 
159
        subjects_base = confmodule.subjects_base
 
160
    except:
 
161
        subjects_base = "/home/informatics/subjects"
238
162
except ImportError:
239
163
    # Just set reasonable defaults
240
 
    for opt in config_options:
241
 
        globals()[opt.option_name] = opt.default
 
164
    root_dir = "/ivle"
 
165
    ivle_install_dir = "/opt/ivle"
 
166
    public_host = "public.localhost"
 
167
    jail_base = "/home/informatics/jails"
 
168
    subjects_base = "/home/informatics/subjects"
 
169
# Always defaults
 
170
allowed_uids = "0"
242
171
 
243
172
# Try importing install_list, but don't fail if we can't, because listmake can
244
173
# function without it.
346
275
 
347
276
Creates www/conf/conf.py and trampoline/conf.h.
348
277
 
349
 
Args are:"""
350
 
        for opt in config_options:
351
 
            print "    --" + opt.option_name
352
 
        print """As explained in the interactive prompt or conf.py.
 
278
Args are:
 
279
    --root_dir
 
280
    --ivle_install_dir
 
281
    --public_host
 
282
    --jail_base
 
283
    --subjects_base
 
284
    --allowed_uids
 
285
As explained in the interactive prompt or conf.py.
353
286
"""
354
287
    elif operation == 'build':
355
288
        print """python -O setup.py build [--dry|-n]
475
408
        file.write(']\n')
476
409
 
477
410
def conf(args):
478
 
    global db_port
 
411
    global root_dir, ivle_install_dir, jail_base, subjects_base
 
412
    global public_host, allowed_uids
479
413
    # Set up some variables
480
414
 
481
415
    cwd = os.getcwd()
485
419
 
486
420
    # Get command-line arguments to avoid asking questions.
487
421
 
488
 
    optnames = []
489
 
    for opt in config_options:
490
 
        optnames.append(opt.option_name + "=")
491
 
    (opts, args) = getopt.gnu_getopt(args, "", optnames)
 
422
    (opts, args) = getopt.gnu_getopt(args, "", ['root_dir=',
 
423
                    'ivle_install_dir=', 'jail_base=', 'allowed_uids='])
492
424
 
493
425
    if args != []:
494
426
        print >>sys.stderr, "Invalid arguments:", string.join(args, ' ')
510
442
        # If EOF is encountered at any time during the questioning, just exit
511
443
        # silently
512
444
 
513
 
        for opt in config_options:
514
 
            globals()[opt.option_name] = \
515
 
                query_user(globals()[opt.option_name], opt.prompt)
 
445
        root_dir = query_user(root_dir,
 
446
        """Root directory where IVLE is located (in URL space):""")
 
447
        ivle_install_dir = query_user(ivle_install_dir,
 
448
        'Root directory where IVLE will be installed (on the local file '
 
449
        'system):')
 
450
        jail_base = query_user(jail_base,
 
451
        """Root directory where the jails (containing user files) are stored
 
452
(on the local file system):""")
 
453
        subjects_base = query_user(subjects_base,
 
454
        """Root directory where the subject directories (containing worksheets
 
455
and other per-subject files) are stored (on the local file system):""")
 
456
        public_host = query_user(public_host,
 
457
        """Hostname which will cause the server to go into "public mode",
 
458
providing login-free access to student's published work:""")
 
459
        allowed_uids = query_user(allowed_uids,
 
460
        """UID of the web server process which will run IVLE.
 
461
Only this user may execute the trampoline. May specify multiple users as
 
462
a comma-separated list.
 
463
    (eg. "1002,78")""")
 
464
 
516
465
    else:
517
466
        opts = dict(opts)
518
467
        # Non-interactive mode. Parse the options.
519
 
        for opt in config_options:
520
 
            if '--' + opt.option_name in opts:
521
 
                globals()[opt.option_name] = opts['--' + opt.option_name]
 
468
        if '--root_dir' in opts:
 
469
            root_dir = opts['--root_dir']
 
470
        if '--ivle_install_dir' in opts:
 
471
            ivle_install_dir = opts['--ivle_install_dir']
 
472
        if '--jail_base' in opts:
 
473
            jail_base = opts['--jail_base']
 
474
        if '--subjects_base' in opts:
 
475
            jail_base = opts['--subjects_base']
 
476
        if '--public_host' in opts:
 
477
            public_host = opts['--public_host']
 
478
        if '--allowed_uids' in opts:
 
479
            allowed_uids = opts['--allowed_uids']
522
480
 
523
481
    # Error handling on input values
524
482
    try:
525
 
        allowed_uids_list = map(int, allowed_uids.split(','))
 
483
        allowed_uids = map(int, allowed_uids.split(','))
526
484
    except ValueError:
527
485
        print >>sys.stderr, (
528
486
        "Invalid UID list (%s).\n"
529
487
        "Must be a comma-separated list of integers." % allowed_uids)
530
488
        return 1
531
 
    try:
532
 
        db_port = int(db_port)
533
 
        if db_port < 0 or db_port >= 65536: raise ValueError()
534
 
    except ValueError:
535
 
        print >>sys.stderr, (
536
 
        "Invalid DB port (%s).\n"
537
 
        "Must be an integer between 0 and 65535." % repr(db_port))
538
 
        return 1
539
489
 
540
490
    # Write www/conf/conf.py
541
491
 
546
496
# conf.py
547
497
# Miscellaneous application settings
548
498
 
549
 
""")
550
 
        for opt in config_options:
551
 
            conf.write('%s\n%s = %s\n' % (opt.comment, opt.option_name,
552
 
                repr(globals()[opt.option_name])))
 
499
 
 
500
# In URL space, where in the site is IVLE located. (All URLs will be prefixed
 
501
# with this).
 
502
# eg. "/" or "/ivle".
 
503
root_dir = "%s"
 
504
 
 
505
# In the local file system, where IVLE is actually installed.
 
506
# This directory should contain the "www" and "bin" directories.
 
507
ivle_install_dir = "%s"
 
508
 
 
509
# The server goes into "public mode" if the browser sends a request with this
 
510
# host. This is for security reasons - we only serve public student files on a
 
511
# separate domain to the main IVLE site.
 
512
# Public mode does not use cookies, and serves only public content.
 
513
# Private mode (normal mode) requires login, and only serves files relevant to
 
514
# the logged-in user.
 
515
public_host = "%s"
 
516
 
 
517
# In the local file system, where are the student/user file spaces located.
 
518
# The user jails are expected to be located immediately in subdirectories of
 
519
# this location.
 
520
jail_base = "%s"
 
521
 
 
522
# In the local file system, where are the per-subject file spaces located.
 
523
# The individual subject directories are expected to be located immediately
 
524
# in subdirectories of this location.
 
525
subjects_base = "%s"
 
526
""" % (root_dir, ivle_install_dir, public_host, jail_base, subjects_base))
553
527
 
554
528
        conf.close()
555
529
    except IOError, (errno, strerror):
581
555
 * (Note that root is an implicit member of this list).
582
556
 */
583
557
static const int allowed_uids[] = { %s };
584
 
""" % (jail_base, repr(allowed_uids_list)[1:-1]))
 
558
""" % (jail_base, repr(allowed_uids)[1:-1]))
585
559
 
586
560
        conf.close()
587
561
    except IOError, (errno, strerror):
607
581
        print "Dry run (no actions will be executed\n"
608
582
 
609
583
    # Compile the trampoline
610
 
    curdir = os.getcwd()
611
 
    os.chdir('trampoline')
612
 
    action_runprog('make', [], dry)
613
 
    os.chdir(curdir)
 
584
    action_runprog('gcc', ['-Wall', '-o', 'trampoline/trampoline',
 
585
        'trampoline/trampoline.c'], dry)
614
586
 
615
587
    # Create the jail and its subdirectories
616
588
    # Note: Other subdirs will be made by copying files