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

« back to all changes in this revision

Viewing changes to setup.py

  • Committer: mattgiuca
  • Date: 2008-01-25 01:05:22 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:300
conf/apps: Added TutorialService as a registered app.
tutorialservice: Started writing app. Currently reads some arguments, and if
    action=test and code is provided, echoes the code back in JSON.

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
# cutting a distribution, and the listfile it generates should be included in
32
32
# the distribution, avoiding the administrator having to run it.
33
33
 
34
 
# setup.py config [args]
 
34
# setup.py conf [args]
35
35
# Configures IVLE with machine-specific details, most notably, various paths.
36
36
# Either prompts the administrator for these details or accepts them as
37
37
# command-line args.
74
74
import conf
75
75
import common.makeuser
76
76
 
77
 
# Determine which Python version (2.4 or 2.5, for example) we are running,
78
 
# and use that as the filename to the Python directory.
79
 
# Just get the first 3 characters of sys.version.
80
 
PYTHON_VERSION = sys.version[0:3]
81
 
 
82
77
# Operating system files to copy over into the jail.
83
78
# These will be copied from the given place on the OS file system into the
84
79
# same place within the jail.
99
94
    '/bin/ls',
100
95
    '/bin/echo',
101
96
    # Needed by python
102
 
    '/usr/bin/python%s' % PYTHON_VERSION,
 
97
    '/usr/bin/python2.5',
103
98
    # Needed by matplotlib
104
99
    '/usr/lib/i686/cmov/libssl.so.0.9.8',
105
100
    '/usr/lib/i686/cmov/libcrypto.so.0.9.8',
123
118
]
124
119
# Symlinks to make within the jail. Src mapped to dst.
125
120
JAIL_LINKS = {
126
 
    'python%s' % PYTHON_VERSION: 'jail/usr/bin/python',
 
121
    'python2.5': 'jail/usr/bin/python',
127
122
}
128
123
# Trees to copy. Src mapped to dst (these will be passed to action_copytree).
129
124
JAIL_COPYTREES = {
130
 
    '/usr/lib/python%s' % PYTHON_VERSION:
131
 
        'jail/usr/lib/python%s' % PYTHON_VERSION,
 
125
    '/usr/lib/python2.5': 'jail/usr/lib/python2.5',
132
126
    '/usr/share/matplotlib': 'jail/usr/share/matplotlib',
133
127
    '/etc/ld.so.conf.d': 'jail/etc/ld.so.conf.d',
134
128
}
182
176
# as necessary, and include it in the distribution.
183
177
listmake_mimetypes = ['text/x-python', 'text/html',
184
178
    'application/x-javascript', 'application/javascript',
185
 
    'text/css', 'image/png', 'application/xml']
 
179
    'text/css', 'image/png']
186
180
 
187
181
# Main function skeleton from Guido van Rossum
188
182
# http://www.artima.com/weblogs/viewpost.jsp?thread=4829
220
214
    try:
221
215
        oper_func = {
222
216
            'help' : help,
223
 
            'config' : conf,
 
217
            'conf' : conf,
224
218
            'build' : build,
225
219
            'listmake' : listmake,
226
220
            'install' : install,
241
235
Operation (and args) can be:
242
236
    help [operation]
243
237
    listmake (developer use only)
244
 
    config [args]
 
238
    conf [args]
245
239
    build
246
 
    install [--nojail] [--nosubjects] [-n|--dry]
 
240
    install [--nojail] [-n|--dry]
247
241
"""
248
242
        return 1
249
243
    elif len(args) != 1:
262
256
be copied upon installation. This should be run by the developer before
263
257
cutting a distribution, and the listfile it generates should be included in
264
258
the distribution, avoiding the administrator having to run it."""
265
 
    elif operation == 'config':
266
 
        print """python setup.py config [args]
 
259
    elif operation == 'conf':
 
260
        print """python setup.py conf [args]
267
261
Configures IVLE with machine-specific details, most notably, various paths.
268
262
Either prompts the administrator for these details or accepts them as
269
263
command-line args. Will be interactive only if there are no arguments given.
299
293
 
300
294
--dry | -n  Print out the actions but don't do anything."""
301
295
    elif operation == 'install':
302
 
        print """sudo python setup.py install [--nojail] [--nosubjects][--dry|-n]
 
296
        print """sudo python setup.py install [--nojail] [--dry|-n]
303
297
(Requires root)
304
298
Create target install directory ($target).
305
299
Create $target/bin.
307
301
chown and chmod the installed trampoline.
308
302
Copy www/ to $target.
309
303
Copy jail/ to jails template directory (unless --nojail specified).
310
 
Copy subjects/ to subjects directory (unless --nosubjects specified).
311
304
 
312
 
--nojail        Do not copy the jail.
313
 
--nosubjects    Do not copy the subjects.
 
305
--nojail    Do not copy the jail.
314
306
--dry | -n  Print out the actions but don't do anything."""
315
307
    elif operation == 'updatejails':
316
308
        print """sudo python setup.py updatejails [--dry|-n]
328
320
    # We build two separate lists, by walking www and console
329
321
    list_www = build_list_py_files('www')
330
322
    list_console = build_list_py_files('console')
331
 
    list_subjects = build_list_py_files('subjects', no_top_level=True)
332
323
    # Make sure that the files generated by conf are in the list
333
324
    # (since listmake is typically run before conf)
334
325
    if "www/conf/conf.py" not in list_www:
358
349
# List of all installable files in console directory.
359
350
list_console = """)
360
351
        writelist_pretty(file, list_console)
