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

« back to all changes in this revision

Viewing changes to setup.py

  • Committer: mattgiuca
  • Date: 2008-01-28 23:04:08 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:315
trampoline/trampoline.c: Added 2 includes, which are required
for the "umask" function. (This wasn't a problem on Ubuntu 7.10 but is for
older versions).

Show diffs side-by-side

added added

removed removed

Lines of Context:
149
149
        jail_base = confmodule.jail_base
150
150
    except:
151
151
        jail_base = "/home/informatics/jails"
 
152
    try:
 
153
        subjects_base = confmodule.subjects_base
 
154
    except:
 
155
        subjects_base = "/home/informatics/subjects"
152
156
except ImportError:
153
157
    # Just set reasonable defaults
154
158
    root_dir = "/ivle"
155
159
    ivle_install_dir = "/opt/ivle"
156
160
    public_host = "public.localhost"
157
161
    jail_base = "/home/informatics/jails"
 
162
    subjects_base = "/home/informatics/subjects"
158
163
# Always defaults
159
164
allowed_uids = "0"
160
165
 
171
176
# as necessary, and include it in the distribution.
172
177
listmake_mimetypes = ['text/x-python', 'text/html',
173
178
    'application/x-javascript', 'application/javascript',
174
 
    'text/css', 'image/png']
 
179
    'text/css', 'image/png', 'application/xml']
175
180
 
176
181
# Main function skeleton from Guido van Rossum
177
182
# http://www.artima.com/weblogs/viewpost.jsp?thread=4829
232
237
    listmake (developer use only)
233
238
    conf [args]
234
239
    build
235
 
    install [--nojail] [-n|--dry]
 
240
    install [--nojail] [--nosubjects] [-n|--dry]
236
241
"""
237
242
        return 1
238
243
    elif len(args) != 1:
269
274
    --ivle_install_dir
270
275
    --public_host
271
276
    --jail_base
 
277
    --subjects_base
272
278
    --allowed_uids
273
279
As explained in the interactive prompt or conf.py.
274
280
"""
287
293
 
288
294
--dry | -n  Print out the actions but don't do anything."""
289
295
    elif operation == 'install':
290
 
        print """sudo python setup.py install [--nojail] [--dry|-n]
 
296
        print """sudo python setup.py install [--nojail] [--nosubjects][--dry|-n]
291
297
(Requires root)
292
298
Create target install directory ($target).
293
299
Create $target/bin.
295
301
chown and chmod the installed trampoline.
296
302
Copy www/ to $target.
297
303
Copy jail/ to jails template directory (unless --nojail specified).
 
304
Copy subjects/ to subjects directory (unless --nosubjects specified).
298
305
 
299
 
--nojail    Do not copy the jail.
 
306
--nojail        Do not copy the jail.
 
307
--nosubjects    Do not copy the subjects.
300
308
--dry | -n  Print out the actions but don't do anything."""
301
309
    elif operation == 'updatejails':
302
310
        print """sudo python setup.py updatejails [--dry|-n]
314
322
    # We build two separate lists, by walking www and console
315
323
    list_www = build_list_py_files('www')
316
324
    list_console = build_list_py_files('console')
 
325
    list_subjects = build_list_py_files('subjects', no_top_level=True)
317
326
    # Make sure that the files generated by conf are in the list
318
327
    # (since listmake is typically run before conf)
319
328
    if "www/conf/conf.py" not in list_www:
343
352
# List of all installable files in console directory.
344
353
list_console = """)
345
354
        writelist_pretty(file, list_console)
 
355
        file.write("""
 
356
# List of all installable files in subjects directory.
 
357
# This is to install sample subjects and material.
 
358
list_subjects = """)
 
359
        writelist_pretty(file, list_subjects)
346
360
 
347
361
        file.close()
348
362
    except IOError, (errno, strerror):
359
373
 
360
374
    return 0
361
375
 
362
 
def build_list_py_files(dir):
 
376
def build_list_py_files(dir, no_top_level=False):
363
377
    """Builds a list of all py files found in a directory and its
364
 
    subdirectories. Returns this as a list of strings."""
 
378
    subdirectories. Returns this as a list of strings.
 
379
    no_top_level=True means the file paths will not include the top-level
 
380
    directory.
 
