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

« back to all changes in this revision

Viewing changes to setup.py

  • Committer: stevenbird
  • Date: 2008-02-16 01:18:46 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:481
reverted change that added a command-line flag to specify that an account should be enabled as this bypasses creating the jail

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',
179
218
# In the local file system, where are the per-subject file spaces located.
180
219
# The individual subject directories are expected to be located immediately
181
220
# in subdirectories of this location."""))
 
221
config_options.append(ConfigOption("problems_base",
 
222
    "/home/informatics/problems",
 
223
    """Root directory where the problem directories (containing
 
224
subject-independent problem sheets) are stored (on the local file
 
225
system):""",
 
226
    """
 
227
# In the local file system, where are the subject-independent problem sheet
 
228
# file spaces located."""))
182
229
config_options.append(ConfigOption("public_host", "public.localhost",
183
230
    """Hostname which will cause the server to go into "public mode",
184
231
providing login-free access to student's published work:""",
220
267
# Database username"""))
221
268
config_options.append(ConfigOption("db_password", "",
222
269
    """Password for DB server login:
223
 
    (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)""",
224
271
    """
225
272
# 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."""))
226
307
 
227
308
# Try importing existing conf, but if we can't just set up defaults
228
309
# The reason for this is that these settings are used by other phases
229
310
# of setup besides conf, so we need to know them.
230
311
# Also this allows you to hit Return to accept the existing value.
231
312
try:
232
 
    confmodule = __import__("www/conf/conf")
 
313
    confmodule = __import__("lib/conf/conf")
233
314
    for opt in config_options:
234
315
        try:
235
316
            globals()[opt.option_name] = confmodule.__dict__[opt.option_name]
344
425
to rebuild/install), just provide ivle_install_dir as the IVLE trunk
345
426
directory, and run build/install one time.
346
427
 
347
 
Creates www/conf/conf.py and trampoline/conf.h.
 
428
Creates lib/conf/conf.py and trampoline/conf.h.
348
429
 
349
430
Args are:"""
350
431
        for opt in config_options:
377
458
Copy subjects/ to subjects directory (unless --nosubjects specified).
378
459
 
379
460
--nojail        Do not copy the jail.
380
 
--nosubjects    Do not copy the subjects.
 
461
--nosubjects    Do not copy the subjects and problems directories.
381
462
--dry | -n  Print out the actions but don't do anything."""
382
463
    elif operation == 'updatejails':
383
464
        print """sudo python setup.py updatejails [--dry|-n]
394
475
def listmake(args):
395
476
    # We build two separate lists, by walking www and console
396
477
    list_www = build_list_py_files('www')
397
 
    list_console = build_list_py_files('console')
 
478
    list_lib = build_list_py_files('lib')
398
479
    list_subjects = build_list_py_files('subjects', no_top_level=True)
 
480
    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
    ]
399
486
    # Make sure that the files generated by conf are in the list
400
487
    # (since listmake is typically run before conf)
401
 
    if "www/conf/conf.py" not in list_www:
402
 
        list_www.append("www/conf/conf.py")
403
 
    # Make sure that console/python-console is in the list
404
 
    if "console/python-console" not in list_console:
405
 
        list_console.append("console/python-console")
 
488
    if "lib/conf/conf.py" not in list_lib:
 
489
        list_lib.append("lib/conf/conf.py")
406
490
    # Write these out to a file
407
491
    cwd = os.getcwd()
408
492
    # the files that will be created/overwritten
422
506
list_www = """)
423
507
        writelist_pretty(file, list_www)
424
508
        file.write("""
425
 
# List of all installable files in console directory.
426
 
list_console = """)
427
 
        writelist_pretty(file, list_console)
 
509
# List of all installable files in lib directory.
 
510
list_lib = """)
 
511
        writelist_pretty(file, list_lib)
 
512
        file.write("""
 
513
# List of all installable files in scripts directory.
 
