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

« back to all changes in this revision

Viewing changes to setup.py

  • Committer: mattgiuca
  • Date: 2008-02-05 01:41:15 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:409
Moved www/conf and www/common to a new directory lib. This separates the "web"
part of IVLE from what is becoming less web oriented (at least from Apache's
standpoint).
Modified setup.py to install this lib directory correctly and write conf in
the right place. Also adds the lib directory to ivle.pth.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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',
191
152
 
192
153
# Configuration options, defaults and descriptions
193
154
config_options = []
194
 
config_options.append(ConfigOption("root_dir", "/",
 
155
config_options.append(ConfigOption("root_dir", "/ivle",
195
156
    """Root directory where IVLE is located (in URL space):""",
196
157
    """
197
158
# In URL space, where in the site is IVLE located. (All URLs will be prefixed
270
231
    (Caution: This password is stored in plaintext in lib/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
476
403
    # We build two separate lists, by walking www and console
477
404
    list_www = build_list_py_files('www')
478
405
    list_lib = build_list_py_files('lib')
 
406
    list_console = build_list_py_files('console')
479
407
    list_subjects = build_list_py_files('subjects', no_top_level=True)
480
408
    list_problems = build_list_py_files('problems', no_top_level=True)
481
 
    list_scripts = [
482
 
        "scripts/python-console",
483
 
        "scripts/fileservice",
484
 
        "scripts/usrmgt-server",
485
 
    ]
486
409
    # Make sure that the files generated by conf are in the list
487
410
    # (since listmake is typically run before conf)
488
411
    if "lib/conf/conf.py" not in list_lib:
489
 
        list_lib.append("lib/conf/conf.py")
 
412
        list_www.append("lib/conf/conf.py")
 
413
    # Make sure that console/python-console is in the list
 
414
    if "console/python-console" not in list_console:
 
415
        list_console.append("console/python-console")
490
416
    # Write these out to a file
491
417
    cwd = os.getcwd()
492
418
    # the files that will be created/overwritten
510
436
list_lib = """)
511
437
        writelist_pretty(file, list_lib)
512
438
        file.write("""
513
 
# List of all installable files in scripts directory.
514
 
list_scripts = """)
515
 
        writelist_pretty(file, list_scripts)
 
439
# List of all installable files in console directory.
 
440
list_console = """)
 
441
        writelist_pretty(file, list_console)
516
442
        file.write("""
517
443
# List of all installable files in subjects directory.
518
444
# This is to install sample subjects and material.
568
494
        file.write(']\n')
569
495
 
570
496
def conf(args):
571
 
    global db_port, usrmgt_port
 
497
    global db_port
572
498
    # Set up some variables
573
499
 
574
500
    cwd = os.getcwd()
575
501
    # the files that will be created/overwritten
576
502
    conffile = os.path.join(cwd, "lib/conf/conf.py")
577
 
    jailconffile = os.path.join(cwd, "lib/conf/jailconf.py")
578
503
    conf_hfile = os.path.join(cwd, "trampoline/conf.h")
579
504
 
580
505
    # Get command-line arguments to avoid asking questions.
594
519
        print """This tool will create the following files:
595
520
    %s
596
521
    %s
597
 
    %s
598
522
prompting you for details about your configuration. The file will be
599
523
overwritten if it already exists. It will *not* install or deploy IVLE.
600
524
 
601
525
Please hit Ctrl+C now if you do not wish to do this.
602
 
""" % (conffile, jailconffile, conf_hfile)
 
526
""" % (conffile, conf_hfile)
603
527
 
604
528
        # Get information from the administrator
605
529
        # If EOF is encountered at any time during the questioning, just exit
631
555
        "Invalid DB port (%s).\n"
632
556
        "Must be an integer between 0 and 65535." % repr(db_port))
633
557
        return 1
634
 
    try:
635
 
        usrmgt_port = int(usrmgt_port)
636
 
        if usrmgt_port < 0 or usrmgt_port >= 65536: raise ValueError()
637
 
    except ValueError:
638
 
        print >>sys.stderr, (
639
 
        "Invalid user management port (%s).\n"
640
 
        "Must be an integer between 0 and 65535." % repr(usrmgt_port))
641
 
        return 1
642
558
 
643
559
    # Write lib/conf/conf.py
644
560
 
661
577
 
662
578
    print "Successfully wrote lib/conf/conf.py"
663
579
 
664
 
    # Write conf/jailconf.py
665
 
 
666
 
    try:
667
 
        conf = open(jailconffile, "w")
668
 
 
669
 
        # In the "in-jail" version of conf, we don't need MOST of the details
670
 
        # (it would be a security risk to have them here).
671
 
        # So we just write root_dir, and jail_base is "/".
672
 
        # (jail_base being "/" means "jail-relative" paths are relative to "/"
673
 
        # when inside the jail.)
674
 
        conf.write("""# IVLE Configuration File
675
 
# conf.py
676
 
# Miscellaneous application settings
677
 
# (User jail version)
678
 
 
679
 
 
680
 
# In URL space, where in the site is IVLE located. (All URLs will be prefixed
681
 
# with this).
682
 
# eg. "/" or "/ivle".
683
 
root_dir = %s
684
 
 
685
 
# In the local file system, where are the student/user file spaces located.
686
 
# The user jails are expected to be located immediately in subdirectories of
687
 
# this location.
688
 
jail_base = '/'
689
 
 
690
 
# The hostname for serving publicly accessible pages
691
 
public_host = %s
692
 
""" % (repr(root_dir),repr(public_host)))
693
 
 
694
 
        conf.close()
695
 
    except IOError, (errno, strerror):
696
 
        print "IO error(%s): %s" % (errno, strerror)
697
 
        sys.exit(1)
698
 
 
699
 
    print "Successfully wrote lib/conf/jailconf.py"
700
 
 
701
580
    # Write trampoline/conf.h
702
581
 
703
582
    try:
721
600
 * (Note that root is an implicit member of this list).
722
601
 */
723
602
static const int allowed_uids[] = { %s };
724
 
""" % (repr(jail_base)[1:-1], repr(allowed_uids_list)[1:-1]))
725
 
    # Note: The above uses PYTHON reprs, not C reprs
726
 
    # However they should be the same with the exception of the outer
727
 
    # characters, which are stripped off and replaced
 
603
""" % (jail_base, repr(allowed_uids_list)[1:-1]))
728
604
 
729
605
        conf.close()
730
606
    except IOError, (errno, strerror):
736
612
    print
737
613
    print "You may modify the configuration at any time by editing"
738
614
    print conffile
739
 
    print jailconffile
740
615
    print conf_hfile
741
616
    print
742
617
    return 0
763
638
    action_mkdir('jail/tmp', dry)
764
639
 
765
640
    # Copy all console and operating system files into the jail
766
 
    action_copylist(install_list.list_scripts, 'jail/opt/ivle', dry)
 
641
    action_copylist(install_list.list_console, 'jail/opt/ivle', dry)
767
642
    copy_os_files_jail(dry)
768
643
    # Chmod the python console
769
 
    action_chmod_x('jail/opt/ivle/scripts/python-console', dry)
770
 
    action_chmod_x('jail/opt/ivle/scripts/fileservice', dry)
 
644
    action_chmod_x('jail/opt/ivle/console/python-console', dry)
771
645
    
772
 
    # Also copy the IVLE lib directory into the jail
773
 
    # This is necessary for running certain scripts
774
 
    action_copylist(install_list.list_lib, 'jail/opt/ivle', dry)
775
 
    # IMPORTANT: The file jail/opt/ivle/lib/conf/conf.py contains details
776
 
    # which could compromise security if left in the jail (such as the DB
777
 
    # password).
778
 
    # The "safe" version is in jailconf.py. Delete conf.py and replace it with
779
 
    # jailconf.py.
780
 
    action_copyfile('lib/conf/jailconf.py',
781
 
        'jail/opt/ivle/lib/conf/conf.py', dry)
782
646
 
783
647
    # Compile .py files into .pyc or .pyo files
784
648
    compileall.compile_dir('www', quiet=True)
785
 
    compileall.compile_dir('lib', quiet=True)
786
 
    compileall.compile_dir('scripts', quiet=True)
787
 
    compileall.compile_dir('jail/opt/ivle/lib', quiet=True)
788
 
 
789
 
    # Set up ivle.pth inside the jail
790
 
    # Need to set /opt/ivle/lib to be on the import path
791
 
    ivle_pth = \
792
 
        "jail/usr/lib/python%s/site-packages/ivle.pth" % PYTHON_VERSION
793
 
    f = open(ivle_pth, 'w')
794
 
    f.write('/opt/ivle/lib\n')
795
 
    f.close()
 
649
    compileall.compile_dir('console', quiet=True)
796
650
 
797
651
    return 0
798
652
 
945
799
    if ret != 0:
946
800
        raise RunError(prog, ret)
947
801
 
948
 
def action_remove(path, dry):
949
 
    """Calls rmtree, deleting the target file if it exists."""
950
 
    try:
951
 
        print "rm -r", path
952
 
        if not dry:
953
 
            shutil.rmtree(path, True)
954
 
    except OSError, (err, msg):
955
 
        if err != errno.EEXIST:
956
 
            raise
957
 
        # Otherwise, didn't exist, so we don't care
958
 
 
959
802
def action_rename(src, dst, dry):
960
803
    """Calls rename. Deletes the target if it already exists."""
961
 
    action_remove(dst, dry)
 
804
    if os.access(dst, os.F_OK):
 
805
        print "rm -r", dst
 
806
        if not dry:
 
807
            shutil.rmtree(dst, True)
962
808
    print "mv ", src, dst
963
809
    if dry: return
964
810
    try:
984
830
    directories as necessary.
985
831
 
986
832
    See shutil.copytree."""
987
 
    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)
988
837
    print "cp -r", src, dst
989
838
    if dry: return
990
839
    shutil.copytree(src, dst, True)
993
842
    """Hard-links an entire directory tree. Same as copytree but the created
994
843
    files are hard-links not actual copies. Removes the existing destination.
995
844
    """
996
 
    action_remove(dst, dry)
 
845
    if os.access(dst, os.F_OK):
 
846
        print "rm -r", dst
 
847
        if not dry:
 
848
            shutil.rmtree(dst, True)
997
849
    print "<cp with hardlinks> -r", src, dst
998
850
    if dry: return
999
851
    common.makeuser.linktree(src, dst)