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

« back to all changes in this revision

Viewing changes to setup.py

  • Committer: drtomc
  • Date: 2008-02-04 04:29:12 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:401
tutorialservice: Fixed "subjects" directory being searched for problem files, now looks in "problems". (A hang over from an earlier change to split them up).
This fixes the issue of problem submissions not working.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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.
38
 
# Creates lib/conf/conf.py and trampoline/conf.h.
 
38
# Creates www/conf/conf.py and trampoline/conf.h.
39
39
 
40
40
# setup.py build
41
41
# Compiles all files and sets up a jail template in the source directory.
70
70
 
71
71
# Import modules from the website is tricky since they're in the www
72
72
# directory.
73
 
sys.path.append(os.path.join(os.getcwd(), 'lib'))
 
73
sys.path.append(os.path.join(os.getcwd(), 'www'))
74
74
import conf
75
75
import common.makeuser
76
76
 
100
100
    '/bin/echo',
101
101
    # Needed by python
102
102
    '/usr/bin/python%s' % PYTHON_VERSION,
103
 
    # Needed by fileservice
104
 
    '/lib/libcom_err.so.2',
105
 
    '/lib/libcrypt.so.1',
106
 
    '/lib/libkeyutils.so.1',
107
 
    '/lib/libresolv.so.2',
108
 
    '/lib/librt.so.1',
109
 
    '/lib/libuuid.so.1',
110
 
    '/usr/lib/libapr-1.so.0',
111
 
    '/usr/lib/libaprutil-1.so.0',
112
 
    '/usr/lib/libdb-4.4.so',
113
 
    '/usr/lib/libexpat.so.1',
114
 
    '/usr/lib/libgcrypt.so.11',
115
 
    '/usr/lib/libgnutls.so.13',
116
 
    '/usr/lib/libgpg-error.so.0',
117
 
    '/usr/lib/libgssapi_krb5.so.2',
118
 
    '/usr/lib/libk5crypto.so.3',
119
 
    '/usr/lib/libkrb5.so.3',
120
 
    '/usr/lib/libkrb5support.so.0',
121
 
    '/usr/lib/liblber.so.2',
122
 
    '/usr/lib/libldap_r.so.2',
123
 
    '/usr/lib/libneon.so.26',
124
 
    '/usr/lib/libpq.so.5',
125
 
    '/usr/lib/libsasl2.so.2',
126
 
    '/usr/lib/libsqlite3.so.0',
127
 
    '/usr/lib/libsvn_client-1.so.1',
128
 
    '/usr/lib/libsvn_delta-1.so.1',
129
 
    '/usr/lib/libsvn_diff-1.so.1',
130
 
    '/usr/lib/libsvn_fs-1.so.1',
131
 
    '/usr/lib/libsvn_fs_base-1.so.1',
132
 
    '/usr/lib/libsvn_fs_fs-1.so.1',
133
 
    '/usr/lib/libsvn_ra-1.so.1',
134
 
    '/usr/lib/libsvn_ra_dav-1.so.1',
135
 
    '/usr/lib/libsvn_ra_local-1.so.1',
136
 
    '/usr/lib/libsvn_ra_svn-1.so.1',
137
 
    '/usr/lib/libsvn_repos-1.so.1',
138
 
    '/usr/lib/libsvn_subr-1.so.1',
139
 
    '/usr/lib/libsvn_wc-1.so.1',
140
 
    '/usr/lib/libtasn1.so.3',
141
 
    '/usr/lib/libxml2.so.2',
142
103
    # Needed by matplotlib
143
104
    '/usr/lib/i686/cmov/libssl.so.0.9.8',
144
105
    '/usr/lib/i686/cmov/libcrypto.so.0.9.8',