381
    """
365
382
    pylist = []
366
383
    for (dirpath, dirnames, filenames) in os.walk(dir):
367
384
        # Exclude directories beginning with a '.' (such as '.svn')
369
386
        # All *.py files are added to the list
370
387
        pylist += [os.path.join(dirpath, item) for item in filenames
371
388
            if mimetypes.guess_type(item)[0] in listmake_mimetypes]
 
389
    if no_top_level:
 
390
        for i in range(0, len(pylist)):
 
391
            _, pylist[i] = pylist[i].split(os.sep, 1)
372
392
    return pylist
373
393
 
374
394
def writelist_pretty(file, list):
382
402
        file.write(']\n')
383
403
 
384
404
def conf(args):
385
 
    global root_dir, ivle_install_dir, jail_base, public_host, allowed_uids
 
405
    global root_dir, ivle_install_dir, jail_base, subjects_base
 
406
    global public_host, allowed_uids
386
407
    # Set up some variables
387
408
 
388
409
    cwd = os.getcwd()
423
444
        jail_base = query_user(jail_base,
424
445
        """Root directory where the jails (containing user files) are stored
425
446
(on the local file system):""")
 
447
        subjects_base = query_user(subjects_base,
 
448
        """Root directory where the subject directories (containing worksheets
 
449
and other per-subject files) are stored (on the local file system):""")
426
450
        public_host = query_user(public_host,
427
451
        """Hostname which will cause the server to go into "public mode",
428
452
providing login-free access to student's published work:""")
441
465
            ivle_install_dir = opts['--ivle_install_dir']
442
466
        if '--jail_base' in opts:
443
467
            jail_base = opts['--jail_base']
 
468
        if '--subjects_base' in opts:
 
469
            jail_base = opts['--subjects_base']
444
470
        if '--public_host' in opts:
445
471
            public_host = opts['--public_host']
446
472
        if '--allowed_uids' in opts:
486
512
# The user jails are expected to be located immediately in subdirectories of
487
513
# this location.
488
514
jail_base = "%s"
489
 
""" % (root_dir, ivle_install_dir, public_host, jail_base))
 
515
 
 
516
# In the local file system, where are the per-subject file spaces located.
 
517
# The individual subject directories are expected to be located immediately
 
518
# in subdirectories of this location.
 
519
subjects_base = "%s"
 
520
""" % (root_dir, ivle_install_dir, public_host, jail_base, subjects_base))
490
521
 
491
522
        conf.close()
492
523
    except IOError, (errno, strerror):
585
616
 
586
617
def install(args):
587
618
    # Get "dry" and "nojail" variables from command line
588
 
    (opts, args) = getopt.gnu_getopt(args, "n", ['dry', 'nojail'])
 
619
    (opts, args) = getopt.gnu_getopt(args, "n",
 
620
        ['dry', 'nojail', 'nosubjects'])
589
621
    opts = dict(opts)
590
622
    dry = '-n' in opts or '--dry' in opts
591
623
    nojail = '--nojail' in opts
 
624
    nosubjects = '--nosubjects' in opts
592
625
 
593
626
    if dry:
594
627
        print "Dry run (no actions will be executed\n"
616
649
        # to the jails template directory (it will be used as a template
617
650
        # for all the students' jails).
618
651
        action_copytree('jail', os.path.join(jail_base, 'template'), dry)
 
652
    if not nosubjects:
 
653
        # Copy the subjects directory across
 
654
        action_copylist(install_list.list_subjects, subjects_base, dry,
 
655
            srcdir="./subjects")
619
656
 
620
657
    # Append IVLE path to ivle.pth in python site packages
621
658
    # (Unless it's already there)
751
788
    if dry: return
752
789
    common.makeuser.linktree(src, dst)
753
790
 
754
 
def action_copylist(srclist, dst, dry):
 
791
def action_copylist(srclist, dst, dry, srcdir="."):
755
792
    """Copies all files in a list to a new location. The files in the list
756
793
    are read relative to the current directory, and their destinations are the
757
794
    same paths relative to dst. Creates all parent directories as necessary.
 
795
    srcdir is "." by default, can be overridden.
758
796
    """
759
797
    for srcfile in srclist:
760
798
        dstfile = os.path.join(dst, srcfile)
 
799
        srcfile = os.path.join(srcdir, srcfile)
761
800
        dstdir = os.path.split(dstfile)[0]
762
801
        if not os.path.isdir(dstdir):
763
802
            action_mkdir(dstdir, dry)