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

« back to all changes in this revision

Viewing changes to setup.py

  • Committer: mattgiuca
  • Date: 2008-06-16 12:31:27 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:780
dispatch/login.py: When displaying the login page, returns a 200, not a 403
    Forbidden.
    This is because "Forbidden" has the wrong semantic - it means "you will
    never get in here even if you auth", whereas we want to present the
    opportunity to auth.
    Some user agents interpret a 403 as defeat, and don't even present the
    page body.

Show diffs side-by-side

added added

removed removed

Lines of Context:
55
55
# Copy trampoline/trampoline to $target/bin.
56
56
# chown and chmod the installed trampoline.
57
57
# Copy www/ to $target.
58
 
# Copy jail/ to jails template directory (unless --nojail specified).
 
58
# Copy jail/ to jails __staging__ directory (unless --nojail specified).
59
59
 
60
60
import os
61
61
import stat
67
67
import mimetypes
68
68
import compileall
69
69
import getopt
 
70
import hashlib
 
71
import uuid
 
72
import pysvn
70
73
 
71
74
# Import modules from the website is tricky since they're in the www
72
75
# directory.
109
112
    '/lib/libuuid.so.1',
110
113
    '/usr/lib/libapr-1.so.0',
111
114
    '/usr/lib/libaprutil-1.so.0',
112
 
    '/usr/lib/libdb-4.4.so',
 
115
    '/usr/lib/libapt-pkg-libc6.6-6.so.4.5',
 
116
    '/usr/lib/libdb-4.6.so',
113
117
    '/usr/lib/libexpat.so.1',
114
118
    '/usr/lib/libgcrypt.so.11',
115
119
    '/usr/lib/libgnutls.so.13',
119
123
    '/usr/lib/libkrb5.so.3',
120
124
    '/usr/lib/libkrb5support.so.0',
121
125
    '/usr/lib/liblber.so.2',
 
126
    '/usr/lib/liblber-2.4.so.2',
122
127
    '/usr/lib/libldap_r.so.2',
123
 
    '/usr/lib/libneon.so.26',
 
128
    '/usr/lib/libldap_r-2.4.so.2',
 
129
    '/usr/lib/libneon.so.27',
124
130
    '/usr/lib/libpq.so.5',
125
131
    '/usr/lib/libsasl2.so.2',
126
132
    '/usr/lib/libsqlite3.so.0',
161
167
    '/etc/matplotlibrc',
162
168
    # Needed for resolv
163
169
    '/lib/libnss_dns.so.2',
164
 
    #'/lib/libnss_mdns4.so',
 
170
    '/lib/libnss_mdns4_minimal.so.2',
165
171
    '/etc/hosts',
166
172
    '/etc/resolv.conf',
167
173
    #'/etc/hosts.conf',
168
174
    #'/etc/hostname',
169
175
    '/etc/nsswitch.conf',
170
176
    '/lib/libnss_files.so.2',
 
177
    # Needed for PIL
 
178
    '/usr/lib/libjpeg.so.62',
 
179
    # Needed by lxml
 
180
    '/usr/lib/libxslt.so.1',
 
181
    '/usr/lib/libexslt.so.0',
 
182
    # Needed by elementtree
 
183
    '/usr/lib/libtidy-0.99.so.0',
171
184
]
172
185
# Symlinks to make within the jail. Src mapped to dst.
173
186
JAIL_LINKS = {
177
190
JAIL_COPYTREES = {
178
191
    '/usr/lib/python%s' % PYTHON_VERSION:
179
192
        'jail/usr/lib/python%s' % PYTHON_VERSION,
 
193
    '/var/lib/python-support/python%s' % PYTHON_VERSION:
 
194
        'jail/var/lib/python-support/python%s' %PYTHON_VERSION,
180
195
    '/usr/share/matplotlib': 'jail/usr/share/matplotlib',
181
196
    '/etc/ld.so.conf.d': 'jail/etc/ld.so.conf.d',
 
197
    '/usr/share/pycentral': 'jail/usr/share/pycentral',
 
198
    '/usr/share/pycentral-data': 'jail/usr/share/pycentral-data',
 
199
    '/usr/share/nltk': 'jail/usr/share/nltk',
182
200
}
183
201
 
184
202
class ConfigOption:
237
255
    """
238
256
# In the local file system, where are the subject-independent exercise sheet
239
257
# file spaces located."""))
 