514
list_scripts = """)
 
515
        writelist_pretty(file, list_scripts)
428
516
        file.write("""
429
517
# List of all installable files in subjects directory.
430
518
# This is to install sample subjects and material.
431
519
list_subjects = """)
432
520
        writelist_pretty(file, list_subjects)
 
521
        file.write("""
 
522
# List of all installable files in problems directory.
 
523
# This is to install sample exercise material.
 
524
list_problems = """)
 
525
        writelist_pretty(file, list_problems)
433
526
 
434
527
        file.close()
435
528
    except IOError, (errno, strerror):
480
573
 
481
574
    cwd = os.getcwd()
482
575
    # the files that will be created/overwritten
483
 
    conffile = os.path.join(cwd, "www/conf/conf.py")
 
576
    conffile = os.path.join(cwd, "lib/conf/conf.py")
 
577
    jailconffile = os.path.join(cwd, "lib/conf/jailconf.py")
484
578
    conf_hfile = os.path.join(cwd, "trampoline/conf.h")
485
579
 
486
580
    # Get command-line arguments to avoid asking questions.
500
594
        print """This tool will create the following files:
501
595
    %s
502
596
    %s
 
597
    %s
503
598
prompting you for details about your configuration. The file will be
504
599
overwritten if it already exists. It will *not* install or deploy IVLE.
505
600
 
506
601
Please hit Ctrl+C now if you do not wish to do this.
507
 
""" % (conffile, conf_hfile)
 
602
""" % (conffile, jailconffile, conf_hfile)
508
603
 
509
604
        # Get information from the administrator
510
605
        # If EOF is encountered at any time during the questioning, just exit
537
632
        "Must be an integer between 0 and 65535." % repr(db_port))
538
633
        return 1
539
634
 
540
 
    # Write www/conf/conf.py
 
635
    # Write lib/conf/conf.py
541
636
 
542
637
    try:
543
638
        conf = open(conffile, "w")
556
651
        print "IO error(%s): %s" % (errno, strerror)
557
652
        sys.exit(1)
558
653
 
559
 
    print "Successfully wrote www/conf/conf.py"
 
654
    print "Successfully wrote lib/conf/conf.py"
 
655
 
 
656
    # Write conf/jailconf.py
 
657
 
 
658
    try:
 
659
        conf = open(jailconffile, "w")
 
660
 
 
661
        # In the "in-jail" version of conf, we don't need MOST of the details
 
662
        # (it would be a security risk to have them here).
 
663
        # So we just write root_dir, and jail_base is "/".
 
664
        # (jail_base being "/" means "jail-relative" paths are relative to "/"
 
665
        # when inside the jail.)
 
666
        conf.write("""# IVLE Configuration File
 
667
# conf.py
 
668
# Miscellaneous application settings
 
669
# (User jail version)
 
670
 
 
671
 
 
672
# In URL space, where in the site is IVLE located. (All URLs will be prefixed
 
673
# with this).
 
674
# eg. "/" or "/ivle".
 
675
root_dir = %s
 
676
 
 
677
# In the local file system, where are the student/user file spaces located.
 
678
# The user jails are expected to be located immediately in subdirectories of
 
679
# this location.
 
680
jail_base = '/'
 
681
 
 
682
# The hostname for serving publicly accessible pages
 
683
public_host = %s
 
684
""" % (repr(root_dir),repr(public_host)))
 
685
 
 
686
        conf.close()
 
687
    except IOError, (errno, strerror):
 
688
        print "IO error(%s): %s" % (errno, strerror)
 
689
        sys.exit(1)
 
690
 
 
691
    print "Successfully wrote lib/conf/jailconf.py"
560
692
 
561
693
    # Write trampoline/conf.h
562
694
 
581
713
 * (Note that root is an implicit member of this list).
582
714
 */
583
715
static const int allowed_uids[] = { %s };
584
 
