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

« back to all changes in this revision

Viewing changes to setup.py

  • Committer: dcoles
  • Date: 2008-02-25 02:26:39 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:562
Added new app: Diff (SVN diff application)
setup.py: Added diffservice script to jail scripts

Show diffs side-by-side

added added

removed removed

Lines of Context:
67
67
import mimetypes
68
68
import compileall
69
69
import getopt
70
 
import hashlib
71
 
import uuid
72
70
 
73
71
# Import modules from the website is tricky since they're in the www
74
72
# directory.
163
161
    '/etc/matplotlibrc',
164
162
    # Needed for resolv
165
163
    '/lib/libnss_dns.so.2',
166
 
    '/lib/libnss_mdns4_minimal.so.2',
 
164
    #'/lib/libnss_mdns4.so',
167
165
    '/etc/hosts',
168
166
    '/etc/resolv.conf',
169
167
    #'/etc/hosts.conf',
181
179
        'jail/usr/lib/python%s' % PYTHON_VERSION,
182
180
    '/usr/share/matplotlib': 'jail/usr/share/matplotlib',
183
181
    '/etc/ld.so.conf.d': 'jail/etc/ld.so.conf.d',
184
 
    '/usr/share/nltk': 'jail/usr/share/nltk',
185
182
}
186
183
 
187
184
class ConfigOption:
240
237
    """
241
238
# In the local file system, where are the subject-independent exercise sheet
242
239
# file spaces located."""))
243
 
config_options.append(ConfigOption("tos_path",
244
 
    "/home/informatics/tos.html",
245
 
    """Location where the Terms of Service document is stored (on the local
246
 
    file system):""",
247
 
    """
248
 
# In the local file system, where is the Terms of Service document located."""))
249
 
config_options.append(ConfigOption("motd_path",
250
 
    "/home/informatics/motd.html",
251
 
    """Location where the Message of the Day document is stored (on the local
252
 
    file system):""",
253
 
    """
254
 
# In the local file system, where is the Message of the Day document
255
 
# located. This is an HTML file (just the body fragment), which will
256
 
# be displayed on the login page. It is optional."""))
257
240
config_options.append(ConfigOption("public_host", "public.localhost",
258
241
    """Hostname which will cause the server to go into "public mode",
259
242
providing login-free access to student's published work:""",
289
272
    """Database name:""",
290
273
    """
291
274
# Database name"""))
292
 