258
config_options.append(ConfigOption("tos_path",
 
259
    "/home/informatics/tos.html",
 
260
    """Location where the Terms of Service document is stored (on the local
 
261
    file system):""",
 
262
    """
 
263
# In the local file system, where is the Terms of Service document located."""))
 
264
config_options.append(ConfigOption("motd_path",
 
265
    "/home/informatics/motd.html",
 
266
    """Location where the Message of the Day document is stored (on the local
 
267
    file system):""",
 
268
    """
 
269
# In the local file system, where is the Message of the Day document
 
270
# located. This is an HTML file (just the body fragment), which will
 
271
# be displayed on the login page. It is optional."""))
240
272
config_options.append(ConfigOption("public_host", "public.localhost",
241
273
    """Hostname which will cause the server to go into "public mode",
242
274
providing login-free access to student's published work:""",
272
304
    """Database name:""",
273
305
    """
274
306
# Database name"""))
 
307
config_options.append(ConfigOption("db_forumdbname", "ivle_forum",
 
308
    """Forum Database name:""",
 
309
    """
 
310
# Forum Database name"""))
275
311
config_options.append(ConfigOption("db_user", "postgres",
276
312
    """Username for DB server login:""",
277
313
    """
377
413
# as necessary, and include it in the distribution.
378
414
listmake_mimetypes = ['text/x-python', 'text/html',
379
415
    'application/x-javascript', 'application/javascript',
380
 
    'text/css', 'image/png', 'application/xml']
 
416
    'text/css', 'image/png', 'image/gif', 'application/xml']
381
417
 
382
418
# Main function skeleton from Guido van Rossum
383
419
# http://www.artima.com/weblogs/viewpost.jsp?thread=4829
497
533
Copy trampoline/trampoline to $target/bin.
498
534
chown and chmod the installed trampoline.
499
535
Copy www/ to $target.
500
 
Copy jail/ to jails template directory (unless --nojail specified).
 
536
Copy jail/ to jails __staging__ directory (unless --nojail specified).
501
537
Copy subjects/ to subjects directory (unless --nosubjects specified).
502
538
 
503
539
--nojail        Do not copy the jail.
524
560
    list_scripts = [
525
561
        "scripts/python-console",
526
562
        "scripts/fileservice",
 
563
        "scripts/serveservice",
527
564
        "scripts/usrmgt-server",
 
565
        "scripts/diffservice",
528
566
    ]
529
567
    # Make sure that the files generated by conf are in the list
530
568
    # (since listmake is typically run before conf)
619
657
    conffile = os.path.join(cwd, "lib/conf/conf.py")
620
658
    jailconffile = os.path.join(cwd, "lib/conf/jailconf.py")
621
659
    conf_hfile = os.path.join(cwd, "trampoline/conf.h")
 
660
    phpBBconffile = os.path.join(cwd, "www/php/phpBB3/config.php")
 
661
    usrmgtserver_initdfile = os.path.join(cwd, "doc/setup/usrmgt-server.init")
622
662
 
623
663
    # Get command-line arguments to avoid asking questions.
624
664
 
638
678
    %s
639
679
    %s
640
680
    %s
 
681
    %s
 
682
    %s
641
683
prompting you for details about your configuration. The file will be
642
684
overwritten if it already exists. It will *not* install or deploy IVLE.
643
685
 
644
686
Please hit Ctrl+C now if you do not wish to do this.
645
 
""" % (conffile, jailconffile, conf_hfile)
 
687
""" % (conffile, jailconffile, conf_hfile, phpBBconffile, usrmgtserver_initdfile)
646
688
 
647
689
        # Get information from the administrator
648
690
        # If EOF is encountered at any time during the questioning, just exit
683
725
        "Must be an integer between 0 and 65535." % repr(usrmgt_port))
684
726
        return 1
685
727
 
 
728
    # Generate the forum secret
 
729
    forum_secret = hashlib.md5(uuid.uuid4().bytes).hexdigest()
 
730
 
686
731
    # Write lib/conf/conf.py
687
732
 
688
733
    try:
697
742
            conf.write('%s\n%s = %s\n' % (opt.comment, opt.option_name,
698
743
                repr(globals()[opt.option_name])))
699
744
 
 
745
        # Add the forum secret to the config file (regenerated each config)
 
746
        conf.write('forum_secret = "%s"\n' % (forum_secret))
 
747
 
700
748
        conf.close()
701
749
    except IOError, (errno, strerror):
702
750
        print "IO error(%s): %s" % (errno, strerror)
776
824
 
777
825
    print "Successfully wrote trampoline/conf.h"
778
826
 
 
827
    # Write www/php/phpBB3/config.php
 
828
 
 
829
    try:
 
830
        conf = open(phpBBconffile, "w")
 
831
        
 
832
        # php-pg work around
 
833
        if db_host == 'localhost':
 
834
            forumdb_host = '127.0.0.1'
 
835
        else:
 
836
            forumdb_host = db_host
 
837
 
 
838
        conf.write( """<?php
 
839
// phpBB 3.0.x auto-generated configuration file
 
840
// Do not change anything in this file!
 
841
$dbms = 'postgres';
 
842
$dbhost = '""" + forumdb_host + """';
 
843
$dbport = '""" + str(db_port) + """';
 
844
$dbname = '""" + db_forumdbname + """';
 
845
$dbuser = '""" + db_user + """';
 
846
$dbpasswd = '""" + db_password + """';
 
847
 
 
848
$table_prefix = 'phpbb_';
 
849
$acm_type = 'file';
 
850
$load_extensions = '';
 
851
@define('PHPBB_INSTALLED', true);
 
852
// @define('DEBUG', true);
 
853
//@define('DEBUG_EXTRA', true);
 
854
 
 
855
$forum_secret = '""" + forum_secret +"""';
 
856
?>"""   )
 
857
    
 
858
        conf.close()
 
859
    except IOError, (errno, strerror):
 
860
        print "IO error(%s): %s" % (errno, strerror)
 
861
        sys.exit(1)
 
862
 
 
863
    print "Successfully wrote www/php/phpBB3/config.php"
 
864
 
 
865
    # Write lib/conf/usrmgt-server.init
 
866
 
 
867
    try:
 
868
        conf = open(usrmgtserver_initdfile, "w")
 
869
 
 
870
        conf.write( '''#! /bin/sh
 
871
 
 
872
# Works for Ubuntu. Check before using on other distributions
 
873
 
 
874
### BEGIN INIT INFO
 
875
# Provides:          usrmgt-server
 
876
# Required-Start:    $syslog $networking $urandom
 
877
# Required-Stop:     $syslog
 
878
# Default-Start:     2 3 4 5
 
879
# Default-Stop:      1
 
880
# Short-Description: IVLE user management server
 
881
# Description:       Daemon connecting to the IVLE user management database.
 
882
### END INIT INFO
 
883
 
 
884
PATH=/sbin:/bin:/usr/sbin:/usr/bin
 
885
DESC="IVLE user management server"
 
886
NAME=usrmgt-server
 
887
DAEMON=/opt/ivle/scripts/$NAME
 
888
DAEMON_ARGS="''' + str(usrmgt_port) + ''' ''' + usrmgt_magic + '''"
 
889
PIDFILE=/var/run/$NAME.pid
 
890
SCRIPTNAME=/etc/init.d/usrmgt-server
 
891
 
 
892
# Exit if the daemon does not exist 
 
893
test -f $DAEMON || exit 0
 
894
 
 
895
# Load the VERBOSE setting and other rcS variables
 
896
[ -f /etc/default/rcS ] && . /etc/default/rcS
 
897
 
 
898
# Define LSB log_* functions.
 
899
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
 
900
. /lib/lsb/init-functions
 
901
 
 
902
#
 
903
# Function that starts the daemon/service
 
904
#
 
905
do_start()
 
906
{
 
907
        # Return
 
908
        #   0 if daemon has been started
 
909
        #   1 if daemon was already running
 
910
        #   2 if daemon could not be started
 
911
        start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
 
912
                || return 1
 
913
        start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
 
914
                $DAEMON_ARGS \
 
915
                || return 2
 
916
        # Add code here, if necessary, that waits for the process to be ready
 
917
        # to handle requests from services started subsequently which depend
 
918
        # on this one.  As a last resort, sleep for some time.
 
919
}
 
920
 
 
921
#
 
922
# Function that stops the daemon/service
 
923
#
 
924
do_stop()
 
925
{
 
926
        # Return
 
927
        #   0 if daemon has been stopped
 
928
        #   1 if daemon was already stopped
 
929
        #   2 if daemon could not be stopped
 
930
        #   other if a failure occurred
 
931
        start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
 
932
        RETVAL="$?"
 
933
        [ "$RETVAL" = 2 ] && return 2
 
934
        # Wait for children to finish too if this is a daemon that forks
 
935
        # and if the daemon is only ever run from this initscript.
 
936
        # If the above conditions are not satisfied then add some other code
 
937
        # that waits for the process to drop all resources that could be
 
938
        # needed by services started subsequently.  A last resort is to
 
939
        # sleep for some time.
 
940
        start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
 
941
        [ "$?" = 2 ] && return 2
 
942
        # Many daemons don't delete their pidfiles when they exit.
 
943
        rm -f $PIDFILE
 
944
        return "$RETVAL"
 
945
}
 
946
 
 
947
#
 
948
# Function that sends a SIGHUP to the daemon/service
 
949
#
 
950
do_reload() {
 
951
        #
 
952
        # If the daemon can reload its configuration without
 
953
        # restarting (for example, when it is sent a SIGHUP),
 
954
        # then implement that here.
 
955
        #
 
956
        start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
 
957
        return 0
 
958
}
 
959
 
 
960
case "$1" in
 
961
  start)
 
962
    [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
 
963
        do_start
 
964
        case "$?" in
 
965
                0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
 
966
                2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
 
967
        esac
 
968
        ;;
 
969
  stop)
 
970
        [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
 
971
        do_stop
 
972
        case "$?" in
 
973
                0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
 
974
                2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
 
975
        esac
 
976
        ;;
 
977
  #reload|force-reload)
 
978
        #
 
979
        # If do_reload() is not implemented then leave this commented out
 
980
        # and leave 'force-reload' as an alias for 'restart'.
 
981
        #
 
982
        #log_daemon_msg "Reloading $DESC" "$NAME"
 
983
        #do_reload
 
984
        #log_end_msg $?
 
985
        #;;
 
986
  restart|force-reload)
 
987
        #
 
988
        # If the "reload" option is implemented then remove the
 
989
        # 'force-reload' alias
 
990
        #
 
991
        log_daemon_msg "Restarting $DESC" "$NAME"
 
992
        do_stop
 
993
        case "$?" in
 
994
          0|1)
 
995
                do_start
 
996
                case "$?" in
 
997
                        0) log_end_msg 0 ;;
 
998
                        1) log_end_msg 1 ;; # Old process is still running
 
999
                        *) log_end_msg 1 ;; # Failed to start
 
1000
                esac
 
1001
                ;;
 
1002
          *)
 
1003
                # Failed to stop
 
1004
                log_end_msg 1
 
1005
                ;;
 
1006
        esac
 
1007
        ;;
 
1008
  *)
 
1009
        #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
 
1010
        echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
 
1011
        exit 3
 
1012
        ;;
 
1013
esac
 
1014
 
 
1015
:
 
1016
''')
 
1017
        
 
1018
        conf.close()
 
1019
    except IOError, (errno, strerror):
 
1020
        print "IO error(%s): %s" % (errno, strerror)
 
1021
        sys.exit(1)
 
1022
 
 
1023
    # fix permissions as the file contains the database password
 
1024
    try:
 
1025
        os.chmod('doc/setup/usrmgt-server.init', 0600)
 
1026
    except OSError, (errno, strerror):
 
1027
        print "WARNING: Couldn't chmod doc/setup/usrmgt-server.init:"
 
1028
        print "OS error(%s): %s" % (errno, strerror)
 
1029
 
 
1030
    print "Successfully wrote lib/conf/usrmgt-server.init"
 
1031
 
779
1032
    print
780
1033
    print "You may modify the configuration at any time by editing"
781
1034
    print conffile
782
1035
    print jailconffile
783
1036
    print conf_hfile
 
1037
    print phpBBconffile
 
1038
    print usrmgtserver_initdfile
784
1039
    print
785
1040
    return 0
786
1041
 
792
1047
 
793
1048
    if dry:
794
1049
        print "Dry run (no actions will be executed\n"
 
1050
    
 
1051
    # Find out the revison number
 
1052
    revnum = get_svn_revision()
 
1053
    print "Building Revision %s"%str(revnum)
 
1054
    if not dry:
 
1055
        vfile = open('BUILD-VERSION','w')
 
1056
        vfile.write(str(revnum) + '\n')
 
1057
        vfile.close()
795
1058
 
796
1059
    # Compile the trampoline
797
1060
    curdir = os.getcwd()
814
1077
    # Chmod the python console
815
1078
    action_chmod_x('jail/opt/ivle/scripts/python-console', dry)
816
1079
    action_chmod_x('jail/opt/ivle/scripts/fileservice', dry)
 
1080
    action_chmod_x('jail/opt/ivle/scripts/serveservice', dry)
817
1081
    
818
1082
    # Also copy the IVLE lib directory into the jail
819
1083
    # This is necessary for running certain scripts
897
1161
    action_copylist(install_list.list_lib, ivle_install_dir, dry)
898
1162
    
899
1163
    # Copy the php directory
900
 
    action_copytree('www/php/phpBB3',os.path.join(ivle_install_dir,'www/php/phpBB3'), 
901
 
    dry)
 
1164
    forum_dir = "www/php/phpBB3"
 
1165
    forum_path = os.path.join(ivle_install_dir, forum_dir)
 
1166
    action_copytree(forum_dir, forum_path, dry)
 
1167
    print "chown -R www-data:www-data %s" % forum_path
 
1168
    if not dry:
 
1169
        os.system("chown -R www-data:www-data %s" % forum_path)
902
1170
 
903
1171
    if not nojail:
904
1172
        # Copy the local jail directory built by the build action
905
 
        # to the jails template directory (it will be used as a template
906
 
        # for all the students' jails).
907
 
        action_copytree('jail', os.path.join(jail_base, 'template'), dry)
 
1173
        # to the jails __staging__ directory (it will be used to help build
 
1174
        # all the students' jails).
 
1175
        action_copytree('jail', os.path.join(jail_base, '__staging__'), dry)
908
1176
    if not nosubjects:
909
1177
        # Copy the subjects and exercises directories across
910
1178
        action_copylist(install_list.list_subjects, subjects_base, dry,
951
1219
        print >>sys.stderr, "(I need to chown some files)."
952
1220
        return 1
953
1221
 
954
 
    # Update the template jail directory in case it hasn't been installed
 
1222
    # Update the staging jail directory in case it hasn't been installed
955
1223
    # recently.
956
 
    action_copytree('jail', os.path.join(jail_base, 'template'), dry)
 
1224
    action_copytree('jail', os.path.join(jail_base, '__staging__'), dry)
957
1225
 
958
1226
    # Re-link all the files in all students jails.
959
1227
    for dir in os.listdir(jail_base):
960
 
        if dir == 'template': continue
 
1228
        if dir == '__staging__': continue
961
1229
        # First back up the student's home directory
962
1230
        temp_home = os.tmpnam()
963
1231
        action_rename(os.path.join(jail_base, dir, 'home'), temp_home, dry)
964
1232
        # Delete the student's jail and relink the jail files
965
 
        action_linktree(os.path.join(jail_base, 'template'),
 
1233
        action_linktree(os.path.join(jail_base, '__staging__'),
966
1234
            os.path.join(jail_base, dir), dry)
967
1235
        # Restore the student's home directory
968
1236
        action_rename(temp_home, os.path.join(jail_base, dir, 'home'), dry)
1175
1443
            del list[i]
1176
1444
        i -= 1
1177
1445
 
 
1446
def get_svn_revision():
 
1447
    """Returns either the current SVN revision of this build, or None"""
 
1448
    try:
 
1449
        svn = pysvn.Client()
 
1450
        entry = svn.info('.')
 
1451
        revnum = entry.revision.number
 
1452
    except pysvn.ClientError, e:
 
1453
        revnum = None
 
1454
    return revnum
 
1455
 
1178
1456
if __name__ == "__main__":
1179
1457
    sys.exit(main())
 
1458