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

« back to all changes in this revision

Viewing changes to setup.py

  • Committer: drtomc
  • Date: 2008-02-08 04:30:55 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:436
fileservice: Make things less broken than they were. No claims of perfection yet! Unpacking form data with cgi.py is AWFUL.

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 www/conf/conf.py and trampoline/conf.h.
 
38
# Creates lib/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(), 'www'))
 
73
sys.path.append(os.path.join(os.getcwd(), 'lib'))
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',
103
142
    # Needed by matplotlib
104
143
    '/usr/lib/i686/cmov/libssl.so.0.9.8',
105
144
    '/usr/lib/i686/cmov/libcrypto.so.0.9.8',
228
267
# Database username"""))
229
268
config_options.append(ConfigOption("db_password", "",
230
269
    """Password for DB server login:
231
 
    (Caution: This password is stored in plaintext in www/conf/conf.py)""",
 
270
    (Caution: This password is stored in plaintext in lib/conf/conf.py)""",
232
271
    """
233
272
# Database password"""))
234
273
 
237
276
# of setup besides conf, so we need to know them.
238
277
# Also this allows you to hit Return to accept the existing value.
239
278
try:
240
 
    confmodule = __import__("www/conf/conf")
 
279
    confmodule = __import__("lib/conf/conf")
241
280
    for opt in config_options:
242
281
        try:
243
282
            globals()[opt.option_name] = confmodule.__dict__[opt.option_name]
352
391
to rebuild/install), just provide ivle_install_dir as the IVLE trunk
353
392
directory, and run build/install one time.
354
393
 
355
 
Creates www/conf/conf.py and trampoline/conf.h.
 
394
Creates lib/conf/conf.py and trampoline/conf.h.
356
395
 
357
396
Args are:"""
358
397
        for opt in config_options:
402
441
def listmake(args):
403
442
    # We build two separate lists, by walking www and console
404
443
    list_www = build_list_py_files('www')
405
 
    list_console = build_list_py_files('console')
 
444
    list_lib = build_list_py_files('lib')
 
445
    list_scripts = build_list_py_files('scripts')
406
446
    list_subjects = build_list_py_files('subjects', no_top_level=True)
407
447
    list_problems = build_list_py_files('problems', no_top_level=True)
408
448
    # Make sure that the files generated by conf are in the list
409
449
    # (since listmake is typically run before conf)
410
 
    if "www/conf/conf.py" not in list_www:
411
 
        list_www.append("www/conf/conf.py")
 
450
    if "lib/conf/conf.py" not in list_lib:
 
451
        list_lib.append("lib/conf/conf.py")
412
452
    # Make sure that console/python-console is in the list
413
 
    if "console/python-console" not in list_console:
414
 
        list_console.append("console/python-console")
 
453
    if "scripts/python-console" not in list_scripts:
 
454
        list_scripts.append("scripts/python-console")
 
455
    if "scripts/fileservice" not in list_scripts:
 
456
        list_scripts.append("scripts/fileservice")
415
457
    # Write these out to a file
416
458
    cwd = os.getcwd()
417
459
    # the files that will be created/overwritten
431
473
list_www = """)
432
474
        writelist_pretty(file, list_www)
433
475
        file.write("""
434
 
# List of all installable files in console directory.
435
 
list_console = """)
436
 
        writelist_pretty(file, list_console)
 
476
# List of all installable files in lib directory.
 
477
list_lib = """)
 
478
        writelist_pretty(file, list_lib)
 
479
        file.write("""
 
480
# List of all installable files in scripts directory.
 
481
list_scripts = """)
 
482
        writelist_pretty(file, list_scripts)
437
483
        file.write("""
438
484
# List of all installable files in subjects directory.
439
485
# This is to install sample subjects and material.
494
540
 
495
541
    cwd = os.getcwd()
496
542
    # the files that will be created/overwritten
497
 
    conffile = os.path.join(cwd, "www/conf/conf.py")
 
543
    conffile = os.path.join(cwd, "lib/conf/conf.py")
 
544
    jailconffile = os.path.join(cwd, "lib/conf/jailconf.py")
498
545
    conf_hfile = os.path.join(cwd, "trampoline/conf.h")
499
546
 
500
547
    # Get command-line arguments to avoid asking questions.
