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

« back to all changes in this revision

Viewing changes to setup.py

  • Committer: mattgiuca
  • Date: 2008-01-25 06:20:32 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:313
test/test_framework: Updated examples, a bit of better descriptions, sample
    partial solutions, etc.

Added all sample subject material.
This has been copied from test/test_framework and modified slightly.
There is now a subject "sample" with 2 worksheets. The 1st worksheet has 3
exercises. These work in IVLE by default.

setup.py: Added code to install subjects into the designated directory. This
means that installing IVLE will result in the sample subjects being
immediately available.

Show diffs side-by-side

added added

removed removed

Lines of Context:
176
176
# as necessary, and include it in the distribution.
177
177
listmake_mimetypes = ['text/x-python', 'text/html',
178
178
    'application/x-javascript', 'application/javascript',
179
 
    'text/css', 'image/png']
 
179
    'text/css', 'image/png', 'application/xml']
180
180
 
181
181
# Main function skeleton from Guido van Rossum
182
182
# http://www.artima.com/weblogs/viewpost.jsp?thread=4829
237
237
    listmake (developer use only)
238
238
    conf [args]
239
239
    build
240
 
    install [--nojail] [-n|--dry]
 
240
    install [--nojail] [--nosubjects] [-n|--dry]
241
241
"""
242
242
        return 1
243
243
    elif len(args) != 1:
293
293
 
294
294
--dry | -n  Print out the actions but don't do anything."""
295
295
    elif operation == 'install':
296
 
        print """sudo python setup.py install [--nojail] [--dry|-n]
 
296
        print """sudo python setup.py install [--nojail] [--nosubjects][--dry|-n]
297
297
(Requires root)
298
298
Create target install directory ($target).
299
299
Create $target/bin.
301
301
chown and chmod the installed trampoline.
302
302
Copy www/ to $target.
303
303
Copy jail/ to jails template directory (unless --nojail specified).
 
304
Copy subjects/ to subjects directory (unless --nosubjects specified).
304
305
 
305
 
--nojail    Do not copy the jail.
 
306
--nojail        Do not copy the jail.
 
307
--nosubjects    Do not copy the subjects.
306
308
--dry | -n  Print out the actions but don't do anything."""
307
309
    elif operation == 'updatejails':
308
310
        print """sudo python setup.py updatejails [--dry|-n]
320
322
    # We build two separate lists, by walking www and console
321
323
    list_www = build_list_py_files('www')
322
324
    list_console = build_list_py_files('console')
 
325
    list_subjects = build_list_py_files('subjects', no_top_level=True)
323
326
    # Make sure that the files generated by conf are in the list
324
327
    # (since listmake is typically run before conf)
325
328
    if "www/conf/conf.py" not in list_www:
349
352
# List of all installable files in console directory.
350
353
list_console = """)
351
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)
352
360
 
353
361
        file.close()
354
362
    except IOError, (errno, strerror):
365
373
 
366
374
    return 0
367
375
 
368
 
def build_list_py_files(dir):
 
376
def build_list_py_files(dir, no_top_level=False):
369
377
    """Builds a list of all py files found in a directory and its
370
 
    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
    """
371
382
    pylist = []
372
383
    for (dirpath, dirnames, filenames) in os.walk(dir):
373
384
        # Exclude directories beginning with a '.' (such as '.svn')
375
386
        # All *.py files are added to the list
376
387
        pylist += [os.path.join(dirpath, item) for item in filenames
377
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)
378
392
    return pylist
379
393
 
380
394
def writelist_pretty(file, list):
602
616
 
603
617
def install(args):
604
618
    # Get "dry" and "nojail" variables from command line
605
 
    (opts, args) = getopt.gnu_getopt(args, "n", ['dry', 'nojail'])
 
619
    (opts, args) = getopt.gnu_getopt(args, "n",
 
620
        ['dry', 'nojail', 'nosubjects'])
606
621
    opts = dict(opts)
607
622
    dry = '-n' in opts or '--dry' in opts
608
623
    nojail = '--nojail' in opts
 
624
    nosubjects = '--nosubjects' in opts
609
625
 
610
626
    if dry:
611
627
        print "Dry run (no actions will be executed\n"
633
649
        # to the jails template directory (it will be used as a template
634
650
        # for all the students' jails).
635
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")
636
656
 
637
657
    # Append IVLE path to ivle.pth in python site packages
638
658
    # (Unless it's already there)
768
788
    if dry: return
769
789
    common.makeuser.linktree(src, dst)
770
790
 
771
 
def action_copylist(srclist, dst, dry):
 
791
def action_copylist(srclist, dst, dry, srcdir="."):
772
792
    """Copies all files in a list to a new location. The files in the list
773
793
    are read relative to the current directory, and their destinations are the
774
794
    same paths relative to dst. Creates all parent directories as necessary.
 
795
    srcdir is "." by default, can be overridden.
775
796
    """
776
797
    for srcfile in srclist:
777
798
        dstfile = os.path.join(dst, srcfile)
 
799
        srcfile = os.path.join(srcdir, srcfile)
778
800
        dstdir = os.path.split(dstfile)[0]
779
801
        if not os.path.isdir(dstdir):
780
802
            action_mkdir(dstdir, dry)