267
228
# Database username"""))
268
229
config_options.append(ConfigOption("db_password", "",
269
230
    """Password for DB server login:
270
 
    (Caution: This password is stored in plaintext in lib/conf/conf.py)""",
 
231
    (Caution: This password is stored in plaintext in www/conf/conf.py)""",
271
232
    """
272
233
# Database password"""))
273
 
config_options.append(ConfigOption("svn_conf", "/opt/ivle/svn/svn.conf",
274
 
    """The location of the subversion configuration file used by apache
275
 
to host the user repositories:""",
276
 
    """
277
 
# The location of the subversion configuration file used by
278
 
# apache to host the user repositories."""))
279
 
config_options.append(ConfigOption("svn_repo_path", "/home/informatics/repositories",
280
 
    """The root directory for the subversion repositories:""",
281
 
    """
282
 
# The root directory for the subversion repositories."""))
283
 
config_options.append(ConfigOption("svn_auth_ivle", "/opt/ivle/svn/ivle.auth",
284
 
    """The location of the password file used to authenticate users
285
 
of the subversion repository from the ivle server:""",
286
 
    """
287
 
# The location of the password file used to authenticate users
288
 
# of the subversion repository from the ivle server."""))
289
 
config_options.append(ConfigOption("svn_auth_local", "/opt/ivle/svn/local.auth",
290
 
    """The location of the password file used to authenticate local users
291
 
of the subversion repository:""",
292
 
    """
293
 
# The location of the password file used to authenticate local users
294
 
# of the subversion repository."""))
295
 
config_options.append(ConfigOption("usrmgt_host", "localhost",
296
 
    """The hostname where the usrmgt-server runs:""",
297
 
    """
298
 
# The hostname where the usrmgt-server runs."""))
299
 
config_options.append(ConfigOption("usrmgt_port", "2178",
300
 
    """The port where the usrmgt-server runs:""",
301
 
    """
302
 
# The port where the usrmgt-server runs."""))
303
 
config_options.append(ConfigOption("usrmgt_magic", "",
304
 
    """The password for the usrmgt-server:""",
305
 
    """
306
 
# The password for the usrmgt-server."""))
307
234
 
308
235
# Try importing existing conf, but if we can't just set up defaults
309
236
# The reason for this is that these settings are used by other phases
310
237
# of setup besides conf, so we need to know them.
311
238
# Also this allows you to hit Return to accept the existing value.
312
239
try:
313
 
    confmodule = __import__("lib/conf/conf")
 
240
    confmodule = __import__("www/conf/conf")
314
241
    for opt in config_options:
315
242
        try:
316
243
            globals()[opt.option_name] = confmodule.__dict__[opt.option_name]
425
352
to rebuild/install), just provide ivle_install_dir as the IVLE trunk
426
353
directory, and run build/install one time.
427
354
 
428
 
Creates lib/conf/conf.py and trampoline/conf.h.
 
355
Creates www/conf/conf.py and trampoline/conf.h.
429
356
 
430
357
Args are:"""
431
358
        for opt in config_options:
475
402
def listmake(args):
476
403
    # We build two separate lists, by walking www and console
477
404
    list_www = build_list_py_files('www')
478
 
    list_lib = build_list_py_files('lib')
479
 
    list_scripts = build_list_py_files('scripts')
 
405
    list_console = build_list_py_files('console')
480
406
    list_subjects = build_list_py_files('subjects', no_top_level=True)
481
407
    list_problems = build_list_py_files('problems', no_top_level=True)
482
408
    # Make sure that the files generated by conf are in the list
483
409
    # (since listmake is typically run before conf)
484
 
    if "lib/conf/conf.py" not in list_lib:
485
 
        list_lib.append("lib/conf/conf.py")
 
410
    if "www/conf/conf.py" not in list_www:
 
411
        list_www.append("www/conf/conf.py")
486
412
    # Make sure that console/python-console is in the list
487
 
    if "scripts/python-console" not in list_scripts:
488
 
        list_scripts.append("scripts/python-console")
489
 
    if "scripts/fileservice" not in list_scripts:
490
 
        list_scripts.append("scripts/fileservice")
 
413
    if "console/python-console" not in list_console:
 
414
        list_console.append("console/python-console")
491
415
    # Write these out to a file
492
416
    cwd = os.getcwd()
493
417
    # the files that will be created/overwritten
507
431
list_www = """)
508
432
        writelist_pretty(file, list_www)
509
433
        file.write("""
510
 
# List of all installable files in lib directory.
511
 
list_lib = """)
512
 
        writelist_pretty(file, list_lib)
513
 
        file.write("""
514
 
# List of all installable files in scripts directory.
515
 
list_scripts = """)
516
 
        writelist_pretty(file, list_scripts)
 
434
# List of all installable files in console directory.
 
435
list_console = """)
 
436
        writelist_pretty(file, list_console)
517
437
        file.write("""
518
438
# List of all installable files in subjects directory.
519
439
# This is to install sample subjects and material.
574
494
 
575
495
    cwd = os.getcwd()
576
496
    # the files that will be created/overwritten
577
 
    conffile = os.path.join(cwd, "lib/conf/conf.py")
578
 
    jailconffile = os.path.join(cwd, "lib/conf/jailconf.py")
 
497
    conffile = os.path.join(cwd, "www/conf/conf.py")
579
498
    conf_hfile = os.path.join(cwd, "trampoline/conf.h")