514
561
        print """This tool will create the following files:
515
562
    %s
516
563
    %s
 
564
    %s
517
565
prompting you for details about your configuration. The file will be
518
566
overwritten if it already exists. It will *not* install or deploy IVLE.
519
567
 
520
568
Please hit Ctrl+C now if you do not wish to do this.
521
 
""" % (conffile, conf_hfile)
 
569
""" % (conffile, jailconffile, conf_hfile)
522
570
 
523
571
        # Get information from the administrator
524
572
        # If EOF is encountered at any time during the questioning, just exit
551
599
        "Must be an integer between 0 and 65535." % repr(db_port))
552
600
        return 1
553
601
 
554
 
    # Write www/conf/conf.py
 
602
    # Write lib/conf/conf.py
555
603
 
556
604
    try:
557
605
        conf = open(conffile, "w")
570
618
        print "IO error(%s): %s" % (errno, strerror)
571
619
        sys.exit(1)
572
620
 
573
 
    print "Successfully wrote www/conf/conf.py"
 
621
    print "Successfully wrote lib/conf/conf.py"
 
622
 
 
623
    # Write conf/jailconf.py
 
624
 
 
625
    try:
 
626
        conf = open(jailconffile, "w")
 
627
 
 
628
        # In the "in-jail" version of conf, we don't need MOST of the details
 
629
        # (it would be a security risk to have them here).
 
630
        # So we just write root_dir, and jail_base is "/".
 
631
        # (jail_base being "/" means "jail-relative" paths are relative to "/"
 
632
        # when inside the jail.)
 
633
        conf.write("""# IVLE Configuration File
 
634
# conf.py
 
635
# Miscellaneous application settings
 
636
# (User jail version)
 
637
 
 
638
 
 
639
# In URL space, where in the site is IVLE located. (All URLs will be prefixed
 
640
# with this).
 
641
# eg. "/" or "/ivle".
 
642
root_dir = %s
 
643
 
 
644
# In the local file system, where are the student/user file spaces located.
 
645
# The user jails are expected to be located immediately in subdirectories of
 
646
# this location.
 
647
jail_base = '/'
 
648
 
 
649
# The hostname for serving publicly accessible pages
 
650
public_host = %s
 
651
""" % (repr(root_dir),repr(public_host)))
 
652
 
 
653
        conf.close()
 
654
    except IOError, (errno, strerror):
 
655
        print "IO error(%s): %s" % (errno, strerror)
 
656
        sys.exit(1)
 
657
 
 
658
    print "Successfully wrote lib/conf/jailconf.py"
574
659
 
575
660
    # Write trampoline/conf.h
576
661
 
595
680
 * (Note that root is an implicit member of this list).
596
681
 */
597
682
static const int allowed_uids[] = { %s };
598
 
""" % (jail_base, repr(allowed_uids_list)[1:-1]))
 