""" % (jail_base, repr(allowed_uids_list)[1:-1]))
 
716
""" % (repr(jail_base)[1:-1], repr(allowed_uids_list)[1:-1]))
 
717
    # Note: The above uses PYTHON reprs, not C reprs
 
718
    # However they should be the same with the exception of the outer
 
719
    # characters, which are stripped off and replaced
585
720
 
586
721
        conf.close()
587
722
    except IOError, (errno, strerror):
593
728
    print
594
729
    print "You may modify the configuration at any time by editing"
595
730
    print conffile
 
731
    print jailconffile
596
732
    print conf_hfile
597
733
    print
598
734
    return 0
619
755
    action_mkdir('jail/tmp', dry)
620
756
 
621
757
    # Copy all console and operating system files into the jail
622
 
    action_copylist(install_list.list_console, 'jail/opt/ivle', dry)
 
758
    action_copylist(install_list.list_scripts, 'jail/opt/ivle', dry)
623
759
    copy_os_files_jail(dry)
624
760
    # Chmod the python console
625
 
    action_chmod_x('jail/opt/ivle/console/python-console', dry)
 
761
    action_chmod_x('jail/opt/ivle/scripts/python-console', dry)
 
762
    action_chmod_x('jail/opt/ivle/scripts/fileservice', dry)
626
763
    
 
764
    # Also copy the IVLE lib directory into the jail
 
765
    # This is necessary for running certain scripts
 
766
    action_copylist(install_list.list_lib, 'jail/opt/ivle', dry)
 
767
    # IMPORTANT: The file jail/opt/ivle/lib/conf/conf.py contains details
 
768
    # which could compromise security if left in the jail (such as the DB
 
769
    # password).
 
770
    # The "safe" version is in jailconf.py. Delete conf.py and replace it with
 
771
    # jailconf.py.
 
772
    action_copyfile('lib/conf/jailconf.py',
 
773
        'jail/opt/ivle/lib/conf/conf.py', dry)
627
774
 
628
775
    # Compile .py files into .pyc or .pyo files
629
776
    compileall.compile_dir('www', quiet=True)
630
 
    compileall.compile_dir('console', quiet=True)
 
777
    compileall.compile_dir('lib', quiet=True)
 
778
    compileall.compile_dir('scripts', quiet=True)
 
779
    compileall.compile_dir('jail/opt/ivle/lib', quiet=True)
 
780
 
 
781
    # Set up ivle.pth inside the jail
 
782
    # Need to set /opt/ivle/lib to be on the import path
 
783
    ivle_pth = \
 
784
        "jail/usr/lib/python%s/site-packages/ivle.pth" % PYTHON_VERSION
 
785
    f = open(ivle_pth, 'w')
 
786
    f.write('/opt/ivle/lib\n')
 
787
    f.close()
631
788
 
632
789
    return 0
633
790
 
675
832
    # chown trampoline to root and set setuid bit
676
833
    action_chown_setuid(tramppath, dry)
677
834
 
678
 
    # Copy the www directory using the list
 
835
    # Copy the www and lib directories using the list
679
836
    action_copylist(install_list.list_www, ivle_install_dir, dry)
 
837
    action_copylist(install_list.list_lib, ivle_install_dir, dry)
680
838
 
681
839
    if not nojail:
682
840
        # Copy the local jail directory built by the build action
684
842
        # for all the students' jails).
685
843
        action_copytree('jail', os.path.join(jail_base, 'template'), dry)
686
844
    if not nosubjects:
687
 
        # Copy the subjects directory across
 
845
        # Copy the subjects and problems directories across
688
846
        action_copylist(install_list.list_subjects, subjects_base, dry,
689
847
            srcdir="./subjects")
 
848
        action_copylist(install_list.list_problems, problems_base, dry,
 
849
            srcdir="./problems")
690
850
 
691
851
    # Append IVLE path to ivle.pth in python site packages