580
499
 
581
500
    # Get command-line arguments to avoid asking questions.
595
514
        print """This tool will create the following files:
596
515
    %s
597
516
    %s
598
 
    %s
599
517
prompting you for details about your configuration. The file will be
600
518
overwritten if it already exists. It will *not* install or deploy IVLE.
601
519
 
602
520
Please hit Ctrl+C now if you do not wish to do this.
603
 
""" % (conffile, jailconffile, conf_hfile)
 
521
""" % (conffile, conf_hfile)
604
522
 
605
523
        # Get information from the administrator
606
524
        # If EOF is encountered at any time during the questioning, just exit
633
551
        "Must be an integer between 0 and 65535." % repr(db_port))
634
552
        return 1
635
553
 
636
 
    # Write lib/conf/conf.py
 
554
    # Write www/conf/conf.py
637
555
 
638
556
    try:
639
557
        conf = open(conffile, "w")
652
570
        print "IO error(%s): %s" % (errno, strerror)
653
571
        sys.exit(1)
654
572
 
655
 
    print "Successfully wrote lib/conf/conf.py"
656
 
 
657
 
    # Write conf/jailconf.py
658
 
 
659
 
    try:
660
 
        conf = open(jailconffile, "w")
661
 
 
662
 
        # In the "in-jail" version of conf, we don't need MOST of the details
663
 
        # (it would be a security risk to have them here).
664
 
        # So we just write root_dir, and jail_base is "/".
665
 
        # (jail_base being "/" means "jail-relative" paths are relative to "/"
666
 
        # when inside the jail.)
667
 
        conf.write("""# IVLE Configuration File
668
 
# conf.py
669
 
# Miscellaneous application settings
670
 
# (User jail version)
671
 
 
672
 
 
673
 
# In URL space, where in the site is IVLE located. (All URLs will be prefixed
674
 
# with this).
675
 
# eg. "/" or "/ivle".
676
 
root_dir = %s
677
 
 
678
 
# In the local file system, where are the student/user file spaces located.
679
 
# The user jails are expected to be located immediately in subdirectories of
680
 
# this location.
681
 
jail_base = '/'
682
 
 
683
 
# The hostname for serving publicly accessible pages
684
 
public_host = %s
685
 
""" % (repr(root_dir),repr(public_host)))
686
 
 
687
 
        conf.close()
688
 
    except IOError, (errno, strerror):
689
 
        print "IO error(%s): %s" % (errno, strerror)
690
 
        sys.exit(1)
691
 
 
692
 
    print "Successfully wrote lib/conf/jailconf.py"
 
573
    print "Successfully wrote www/conf/conf.py"
693
574
 
694
575
    # Write trampoline/conf.h
695
576
 
714
595
 * (Note that root is an implicit member of this list).
715
596
 */
716
597
static const int allowed_uids[] = { %s };
717
 
""" % (repr(jail_base)[1:-1], repr(allowed_uids_list)[1:-1]))
718
 
    # Note: The above uses PYTHON reprs, not C reprs
719
 
    # However they should be the same with the exception of the outer
720
 
    # characters, which are stripped off and replaced
 