361
 
        file.write("""
362
 
# List of all installable files in subjects directory.
363
 
# This is to install sample subjects and material.
364
 
list_subjects = """)
365
 
        writelist_pretty(file, list_subjects)
366
352
 
367
353
        file.close()
368
354
    except IOError, (errno, strerror):
379
365
 
380
366
    return 0
381
367
 
382
 
def build_list_py_files(dir, no_top_level=False):
 
368
def build_list_py_files(dir):
383
369
    """Builds a list of all py files found in a directory and its
384
 
    subdirectories. Returns this as a list of strings.
385
 
    no_top_level=True means the file paths will not include the top-level
386
 
    directory.
387
 
    """
 
370
    subdirectories. Returns this as a list of strings."""
388
371
    pylist = []
389
372
    for (dirpath, dirnames, filenames) in os.walk(dir):
390
373
        # Exclude directories beginning with a '.' (such as '.svn')
392
375
        # All *.py files are added to the list
393
376
        pylist += [os.path.join(dirpath, item) for item in filenames
394
377
            if mimetypes.guess_type(item)[0] in listmake_mimetypes]
395
 
    if no_top_level:
396
 
        for i in range(0, len(pylist)):
397
 
            _, pylist[i] = pylist[i].split(os.sep, 1)
398
378
    return pylist
399
379
 
400
380
def writelist_pretty(file, list):
622
602
 
623
603
def install(args):
624
604
    # Get "dry" and "nojail" variables from command line
625
 
    (opts, args) = getopt.gnu_getopt(args, "n",
626
 
        ['dry', 'nojail', 'nosubjects'])
 
605
    (opts, args) = getopt.gnu_getopt(args, "n", ['dry', 'nojail'])
627
606
    opts = dict(opts)
628
607
    dry = '-n' in opts or '--dry' in opts
629
608
    nojail = '--nojail' in opts
630
 
    nosubjects = '--nosubjects' in opts
631
609
 
632
610
    if dry:
633
611
        print "Dry run (no actions will be executed\n"
655
633
        # to the jails template directory (it will be used as a template
656
634
        # for all the students' jails).
657
635
        action_copytree('jail', os.path.join(jail_base, 'template'), dry)
658
 
    if not nosubjects:
659
 
        # Copy the subjects directory across
660
 
        action_copylist(install_list.list_subjects, subjects_base, dry,
661
 
            srcdir="./subjects")
662
636
 
663
637
    # Append IVLE path to ivle.pth in python site packages
664
638
    # (Unless it's already there)
665
639
    ivle_pth = os.path.join(sys.prefix,
666
 
        "lib/python%s/site-packages/ivle.pth" % PYTHON_VERSION)
 
640
        "lib/python2.5/site-packages/ivle.pth")
667
641
    ivle_www = os.path.join(ivle_install_dir, "www")
668
642
    write_ivle_pth = True
669
643
    try:
794
768
    if dry: return
795
769
    common.makeuser.linktree(src, dst)
796
770
 
797
 
def action_copylist(srclist, dst, dry, srcdir="."):
 
771
def action_copylist(srclist, dst, dry):
798
772
    """Copies all files in a list to a new location. The files in the list
799
773
    are read relative to the current directory, and their destinations are the
800
774
    same paths relative to dst. Creates all parent directories as necessary.
801
 
    srcdir is "." by default, can be overridden.
802
775
    """
803
776
    for srcfile in srclist:
804
777
        dstfile = os.path.join(dst, srcfile)
805
 
        srcfile = os.path.join(srcdir, srcfile)
806
778
        dstdir = os.path.split(dstfile)[0]
807
779
        if not os.path.isdir(dstdir):
808
780
            action_mkdir(dstdir, dry)
817
789
def action_copyfile(src, dst, dry):
818
790
    """Copies one file to a new location. Creates all parent directories
819
791
    as necessary.
820
 
    Warn if file not found.
821
792
    """
822
793
    dstdir = os.path.split(dst)[0]
823
794
    if not os.path.isdir(dstdir):
827
798
        try:
828
799
            shutil.copyfile(src, dst)
829
800
            shutil.copymode(src, dst)
830
 
        except (shutil.Error, IOError), e:
831
 
            print "Warning: " + str(e)
 
801
        except shutil.Error:
 
802
            pass
832
803
 
833
804
def action_symlink(src, dst, dry):
834
805
    """Creates a symlink in a given location. Creates all parent directories