683
""" % (repr(jail_base)[1:-1], repr(allowed_uids_list)[1:-1]))
 
684
    # Note: The above uses PYTHON reprs, not C reprs
 
685
    # However they should be the same with the exception of the outer
 
686
    # characters, which are stripped off and replaced
599
687
 
600
688
        conf.close()
601
689
    except IOError, (errno, strerror):
607
695
    print
608
696
    print "You may modify the configuration at any time by editing"
609
697
    print conffile
 
698
    print jailconffile
610
699
    print conf_hfile
611
700
    print
612
701
    return 0
633
722
    action_mkdir('jail/tmp', dry)
634
723
 
635
724
    # Copy all console and operating system files into the jail
636
 
    action_copylist(install_list.list_console, 'jail/opt/ivle', dry)
 
725
    action_copylist(install_list.list_scripts, 'jail/opt/ivle', dry)
637
726
    copy_os_files_jail(dry)
638
727
    # Chmod the python console
639
 
    action_chmod_x('jail/opt/ivle/console/python-console', dry)
 
728
    action_chmod_x('jail/opt/ivle/scripts/python-console', dry)
 
729
    action_chmod_x('jail/opt/ivle/scripts/fileservice', dry)
640
730
    
 
731
    # Also copy the IVLE lib directory into the jail
 
732
    # This is necessary for running certain scripts
 
733
    action_copylist(install_list.list_lib, 'jail/opt/ivle', dry)
 
734
    # IMPORTANT: The file jail/opt/ivle/lib/conf/conf.py contains details
 
735
    # which could compromise security if left in the jail (such as the DB
 
736
    # password).
 
737
    # The "safe" version is in jailconf.py. Delete conf.py and replace it with
 
738
    # jailconf.py.
 
739
    action_copyfile('lib/conf/jailconf.py',
 
740
        'jail/opt/ivle/lib/conf/conf.py', dry)
641
741
 
642
742
    # Compile .py files into .pyc or .pyo files
643
743
    compileall.compile_dir('www', quiet=True)
644
 
    compileall.compile_dir('console', quiet=True)
 
744
    compileall.compile_dir('lib', quiet=True)
 
745
    compileall.compile_dir('scripts', quiet=True)
 
746
    compileall.compile_dir('jail/opt/ivle/lib', quiet=True)
 
747
 
 
748
    # Set up ivle.pth inside the jail
 
749
    # Need to set /opt/ivle/lib to be on the import path
 
750
    ivle_pth = \
 
751
        "jail/usr/lib/python%s/site-packages/ivle.pth" % PYTHON_VERSION
 
752
    f = open(ivle_pth, 'w')
 
753
    f.write('/opt/ivle/lib\n')
 
754
    f.close()
645
755
 
646
756
    return 0
647
757
 
689
799
    # chown trampoline to root and set setuid bit
690
800
    action_chown_setuid(tramppath, dry)
691
801
 
692
 
    # Copy the www directory using the list
 
802
    # Copy the www and lib directories using the list
693
803
    action_copylist(install_list.list_www, ivle_install_dir, dry)
 
804
    action_copylist(install_list.list_lib, ivle_install_dir, dry)
694
805
 
695
806
    if not nojail:
696
807
        # Copy the local jail directory built by the build action
709
820
    ivle_pth = os.path.join(sys.prefix,
710
821
        "lib/python%s/site-packages/ivle.pth" % PYTHON_VERSION)
711
822
    ivle_www = os.path.join(ivle_install_dir, "www")
 
823
    ivle_lib = os.path.join(ivle_install_dir, "lib")
712
824
    write_ivle_pth = True
 
825
    write_ivle_lib_pth = True
713
826
    try:
714
827
        file = open(ivle_pth, 'r')
715
828
        for line in file:
716
829
            if line.strip() == ivle_www:
717
830
                write_ivle_pth = False
718
 
                break
 
831
            elif line.strip() == ivle_lib:
 
832
                write_ivle_lib_pth = False
 
833
        file.close()
719
834
    except (IOError, OSError):
720
835
        pass
721
836
    if write_ivle_pth:
722
837
        action_append(ivle_pth, ivle_www)
 
838
    if write_ivle_lib_pth:
 
839
        action_append(ivle_pth, ivle_lib)
723
840
 
724
841
    return 0
725
842
 
787
904
    if ret != 0:
788
905
        raise RunError(prog, ret)
789
906
 
 
907
def action_remove(path, dry):
 
908
    """Calls rmtree, deleting the target file if it exists."""
 
909
    try:
 
910
        print "rm -r", path
 
911
        if not dry:
 
912
            shutil.rmtree(path, True)
 
913
    except OSError, (err, msg):
 
914
        if err != errno.EEXIST:
 
915
            raise
 
916
        # Otherwise, didn't exist, so we don't care
 
917
 
790
918
def action_rename(src, dst, dry):
791
919
    """Calls rename. Deletes the target if it already exists."""
792
 
    if os.access(dst, os.F_OK):
793
 
        print "rm -r", dst
794
 
        if not dry:
795
 
            shutil.rmtree(dst, True)
 
920
    action_remove(dst, dry)
796
921
    print "mv ", src, dst
797
922
    if dry: return
798
923
    try:
818
943
    directories as necessary.
819
944
 
820
945
    See shutil.copytree."""
821
 
    if os.access(dst, os.F_OK):
822
 
        print "rm -r", dst
823
 
        if not dry:
824
 
            shutil.rmtree(dst, True)
 
946
    action_remove(dst, dry)
825
947
    print "cp -r", src, dst
826
948
    if dry: return
827
949
    shutil.copytree(src, dst, True)
830
952
    """Hard-links an entire directory tree. Same as copytree but the created
831
953
    files are hard-links not actual copies. Removes the existing destination.
832
954
    """
833
 
    if os.access(dst, os.F_OK):
834
 
        print "rm -r", dst
835
 
        if not dry:
836
 
            shutil.rmtree(dst, True)
 
955
    action_remove(dst, dry)
837
956
    print "<cp with hardlinks> -r", src, dst
838
957
    if dry: return
839
958
    common.makeuser.linktree(src, dst)