598
""" % (jail_base, repr(allowed_uids_list)[1:-1]))
721
599
 
722
600
        conf.close()
723
601
    except IOError, (errno, strerror):
729
607
    print
730
608
    print "You may modify the configuration at any time by editing"
731
609
    print conffile
732
 
    print jailconffile
733
610
    print conf_hfile
734
611
    print
735
612
    return 0
756
633
    action_mkdir('jail/tmp', dry)
757
634
 
758
635
    # Copy all console and operating system files into the jail
759
 
    action_copylist(install_list.list_scripts, 'jail/opt/ivle', dry)
 
636
    action_copylist(install_list.list_console, 'jail/opt/ivle', dry)
760
637
    copy_os_files_jail(dry)
761
638
    # Chmod the python console
762
 
    action_chmod_x('jail/opt/ivle/scripts/python-console', dry)
763
 
    action_chmod_x('jail/opt/ivle/scripts/fileservice', dry)
 
639
    action_chmod_x('jail/opt/ivle/console/python-console', dry)
764
640
    
765
 
    # Also copy the IVLE lib directory into the jail
766
 
    # This is necessary for running certain scripts
767
 
    action_copylist(install_list.list_lib, 'jail/opt/ivle', dry)
768
 
    # IMPORTANT: The file jail/opt/ivle/lib/conf/conf.py contains details
769
 
    # which could compromise security if left in the jail (such as the DB
770
 
    # password).
771
 
    # The "safe" version is in jailconf.py. Delete conf.py and replace it with
772
 
    # jailconf.py.
773
 
    action_copyfile('lib/conf/jailconf.py',
774
 
        'jail/opt/ivle/lib/conf/conf.py', dry)
775
641
 
776
642
    # Compile .py files into .pyc or .pyo files
777
643
    compileall.compile_dir('www', quiet=True)
778
 
    compileall.compile_dir('lib', quiet=True)
779
 
    compileall.compile_dir('scripts', quiet=True)
780
 
    compileall.compile_dir('jail/opt/ivle/lib', quiet=True)
781
 
 
782
 
    # Set up ivle.pth inside the jail
783
 
    # Need to set /opt/ivle/lib to be on the import path
784
 
    ivle_pth = \
785
 
        "jail/usr/lib/python%s/site-packages/ivle.pth" % PYTHON_VERSION
786
 
    f = open(ivle_pth, 'w')
787
 
    f.write('/opt/ivle/lib\n')
788
 
    f.close()
 
644
    compileall.compile_dir('console', quiet=True)
789
645
 
790
646
    return 0
791
647
 
833
689
    # chown trampoline to root and set setuid bit
834
690
    action_chown_setuid(tramppath, dry)
835
691
 
836
 
    # Copy the www and lib directories using the list
 
692
    # Copy the www directory using the list
837
693
    action_copylist(install_list.list_www, ivle_install_dir, dry)
838
 
    action_copylist(install_list.list_lib, ivle_install_dir, dry)
839
694
 
840
695
    if not nojail:
841
696
        # Copy the local jail directory built by the build action
854
709
    ivle_pth = os.path.join(sys.prefix,
855
710
        "lib/python%s/site-packages/ivle.pth" % PYTHON_VERSION)
856
711
    ivle_www = os.path.join(ivle_install_dir, "www")
857
 
    ivle_lib = os.path.join(ivle_install_dir, "lib")
858
712
    write_ivle_pth = True
859
 
    write_ivle_lib_pth = True
860
713
    try:
861
714
        file = open(ivle_pth, 'r')
862
715
        for line in file:
863
716
            if line.strip() == ivle_www:
864
717
                write_ivle_pth = False
865
 
            elif line.strip() == ivle_lib:
866
 
                write_ivle_lib_pth = False
867
 
        file.close()
 
718
                break
868
719
    except (IOError, OSError):
869
720
        pass
870
721
    if write_ivle_pth:
871
722
        action_append(ivle_pth, ivle_www)
872
 
    if write_ivle_lib_pth:
873
 
        action_append(ivle_pth, ivle_lib)
874
723
 
875
724
    return 0
876
725
 
938
787
    if ret != 0:
939
788
        raise RunError(prog, ret)
940
789
 
941
 
def action_remove(path, dry):
942
 
    """Calls rmtree, deleting the target file if it exists."""
943
 
    try:
944
 
        print "rm -r", path
945
 
        if not dry:
946
 
            shutil.rmtree(path, True)
947
 
    except OSError, (err, msg):
948
 
        if err != errno.EEXIST:
949
 
            raise
950
 
        # Otherwise, didn't exist, so we don't care
951
 
 
952
790
def action_rename(src, dst, dry):
953
791
    """Calls rename. Deletes the target if it already exists."""
954
 
    action_remove(dst, dry)
 
792
    if os.access(dst, os.F_OK):
 
793
        print "rm -r", dst
 
794
        if not dry:
 
795
            shutil.rmtree(dst, True)
955
796
    print "mv ", src, dst
956
797
    if dry: return
957
798
    try:
977
818
    directories as necessary.
978
819
 
979
820
    See shutil.copytree."""
980
 
    action_remove(dst, dry)
 
821
    if os.access(dst, os.F_OK):
 
822
        print "rm -r", dst
 
823
        if not dry:
 
824
            shutil.rmtree(dst, True)
981
825
    print "cp -r", src, dst
982
826
    if dry: return
983
827
    shutil.copytree(src, dst, True)
986
830
    """Hard-links an entire directory tree. Same as copytree but the created
987
831
    files are hard-links not actual copies. Removes the existing destination.
988
832
    """
989
 
    action_remove(dst, dry)
 
833
    if os.access(dst, os.F_OK):
 
834
        print "rm -r", dst
 
835
        if not dry:
 
836
            shutil.rmtree(dst, True)
990
837
    print "<cp with hardlinks> -r", src, dst
991
838
    if dry: return
992
839
    common.makeuser.linktree(src, dst)