692
852
    # (Unless it's already there)
693
853
    ivle_pth = os.path.join(sys.prefix,
694
854
        "lib/python%s/site-packages/ivle.pth" % PYTHON_VERSION)
695
855
    ivle_www = os.path.join(ivle_install_dir, "www")
 
856
    ivle_lib = os.path.join(ivle_install_dir, "lib")
696
857
    write_ivle_pth = True
 
858
    write_ivle_lib_pth = True
697
859
    try:
698
860
        file = open(ivle_pth, 'r')
699
861
        for line in file:
700
862
            if line.strip() == ivle_www:
701
863
                write_ivle_pth = False
702
 
                break
 
864
            elif line.strip() == ivle_lib:
 
865
                write_ivle_lib_pth = False
 
866
        file.close()
703
867
    except (IOError, OSError):
704
868
        pass
705
869
    if write_ivle_pth:
706
870
        action_append(ivle_pth, ivle_www)
 
871
    if write_ivle_lib_pth:
 
872
        action_append(ivle_pth, ivle_lib)
707
873
 
708
874
    return 0
709
875
 
771
937
    if ret != 0:
772
938
        raise RunError(prog, ret)
773
939
 
 
940
def action_remove(path, dry):
 
941
    """Calls rmtree, deleting the target file if it exists."""
 
942
    try:
 
943
        print "rm -r", path
 
944
        if not dry:
 
945
            shutil.rmtree(path, True)
 
946
    except OSError, (err, msg):
 
947
        if err != errno.EEXIST:
 
948
            raise
 
949
        # Otherwise, didn't exist, so we don't care
 
950
 
774
951
def action_rename(src, dst, dry):
775
952
    """Calls rename. Deletes the target if it already exists."""
776
 
    if os.access(dst, os.F_OK):
777
 
        print "rm -r", dst
778
 
        if not dry:
779
 
            shutil.rmtree(dst, True)
 
953
    action_remove(dst, dry)
780
954
    print "mv ", src, dst
781
955
    if dry: return
782
956
    try:
802
976
    directories as necessary.
803
977
 
804
978
    See shutil.copytree."""
805
 
    if os.access(dst, os.F_OK):
806
 
        print "rm -r", dst
807
 
        if not dry:
808
 
            shutil.rmtree(dst, True)
 
979
    action_remove(dst, dry)
809
980
    print "cp -r", src, dst
810
981
    if dry: return
811
982
    shutil.copytree(src, dst, True)
814
985
    """Hard-links an entire directory tree. Same as copytree but the created
815
986
    files are hard-links not actual copies. Removes the existing destination.
816
987
    """
817
 
    if os.access(dst, os.F_OK):
818
 
        print "rm -r", dst
819
 
        if not dry:
820
 
            shutil.rmtree(dst, True)
 
988
    action_remove(dst, dry)
821
989
    print "<cp with hardlinks> -r", src, dst
822
990
    if dry: return
823
991
    common.makeuser.linktree(src, dst)
892
1060
            | stat.S_ISUID | stat.S_IRUSR | stat.S_IWUSR)
893
1061
 
894
1062
def action_chmod_x(file, dry):
895
 
    """Chmod +xs a file (sets execute permission)."""
896
 
    print "chmod u+rwx", file
 
1063
    """Chmod 755 a file (sets permissions to rwxr-xr-x)."""
 
1064
    print "chmod 755", file
897
1065
    if not dry:
898
 
        os.chmod(file, stat.S_IXUSR | stat.S_IRUSR | stat.S_IWUSR)
 
1066
        os.chmod(file, stat.S_IXUSR | stat.S_IRUSR | stat.S_IWUSR
 
1067
            | stat.S_IXGRP | stat.S_IRGRP | stat.S_IXOTH | stat.S_IROTH)
899
1068
 
900
1069
def query_user(default, prompt):
901
1070
    """Prompts the user for a string, which is read from a line of stdin.