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

« back to all changes in this revision

Viewing changes to setup.py

  • Committer: mattgiuca
  • Date: 2007-12-21 02:21:39 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:118
setup.py: Added copytree and copylist actions.
    build now copies all console files into the jail using copylist.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
# It is called with at least one argument, which specifies which operation to
26
26
# take.
27
27
 
 
28
# setup.py listmake (for developer use only)
 
29
# Recurses through the source tree and builds a list of all files which should
 
30
# be copied upon installation. This should be run by the developer before
 
31
# cutting a distribution, and the listfile it generates should be included in
 
32
# the distribution, avoiding the administrator having to run it.
 
33
 
28
34
# setup.py conf [args]
29
35
# Configures IVLE with machine-specific details, most notably, various paths.
30
36
# Either prompts the administrator for these details or accepts them as
42
48
#   (eg. python and Python libs, ld.so, etc).
43
49
# Generates .pyc files for all the IVLE .py files.
44
50
 
45
 
# setup.py listmake (for developer use only)
46
 
# Recurses through the source tree and builds a list of all files which should
47
 
# be copied upon installation. This should be run by the developer before
48
 
# cutting a distribution, and the listfile it generates should be included in
49
 
# the distribution, avoiding the administrator having to run it.
50
 
 
51
51
# setup.py install [--nojail] [--dry|n]
52
52
# (Requires root)
53
53
# Create target install directory ($target).
60
60
# TODO: List in help, and handle, args for the conf operation
61
61
 
62
62
import os
 
63
import shutil
63
64
import sys
64
65
import getopt
65
66
import string
84
85
# Always defaults
85
86
allowed_uids = "0"
86
87
 
 
88
# Try importing install_list, but don't fail if we can't, because listmake can
 
89
# function without it.
 
90
try:
 
91
    import install_list
 
92
except:
 
93
    pass
 
94
 
87
95
# Mime types which will automatically be placed in the list by listmake.
88
96
# Note that listmake is not intended to be run by the final user (the system
89
97
# administrator who installs this), so the developers can customize the list
168
176
    if operation == 'help':
169
177
        print """python setup.py help [operation]
170
178
Prints the usage message or detailed help on an operation, then exits."""
 
179
    elif operation == 'listmake':
 
180
        print """python setup.py listmake
 
181
(For developer use only)
 
182
Recurses through the source tree and builds a list of all files which should
 
183
be copied upon installation. This should be run by the developer before
 
184
cutting a distribution, and the listfile it generates should be included in
 
185
the distribution, avoiding the administrator having to run it."""
171
186
    elif operation == 'conf':
172
187
        print """python setup.py conf [args]
173
188
Configures IVLE with machine-specific details, most notably, various paths.
177
192
Args are:
178
193
"""
179
194
    elif operation == 'build':
180
 
        print """python -O setup.py build
 
195
        print """python -O setup.py build [--dry|-n]
181
196
Compiles all files and sets up a jail template in the source directory.
182
197
-O is recommended to cause compilation to be optimised.
183
198
Details:
187
202
Copies console/ to a location within the jail.
188
203
Copies OS programs and files to corresponding locations within the jail
189
204
  (eg. python and Python libs, ld.so, etc).
190
 
Generates .pyc or .pyo files for all the IVLE .py files."""
191
 
    elif operation == 'listmake':
192
 
        print """python setup.py listmake
193
 
(For developer use only)
194
 
Recurses through the source tree and builds a list of all files which should
195
 
be copied upon installation. This should be run by the developer before
196
 
cutting a distribution, and the listfile it generates should be included in
197
 
the distribution, avoiding the administrator having to run it."""
 
205
Generates .pyc or .pyo files for all the IVLE .py files.
 
206
 
 
207
--dry | -n  Print out the actions but don't do anything."""
198
208
    elif operation == 'install':
199
209
        print """sudo python setup.py install [--nojail] [--dry|-n]
200
210
(Requires root)
428
438
    action_mkdir('jail/home', dry)
429
439
    action_mkdir('jail/tmp', dry)
430
440
 
431
 
    # TODO: Copy console into the jail
 
441
    # Copy all console files into the jail
 
442
    action_copylist(install_list.list_console, 'jail/opt/ivle', dry)
 
443
 
432
444
    # TODO: Copy operating system files into the jail
 
445
 
433
446
    # Compile .py files into .pyc or .pyo files
434
447
    compileall.compile_dir('www', quiet=True)
435
448
    compileall.compile_dir('console', quiet=True)
480
493
        if err != errno.EEXIST:
481
494
            raise
482
495
 
 
496
def action_copytree(src, dst, dry):
 
497
    """Copies an entire directory tree. Symlinks are seen as normal files and
 
498
    copies of the entire file (not the link) are made. Creates all parent
 
499
    directories as necessary.
 
500
 
 
501
    See shutil.copytree."""
 
502
    if os.access(dst, os.F_OK):
 
503
        print "rm -r", dst
 
504
        if not dry:
 
505
            shutil.rmtree(dst, True)
 
506
    print "cp -r", src, dst
 
507
    if dry: return
 
508
    shutil.copytree(src, dst)
 
509
 
 
510
def action_copylist(srclist, dst, dry):
 
511
    """Copies all files in a list to a new location. The files in the list
 
512
    are read relative to the current directory, and their destinations are the
 
513
    same paths relative to dst. Creates all parent directories as necessary.
 
514
    """
 
515
    for srcfile in srclist:
 
516
        dstfile = os.path.join(dst, srcfile)
 
517
        dstdir = os.path.split(dstfile)[0]
 
518
        if not os.path.isdir(dstdir):
 
519
            action_mkdir(dstdir, dry)
 
520
        print "cp -f", srcfile, dstfile
 
521
        if not dry:
 
522
            shutil.copyfile(srcfile, dstfile)
 
523
 
483
524
def query_user(default, prompt):
484
525
    """Prompts the user for a string, which is read from a line of stdin.
485
526
    Exits silently if EOF is encountered. Returns the string, with spaces