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

« back to all changes in this revision

Viewing changes to setup.py

  • Committer: mattgiuca
  • Date: 2007-12-21 00:53:07 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:113
setup.py: Now loads defaults, if possible, from the existing conf.py.
Instead of printing examples, prints the defaults. Hitting return immediately
when faced with a query now chooses the default.

Show diffs side-by-side

added added

removed removed

Lines of Context:
65
65
import string
66
66
import errno
67
67
 
 
68
# Try importing existing conf, but if we can't just set up defaults
 
69
# The reason for this is that these settings are used by other phases
 
70
# of setup besides conf, so we need to know them.
 
71
# Also this allows you to hit Return to accept the existing value.
 
72
try:
 
73
    confmodule = __import__("www/conf/conf")
 
74
    root_dir = confmodule.root_dir
 
75
    ivle_install_dir = confmodule.ivle_install_dir
 
76
    jail_base = confmodule.jail_base
 
77
except ImportError:
 
78
    # Just set reasonable defaults
 
79
    root_dir = "/ivle"
 
80
    ivle_install_dir = "/opt/ivle"
 
81
    jail_base = "/home/informatics/jails"
 
82
# Always defaults
 
83
allowed_uids = "0"
 
84
 
68
85
# Main function skeleton from Guido van Rossum
69
86
# http://www.artima.com/weblogs/viewpost.jsp?thread=4829
70
87
 
186
203
    return 1
187
204
 
188
205
def conf(args):
 
206
    global root_dir, ivle_install_dir, jail_base, allowed_uids
189
207
    # Set up some variables
190
208
 
191
209
    cwd = os.getcwd()
210
228
    # If EOF is encountered at any time during the questioning, just exit
211
229
    # silently
212
230
 
213
 
    root_dir = query_user(
214
 
    """Root directory where IVLE is located (in URL space):
215
 
    (eg. "/" or "/ivle")""")
216
 
    ivle_install_dir = query_user(
 
231
    root_dir = query_user(root_dir,
 
232
    """Root directory where IVLE is located (in URL space):""")
 
233
    ivle_install_dir = query_user(ivle_install_dir,
217
234
    'Root directory where IVLE will be installed (on the local file '
218
 
    'system):\n'
219
 
    '(eg. "/opt/ivle")')
220
 
    jail_base = query_user(
 
235
    'system):')
 
236
    jail_base = query_user(jail_base,
221
237
    """Root directory where the jails (containing user files) are stored
222
 
(on the local file system):
223
 
    (eg. "/home/informatics/jails")""")
224
 
    allowed_uids = query_user(
 
238
(on the local file system):""")
 
239
    allowed_uids = query_user(allowed_uids,
225
240
    """UID of the web server process which will run IVLE.
226
241
Only this user may execute the trampoline. May specify multiple users as
227
242
a comma-separated list.
325
340
    action_mkdir('jail')
326
341
    action_mkdir('jail/bin')
327
342
    action_mkdir('jail/lib')
328
 
    action_mkdir('jail/usr')
329
343
    action_mkdir('jail/usr/bin')
330
344
    action_mkdir('jail/usr/lib')
331
 
    action_mkdir('jail/opt')
 
345
    action_mkdir('jail/opt/ivle')
332
346
    action_mkdir('jail/home')
333
347
    action_mkdir('jail/tmp')
334
348
 
376
390
            raise RunError(prog, ret)
377
391
 
378
392
def action_mkdir(path):
379
 
    """Calls mkdir. Silently ignored if the directory already exists."""
380
 
    print "mkdir", path
 
393
    """Calls mkdir. Silently ignored if the directory already exists.
 
394
    Creates all parent directories as necessary."""
 
395
    print "mkdir -p", path
381
396
    try:
382
 
        os.mkdir(path)
 
397
        os.makedirs(path)
383
398
    except OSError, (err, msg):
384
399
        if err != errno.EEXIST:
385
400
            raise
386
401
 
387
 
def query_user(prompt):
 
402
def query_user(default, prompt):
388
403
    """Prompts the user for a string, which is read from a line of stdin.
389
404
    Exits silently if EOF is encountered. Returns the string, with spaces
390
405
    removed from the beginning and end.
 
406
 
 
407
    Returns default if a 0-length line (after spaces removed) was read.
391
408
    """
392
 
    sys.stdout.write(prompt)
393
 
    sys.stdout.write("\n>")
 
409
    sys.stdout.write('%s\n    (default: "%s")\n>' % (prompt, default))
394
410
    try:
395
411
        val = sys.stdin.readline()
396
412
    except KeyboardInterrupt:
398
414
        sys.stdout.write("\n")
399
415
        sys.exit(1)
400
416
    sys.stdout.write("\n")
 
417
    # If EOF, exit
401
418
    if val == '': sys.exit(1)
402
 
    return val.strip()
 
419
    # If empty line, return default
 
420
    val = val.strip()
 
421
    if val == '': return default
 
422
    return val
403
423
 
404
424
if __name__ == "__main__":
405
425
    sys.exit(main())