config_options.append(ConfigOption("db_forumdbname", "ivle_forum",
293
 
    """Forum Database name:""",
294
 
    """
295
 
# Forum Database name"""))
296
275
config_options.append(ConfigOption("db_user", "postgres",
297
276
    """Username for DB server login:""",
298
277
    """
398
377
# as necessary, and include it in the distribution.
399
378
listmake_mimetypes = ['text/x-python', 'text/html',
400
379
    'application/x-javascript', 'application/javascript',
401
 
    'text/css', 'image/png', 'image/gif', 'application/xml']
 
380
    'text/css', 'image/png', 'application/xml']
402
381
 
403
382
# Main function skeleton from Guido van Rossum
404
383
# http://www.artima.com/weblogs/viewpost.jsp?thread=4829
545
524
    list_scripts = [
546
525
        "scripts/python-console",
547
526
        "scripts/fileservice",
548
 
        "scripts/serveservice",
549
527
        "scripts/usrmgt-server",
550
528
        "scripts/diffservice",
551
529
    ]
642
620
    conffile = os.path.join(cwd, "lib/conf/conf.py")
643
621
    jailconffile = os.path.join(cwd, "lib/conf/jailconf.py")
644
622
    conf_hfile = os.path.join(cwd, "trampoline/conf.h")
645
 
    phpBBconffile = os.path.join(cwd, "www/php/phpBB3/config.php")
646
 
    usrmgtserver_initdfile = os.path.join(cwd, "doc/setup/usrmgt-server.init")
647
623
 
648
624
    # Get command-line arguments to avoid asking questions.
649
625
 
663
639
    %s
664
640
    %s
665
641
    %s
666
 
    %s
667
 
    %s
668
642
prompting you for details about your configuration. The file will be
669
643
overwritten if it already exists. It will *not* install or deploy IVLE.
670
644
 
671
645
Please hit Ctrl+C now if you do not wish to do this.
672
 
""" % (conffile, jailconffile, conf_hfile, phpBBconffile, usrmgtserver_initdfile)
 
646
""" % (conffile, jailconffile, conf_hfile)
673
647
 
674
648
        # Get information from the administrator
675
649
        # If EOF is encountered at any time during the questioning, just exit
710
684
        "Must be an integer between 0 and 65535." % repr(usrmgt_port))
711
685
        return 1
712
686
 
713
 
    # Generate the forum secret
714
 
    forum_secret = hashlib.md5(uuid.uuid4().bytes).hexdigest()
715
 
 
716
687
    # Write lib/conf/conf.py
717
688
 
718
689
    try:
727
698
            conf.write('%s\n%s = %s\n' % (opt.comment, opt.option_name,
728
699
                repr(globals()[opt.option_name])))
729
700
 
730
 
        # Add the forum secret to the config file (regenerated each config)
731
 
        conf.write('forum_secret = "%s"\n' % (forum_secret))
732
 
 
733
701
        conf.close()
734
702
    except IOError, (errno, strerror):
735
703
        print "IO error(%s): %s" % (errno, strerror)
809
777
 
810
778
    print "Successfully wrote trampoline/conf.h"
811
779
 
812
 
    # Write www/php/phpBB3/config.php
813
 
 
814
 
    try:
815
 
        conf = open(phpBBconffile, "w")
816
 
        
817
 
        # php-pg work around
818
 
        if db_host == 'localhost':
819
 
            forumdb_host = '127.0.0.1'
820
 
        else:
821
 
            forumdb_host = db_host
822
 
 
823
 
        conf.write( """<?php
824
 
// phpBB 3.0.x auto-generated configuration file
825
 
// Do not change anything in this file!
826
 
$dbms = 'postgres';
827
 
$dbhost = '""" + forumdb_host + """';
828
 
$dbport = '""" + str(db_port) + """';
829
 
$dbname = '""" + db_forumdbname + """';
830
 
$dbuser = '""" + db_user + """';
831
 
$dbpasswd = '""" + db_password + """';
832
 
 
833
 
$table_prefix = 'phpbb_';
834
 
$acm_type = 'file';
835
 
$load_extensions = '';
836
 
@define('PHPBB_INSTALLED', true);
837
 
// @define('DEBUG', true);
838
 
//@define('DEBUG_EXTRA', true);
839
 
 
840
 
$forum_secret = '""" + forum_secret +"""';
841
 
?>"""   )
842
 
    
843
 
        conf.close()
844
 
    except IOError, (errno, strerror):
845
 
        print "IO error(%s): %s" % (errno, strerror)
846
 
        sys.exit(1)
847
 
 
848
 
    print "Successfully wrote www/php/phpBB3/config.php"
849
 
 
850
 
    # Write lib/conf/usrmgt-server.init
851
 
 
852
 
    try:
853
 
        conf = open(usrmgtserver_initdfile, "w")
854
 
 
855
 
        conf.write( '''#! /bin/sh
856
 
 
857
 
# Works for Ubuntu. Check before using on other distributions
858
 
 
859
 
### BEGIN INIT INFO
860
 
# Provides:          usrmgt-server
861
 
# Required-Start:    $syslog $networking $urandom
862
 
# Required-Stop:     $syslog
863
 
# Default-Start:     2 3 4 5
864
 
# Default-Stop:      1
865
 
# Short-Description: IVLE user management server
866
 
# Description:       Daemon connecting to the IVLE user management database.
867
 
### END INIT INFO
868
 
 
869
 
PATH=/sbin:/bin:/usr/sbin:/usr/bin
870
 
DESC="IVLE user management server"
871
 
NAME=usrmgt-server
872
 
DAEMON=/opt/ivle/scripts/$NAME
873
 
DAEMON_ARGS="''' + str(usrmgt_port) + ''' ''' + usrmgt_magic + '''"
874
 
PIDFILE=/var/run/$NAME.pid
875
 
SCRIPTNAME=/etc/init.d/usrmgt-server
876
 
 
877
 
# Exit if the daemon does not exist 
878
 
test -f $DAEMON || exit 0
879
 
 
880
 
# Load the VERBOSE setting and other rcS variables
881
 
[ -f /etc/default/rcS ] && . /etc/default/rcS
882
 
 
883
 
# Define LSB log_* functions.
884
 
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
885
 
. /lib/lsb/init-functions
886
 
 
887
 
#
888
 
# Function that starts the daemon/service
889
 
#
890
 
do_start()
891
 
{
892
 
        # Return
893
 
        #   0 if daemon has been started
894
 
        #   1 if daemon was already running
895
 
        #   2 if daemon could not be started
896
 
        start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
897
 
                || return 1
898
 
        start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
899
 
                $DAEMON_ARGS \
900
 
                || return 2
901
 
        # Add code here, if necessary, that waits for the process to be ready
902
 
        # to handle requests from services started subsequently which depend
903
 
        # on this one.  As a last resort, sleep for some time.
904
 
}
905
 
 
906
 
#
907
 
# Function that stops the daemon/service
908
 
#
909
 
do_stop()
910
 
{
911
 
        # Return
912
 
        #   0 if daemon has been stopped
913
 
        #   1 if daemon was already stopped
914
 
        #   2 if daemon could not be stopped
915
 
        #   other if a failure occurred
916
 
        start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
917
 
        RETVAL="$?"
918
 
        [ "$RETVAL" = 2 ] && return 2
919
 
        # Wait for children to finish too if this is a daemon that forks
920
 
        # and if the daemon is only ever run from this initscript.
921
 
        # If the above conditions are not satisfied then add some other code
922
 
        # that waits for the process to drop all resources that could be
923
 
        # needed by services started subsequently.  A last resort is to
924
 
        # sleep for some time.
925
 
        start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
926
 
        [ "$?" = 2 ] && return 2
927
 
        # Many daemons don't delete their pidfiles when they exit.
928
 
        rm -f $PIDFILE
929
 
        return "$RETVAL"
930
 
}
931
 
 
932
 
#
933
 
# Function that sends a SIGHUP to the daemon/service
934
 
#
935
 
do_reload() {
936
 
        #
937
 
        # If the daemon can reload its configuration without
938
 
        # restarting (for example, when it is sent a SIGHUP),
939
 
        # then implement that here.
940
 
        #
941
 
        start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
942
 
        return 0
943
 
}
944
 
 
945
 
case "$1" in
946
 
  start)
947
 
    [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
948
 
        do_start
949
 
        case "$?" in
950
 
                0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
951
 
                2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
952
 
        esac
953
 
        ;;
954
 
  stop)
955
 
        [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
956
 
        do_stop
957
 
        case "$?" in
958
 
                0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
959
 
                2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
960
 
        esac
961
 
        ;;
962
 
  #reload|force-reload)
963
 
        #
964
 
        # If do_reload() is not implemented then leave this commented out
965
 
        # and leave 'force-reload' as an alias for 'restart'.
966
 
        #
967
 
        #log_daemon_msg "Reloading $DESC" "$NAME"
968
 
        #do_reload
969
 
        #log_end_msg $?
970
 
        #;;
971
 
  restart|force-reload)
972
 
        #
973
 
        # If the "reload" option is implemented then remove the
974
 
        # 'force-reload' alias
975
 
        #
976
 
        log_daemon_msg "Restarting $DESC" "$NAME"
977
 
        do_stop
978
 
        case "$?" in
979
 
          0|1)
980
 
                do_start
981
 
                case "$?" in
982
 
                        0) log_end_msg 0 ;;
983
 
                        1) log_end_msg 1 ;; # Old process is still running
984
 
                        *) log_end_msg 1 ;; # Failed to start
985
 
                esac
986
 
                ;;
987
 
          *)
988
 
                # Failed to stop
989
 
                log_end_msg 1
990
 
                ;;
991
 
        esac
992
 
        ;;
993
 
  *)
994
 
        #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
995
 
        echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
996
 
        exit 3
997
 
        ;;
998
 
esac
999
 
 
1000
 
:
1001
 
''')
1002
 
        
1003
 
        conf.close()
1004
 
    except IOError, (errno, strerror):
1005
 
        print "IO error(%s): %s" % (errno, strerror)
1006
 
        sys.exit(1)
1007
 
 
1008
 
    # fix permissions as the file contains the database password
1009
 
    try:
1010
 
        os.chmod('doc/setup/usrmgt-server.init', 0600)
1011
 
    except OSError, (errno, strerror):
1012
 
        print "WARNING: Couldn't chmod doc/setup/usrmgt-server.init:"
1013
 
        print "OS error(%s): %s" % (errno, strerror)
1014
 
 
1015
 
    print "Successfully wrote lib/conf/usrmgt-server.init"
1016
 
 
1017
780
    print
1018
781
    print "You may modify the configuration at any time by editing"
1019
782
    print conffile
1020
783
    print jailconffile
1021
784
    print conf_hfile
1022
 
    print phpBBconffile
1023
 
    print usrmgtserver_initdfile
1024
785
    print
1025
786
    return 0
1026
787
 
1054
815
    # Chmod the python console
1055
816
    action_chmod_x('jail/opt/ivle/scripts/python-console', dry)
1056
817
    action_chmod_x('jail/opt/ivle/scripts/fileservice', dry)
1057
 
    action_chmod_x('jail/opt/ivle/scripts/serveservice', dry)
1058
818
    
1059
819
    # Also copy the IVLE lib directory into the jail
1060
820
    # This is necessary for running certain scripts
1138
898
    action_copylist(install_list.list_lib, ivle_install_dir, dry)
1139
899
    
1140
900
    # Copy the php directory
1141
 
    forum_dir = "www/php/phpBB3"
1142
 
    forum_path = os.path.join(ivle_install_dir, forum_dir)
1143
 
    action_copytree(forum_dir, forum_path, dry)
1144
 
    print "chown -R www-data:www-data %s" % forum_path
1145
 
    if not dry:
1146
 
        os.system("chown -R www-data:www-data %s" % forum_path)
 
901
    action_copytree('www/php/phpBB3',os.path.join(ivle_install_dir,'www/php/phpBB3'), 
 
902
    dry)
1147
903
 
1148
904
    if not nojail:
1149
905
        # Copy the local jail directory built by the build action