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

« back to all changes in this revision

Viewing changes to setup.py

  • Committer: mattgiuca
  • Date: 2007-12-20 05:25:03 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:103
Fix to Makefile.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
# IVLE - Informatics Virtual Learning Environment
 
3
# Copyright (C) 2007-2008 The University of Melbourne
 
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
# Module: setup
 
20
# Author: Matt Giuca
 
21
# Date:   12/12/2007
 
22
 
 
23
# This is a command-line application, for use by the administrator.
 
24
# Prompts the administrator to enter machine-specific details and builds the
 
25
# file conf/conf.py.
 
26
# (This file is not included with the distribution precisely because it
 
27
# contains machine-specific settings).
 
28
 
 
29
import os
 
30
import sys
 
31
 
 
32
def query_user(prompt):
 
33
    """Prompts the user for a string, which is read from a line of stdin.
 
34
    Exits silently if EOF is encountered. Returns the string, with spaces
 
35
    removed from the beginning and end.
 
36
    """
 
37
    sys.stdout.write(prompt)
 
38
    sys.stdout.write("\n>")
 
39
    try:
 
40
        val = sys.stdin.readline()
 
41
    except KeyboardInterrupt:
 
42
        # Ctrl+C
 
43
        sys.stdout.write("\n")
 
44
        sys.exit(1)
 
45
    sys.stdout.write("\n")
 
46
    if val == '': sys.exit(1)
 
47
    return val.strip()
 
48
 
 
49
# MAIN SCRIPT
 
50
 
 
51
# Set up some variables
 
52
 
 
53
cwd = os.getcwd()
 
54
# the files that will be created/overwritten
 
55
conffile = os.path.join(cwd, "www/conf/conf.py")
 
56
conf_hfile = os.path.join(cwd, "trampoline/conf.h")
 
57
 
 
58
# Fixed config options that we don't ask the admin
 
59
 
 
60
default_app = "dummy"
 
61
 
 
62
# Print the opening spiel including the GPL notice
 
63
 
 
64
print """IVLE - Informatics Virtual Learning Environment Setup
 
65
Copyright (C) 2007-2008 The University of Melbourne
 
66
IVLE comes with ABSOLUTELY NO WARRANTY.
 
67
This is free software, and you are welcome to redistribute it
 
68
under certain conditions. See LICENSE.txt for details.
 
69
"""
 
70
 
 
71
print """IVLE Setup
 
72
This tool will create the following files:
 
73
    %s
 
74
    %s
 
75
prompting you for details about your configuration. The file will be
 
76
overwritten if it already exists. It will *not* install or deploy IVLE.
 
77
 
 
78
Please hit Ctrl+C now if you do not wish to do this.
 
79
""" % (conffile, conf_hfile)
 
80
 
 
81
# Get information from the administrator
 
82
# If EOF is encountered at any time during the questioning, just exit silently
 
83
 
 
84
root_dir = query_user("""Root directory where IVLE is located (in URL space):
 
85
(eg. "/" or "/ivle")""")
 
86
ivle_install_dir = query_user('Root directory where IVLE is located (on the '
 
87
'local file system):\n'
 
88
'(eg. "/home/informatics/ivle")')
 
89
student_dir = query_user(
 
90
    """Root directory where user files are stored (on the local file system):
 
91
(eg. "/home/informatics/jails")""")
 
92
 
 
93
# Write www/conf.py
 
94
 
 
95
try:
 
96
    conf = open(conffile, "w")
 
97
 
 
98
    conf.write("""# IVLE Configuration File
 
99
# conf.py
 
100
# Miscellaneous application settings
 
101
 
 
102
 
 
103
# In URL space, where in the site is IVLE located. (All URLs will be prefixed
 
104
# with this).
 
105
# eg. "/" or "/ivle".
 
106
root_dir = "%s"
 
107
 
 
108
# In the local file system, where IVLE is actually installed.
 
109
# This directory should contain the "www" and "bin" directories.
 
110
ivle_install_dir = "%s"
 
111
 
 
112
# In the local file system, where are the student/user file spaces located.
 
113
# The user jails are expected to be located immediately in subdirectories of
 
114
# this location.
 
115
student_dir = "%s"
 
116
 
 
117
# Which application to load by default (if the user navigates to the top level
 
118
# of the site). This is the app's URL name.
 
119
# Note that if this app requires authentication, the user will first be
 
120
# presented with the login screen.
 
121
default_app = "%s"
 
122
""" % (root_dir, ivle_install_dir, student_dir, default_app))
 
123
    
 
124
    conf.close()
 
125
except IOError, (errno, strerror):
 
126
    print "IO error(%s): %s" % (errno, strerror)
 
127
    sys.exit(1)
 
128
 
 
129
print "Successfully wrote www/conf.py"
 
130
 
 
131
# Write trampoline/conf.h
 
132
 
 
133
try:
 
134
    conf = open(conf_hfile, "w")
 
135
 
 
136
    conf.write("""/* IVLE Configuration File
 
137
 * conf.h
 
138
 * Administrator settings required by trampoline.
 
139
 * Note: trampoline will have to be rebuilt in order for changes to this file
 
140
 * to take effect.
 
141
 */
 
142
 
 
143
/* In the local file system, where are the jails located.
 
144
 * The trampoline does not allow the creation of a jail anywhere besides
 
145
 * jail_base or a subdirectory of jail_base.
 
146
 */
 
147
static const char* jail_base = "%s";
 
148
""" % (student_dir))
 
149
 
 
150
    conf.close()
 
151
except IOError, (errno, strerror):
 
152
    print "IO error(%s): %s" % (errno, strerror)
 
153
    sys.exit(1)
 
154
 
 
155
print "Successfully wrote trampoline/conf.h"
 
156
 
 
157
print
 
158
print "You may modify the configuration at any time by editing"
 
159
print conffile
 
160
print conf_hfile
 
161
print
 
162