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

« back to all changes in this revision

Viewing changes to setup.py

  • Committer: dcoles
  • Date: 2008-04-21 05:57:40 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:746
Setup: During Build the system will now indicate what revision is being built 
as well as storing this number in 'BUILD-VERSION'. This will probably be used 
so we can see what revision in running from IVLE itself.

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
import pysvn
70
73
 
71
74
# Import modules from the website is tricky since they're in the www
72
75
# directory.
159
162
    '/usr/lib/libXdmcp.so.6',
160
163
    '/lib/libgcc_s.so.1',
161
164
    '/etc/matplotlibrc',
 
165
    # Needed for resolv
 
166
    '/lib/libnss_dns.so.2',
 
167
    '/lib/libnss_mdns4_minimal.so.2',
 
168
    '/etc/hosts',
 
169
    '/etc/resolv.conf',
 
170
    #'/etc/hosts.conf',
 
171
    #'/etc/hostname',
 
172
    '/etc/nsswitch.conf',
 
173
    '/lib/libnss_files.so.2',
 
174
    # Needed for PIL
 
175
    '/usr/lib/libjpeg.so.62',
 
176
    # Needed by lxml
 
177
    '/usr/lib/libxslt.so.1',
 
178
    '/usr/lib/libexslt.so.0',
 
179
    # Needed by elementtree
 
180
    '/usr/lib/libtidy-0.99.so.0',
162
181
]
163
182
# Symlinks to make within the jail. Src mapped to dst.
164
183
JAIL_LINKS = {
168
187
JAIL_COPYTREES = {
169
188
    '/usr/lib/python%s' % PYTHON_VERSION:
170
189
        'jail/usr/lib/python%s' % PYTHON_VERSION,
 
190
    '/var/lib/python-support/python%s' % PYTHON_VERSION:
 
191
        'jail/var/lib/python-support/python%s' %PYTHON_VERSION,
171
192
    '/usr/share/matplotlib': 'jail/usr/share/matplotlib',
172
193
    '/etc/ld.so.conf.d': 'jail/etc/ld.so.conf.d',
 
194
    '/usr/share/pycentral': 'jail/usr/share/pycentral',
 
195
    '/usr/share/pycentral-data': 'jail/usr/share/pycentral-data',
 
196
    '/usr/share/nltk': 'jail/usr/share/nltk',
173
197
}
174
198
 
175
199
class ConfigOption:
191
215
 
192
216
# Configuration options, defaults and descriptions
193
217
config_options = []
194
 
config_options.append(ConfigOption("root_dir", "/ivle",
 
218
config_options.append(ConfigOption("root_dir", "/",
195
219
    """Root directory where IVLE is located (in URL space):""",
196
220
    """
197
221
# In URL space, where in the site is IVLE located. (All URLs will be prefixed
204
228
# In the local file system, where IVLE is actually installed.
205
229
# This directory should contain the "www" and "bin" directories."""))
206
230
config_options.append(ConfigOption("jail_base", "/home/informatics/jails",
207
 
    """Root directory where the jails (containing user files) are stored
 
231
    """Location of Directories
 
232
=======================
 
233
Root directory where the jails (containing user files) are stored
208
234
(on the local file system):""",
209
235
    """
210
236
# In the local file system, where are the student/user file spaces located.
218
244
# In the local file system, where are the per-subject file spaces located.
219
245
# The individual subject directories are expected to be located immediately
220
246
# 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
 
247
config_options.append(ConfigOption("exercises_base",
 
248
    "/home/informatics/exercises",
 
249
    """Root directory where the exercise directories (containing
 
250
subject-independent exercise sheets) are stored (on the local file
225
251
system):""",
226
252
    """
227
 
# In the local file system, where are the subject-independent problem sheet
 
253
# In the local file system, where are the subject-independent exercise sheet
228
254
# file spaces located."""))
 
255
config_options.append(ConfigOption("tos_path",
 
256
    "/home/informatics/tos.html",
 
257
    """Location where the Terms of Service document is stored (on the local
 
258
    file system):""",
 
259
    """
 
260
# In the local file system, where is the Terms of Service document located."""))
 
261
config_options.append(ConfigOption("motd_path",
 
262
    "/home/informatics/motd.html",
 
263
    """Location where the Message of the Day document is stored (on the local
 
264
    file system):""",
 
265
    """
 
266
# In the local file system, where is the Message of the Day document
 
267
# located. This is an HTML file (just the body fragment), which will
 
268
# be displayed on the login page. It is optional."""))
229
269
config_options.append(ConfigOption("public_host", "public.localhost",
230
270
    """Hostname which will cause the server to go into "public mode",
231
271
providing login-free access to student's published work:""",
261
301
    """Database name:""",
262
302
    """
263
303
# Database name"""))
 
304
config_options.append(ConfigOption("db_forumdbname", "ivle_forum",
 
305
    """Forum Database name:""",
 
306
    """
 
307
# Forum Database name"""))
264
308
config_options.append(ConfigOption("db_user", "postgres",
265
309
    """Username for DB server login:""",
266
310
    """
270
314
    (Caution: This password is stored in plaintext in lib/conf/conf.py)""",
271
315
    """
272
316
# Database password"""))
 
317
config_options.append(ConfigOption("auth_modules", "ldap_auth",
 
318
    """Authentication config
 
319
=====================
 
320
Comma-separated list of authentication modules. Only "ldap" is available
 
321
by default.""",
 
322
    """
 
323
# Comma-separated list of authentication modules.
 
324
# These refer to importable Python modules in the www/auth directory.
 
325
# Modules "ldap" and "guest" are available in the source tree, but
 
326
# other modules may be plugged in to auth against organisation-specific
 
327
# auth backends."""))
 
328
config_options.append(ConfigOption("ldap_url", "ldaps://www.example.com",
 
329
    """(LDAP options are only relevant if "ldap" is included in the list of
 
330
auth modules).
 
331
URL for LDAP authentication server:""",
 
332
    """
 
333
# URL for LDAP authentication server"""))
 
334
config_options.append(ConfigOption("ldap_format_string",
 
335
    "uid=%s,ou=users,o=example",
 
336
    """Format string for LDAP auth request:
 
337
    (Must contain a single "%s" for the user's login name)""",
 
338
    """
 
339
# Format string for LDAP auth request
 
340
# (Must contain a single "%s" for the user's login name)"""))
 
341
config_options.append(ConfigOption("svn_addr", "http://svn.localhost/",
 
342
    """Subversion config
 
343
=================
 
344
The base url for accessing subversion repositories:""",
 
345
    """
 
346
# The base url for accessing subversion repositories."""))
 
347
config_options.append(ConfigOption("svn_conf", "/opt/ivle/svn/svn.conf",
 
348
    """The location of the subversion configuration file used by apache
 
349
to host the user repositories:""",
 
350
    """
 
351
# The location of the subversion configuration file used by
 
352
# apache to host the user repositories."""))
 
353
config_options.append(ConfigOption("svn_repo_path", "/home/informatics/repositories",
 
354
    """The root directory for the subversion repositories:""",
 
355
    """
 
356
# The root directory for the subversion repositories."""))
 
357
config_options.append(ConfigOption("svn_auth_ivle", "/opt/ivle/svn/ivle.auth",
 
358
    """The location of the password file used to authenticate users
 
359
of the subversion repository from the ivle server:""",
 
360
    """
 
361
# The location of the password file used to authenticate users
 
362
# of the subversion repository from the ivle server."""))
 
363
config_options.append(ConfigOption("svn_auth_local", "/opt/ivle/svn/local.auth",
 
364
    """The location of the password file used to authenticate local users
 
365
of the subversion repository:""",
 
366
    """
 
367
# The location of the password file used to authenticate local users
 
368
# of the subversion repository."""))
 
369
config_options.append(ConfigOption("usrmgt_host", "localhost",
 
370
    """User Management Server config
 
371
============================
 
372
The hostname where the usrmgt-server runs:""",
 
373
    """
 
374
# The hostname where the usrmgt-server runs."""))
 
375
config_options.append(ConfigOption("usrmgt_port", "2178",
 
376
    """The port where the usrmgt-server runs:""",
 
377
    """
 
378
# The port where the usrmgt-server runs."""))
 
379
config_options.append(ConfigOption("usrmgt_magic", "",
 
380
    """The password for the usrmgt-server:""",
 
381
    """
 
382
# The password for the usrmgt-server."""))
273
383
 
274
384
# Try importing existing conf, but if we can't just set up defaults
275
385
# The reason for this is that these settings are used by other phases
300
410
# as necessary, and include it in the distribution.
301
411
listmake_mimetypes = ['text/x-python', 'text/html',
302
412
    'application/x-javascript', 'application/javascript',
303
 
    'text/css', 'image/png', 'application/xml']
 
413
    'text/css', 'image/png', 'image/gif', 'application/xml']
304
414
 
305
415
# Main function skeleton from Guido van Rossum
306
416
# http://www.artima.com/weblogs/viewpost.jsp?thread=4829
424
534
Copy subjects/ to subjects directory (unless --nosubjects specified).
425
535
 
426
536
--nojail        Do not copy the jail.
427
 
--nosubjects    Do not copy the subjects and problems directories.
 
537
--nosubjects    Do not copy the subjects and exercises directories.
428
538
--dry | -n  Print out the actions but don't do anything."""
429
539
    elif operation == 'updatejails':
430
540
        print """sudo python setup.py updatejails [--dry|-n]
442
552
    # We build two separate lists, by walking www and console
443
553
    list_www = build_list_py_files('www')
444
554
    list_lib = build_list_py_files('lib')
445
 
    list_scripts = build_list_py_files('scripts')
446
555
    list_subjects = build_list_py_files('subjects', no_top_level=True)
447
 
    list_problems = build_list_py_files('problems', no_top_level=True)
 
556
    list_exercises = build_list_py_files('exercises', no_top_level=True)
 
557
    list_scripts = [
 
558
        "scripts/python-console",
 
559
        "scripts/fileservice",
 
560
        "scripts/serveservice",
 
561
        "scripts/usrmgt-server",
 
562
        "scripts/diffservice",
 
563
    ]
448
564
    # Make sure that the files generated by conf are in the list
449
565
    # (since listmake is typically run before conf)
450
566
    if "lib/conf/conf.py" not in list_lib:
451
567
        list_lib.append("lib/conf/conf.py")
452
 
    # Make sure that console/python-console is in the list
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")
457
568
    # Write these out to a file
458
569
    cwd = os.getcwd()
459
570
    # the files that will be created/overwritten
486
597
list_subjects = """)
487
598
        writelist_pretty(file, list_subjects)
488
599
        file.write("""
489
 
# List of all installable files in problems directory.
 
600
# List of all installable files in exercises directory.
490
601
# This is to install sample exercise material.
491
 
list_problems = """)
492
 
        writelist_pretty(file, list_problems)
 
602
list_exercises = """)
 
603
        writelist_pretty(file, list_exercises)
493
604
 
494
605
        file.close()
495
606
    except IOError, (errno, strerror):
535
646
        file.write(']\n')
536
647
 
537
648
def conf(args):
538
 
    global db_port
 
649
    global db_port, usrmgt_port
539
650
    # Set up some variables
540
651
 
541
652
    cwd = os.getcwd()
543
654
    conffile = os.path.join(cwd, "lib/conf/conf.py")
544
655
    jailconffile = os.path.join(cwd, "lib/conf/jailconf.py")
545
656
    conf_hfile = os.path.join(cwd, "trampoline/conf.h")
 
657
    phpBBconffile = os.path.join(cwd, "www/php/phpBB3/config.php")
 
658
    usrmgtserver_initdfile = os.path.join(cwd, "doc/setup/usrmgt-server.init")
546
659
 
547
660
    # Get command-line arguments to avoid asking questions.
548
661
 
562
675
    %s
563
676
    %s
564
677
    %s
 
678
    %s
 
679
    %s
565
680
prompting you for details about your configuration. The file will be
566
681
overwritten if it already exists. It will *not* install or deploy IVLE.
567
682
 
568
683
Please hit Ctrl+C now if you do not wish to do this.
569
 
""" % (conffile, jailconffile, conf_hfile)
 
684
""" % (conffile, jailconffile, conf_hfile, phpBBconffile, usrmgtserver_initdfile)
570
685
 
571
686
        # Get information from the administrator
572
687
        # If EOF is encountered at any time during the questioning, just exit
598
713
        "Invalid DB port (%s).\n"
599
714
        "Must be an integer between 0 and 65535." % repr(db_port))
600
715
        return 1
 
716
    try:
 
717
        usrmgt_port = int(usrmgt_port)
 
718
        if usrmgt_port < 0 or usrmgt_port >= 65536: raise ValueError()
 
719
    except ValueError:
 
720
        print >>sys.stderr, (
 
721
        "Invalid user management port (%s).\n"
 
722
        "Must be an integer between 0 and 65535." % repr(usrmgt_port))
 
723
        return 1
 
724
 
 
725
    # Generate the forum secret
 
726
    forum_secret = hashlib.md5(uuid.uuid4().bytes).hexdigest()
601
727
 
602
728
    # Write lib/conf/conf.py
603
729
 
613
739
            conf.write('%s\n%s = %s\n' % (opt.comment, opt.option_name,
614
740
                repr(globals()[opt.option_name])))
615
741
 
 
742
        # Add the forum secret to the config file (regenerated each config)
 
743
        conf.write('forum_secret = "%s"\n' % (forum_secret))
 
744
 
616
745
        conf.close()
617
746
    except IOError, (errno, strerror):
618
747
        print "IO error(%s): %s" % (errno, strerror)
692
821
 
693
822
    print "Successfully wrote trampoline/conf.h"
694
823
 
 
824
    # Write www/php/phpBB3/config.php
 
825
 
 
826
    try:
 
827
        conf = open(phpBBconffile, "w")
 
828
        
 
829
        # php-pg work around
 
830
        if db_host == 'localhost':
 
831
            forumdb_host = '127.0.0.1'
 
832
        else:
 
833
            forumdb_host = db_host
 
834
 
 
835
        conf.write( """<?php
 
836
// phpBB 3.0.x auto-generated configuration file
 
837
// Do not change anything in this file!
 
838
$dbms = 'postgres';
 
839
$dbhost = '""" + forumdb_host + """';
 
840
$dbport = '""" + str(db_port) + """';
 
841
$dbname = '""" + db_forumdbname + """';
 
842
$dbuser = '""" + db_user + """';
 
843
$dbpasswd = '""" + db_password + """';
 
844
 
 
845
$table_prefix = 'phpbb_';
 
846
$acm_type = 'file';
 
847
$load_extensions = '';
 
848
@define('PHPBB_INSTALLED', true);
 
849
// @define('DEBUG', true);
 
850
//@define('DEBUG_EXTRA', true);
 
851
 
 
852
$forum_secret = '""" + forum_secret +"""';
 
853
?>"""   )
 
854
    
 
855
        conf.close()
 
856
    except IOError, (errno, strerror):
 
857
        print "IO error(%s): %s" % (errno, strerror)
 
858
        sys.exit(1)
 
859
 
 
860
    print "Successfully wrote www/php/phpBB3/config.php"
 
861
 
 
862
    # Write lib/conf/usrmgt-server.init
 
863
 
 
864
    try:
 
865
        conf = open(usrmgtserver_initdfile, "w")
 
866
 
 
867
        conf.write( '''#! /bin/sh
 
868
 
 
869
# Works for Ubuntu. Check before using on other distributions
 
870
 
 
871
### BEGIN INIT INFO
 
872
# Provides:          usrmgt-server
 
873
# Required-Start:    $syslog $networking $urandom
 
874
# Required-Stop:     $syslog
 
875
# Default-Start:     2 3 4 5
 
876
# Default-Stop:      1
 
877
# Short-Description: IVLE user management server
 
878
# Description:       Daemon connecting to the IVLE user management database.
 
879
### END INIT INFO
 
880
 
 
881
PATH=/sbin:/bin:/usr/sbin:/usr/bin
 
882
DESC="IVLE user management server"
 
883
NAME=usrmgt-server
 
884
DAEMON=/opt/ivle/scripts/$NAME
 
885
DAEMON_ARGS="''' + str(usrmgt_port) + ''' ''' + usrmgt_magic + '''"
 
886
PIDFILE=/var/run/$NAME.pid
 
887
SCRIPTNAME=/etc/init.d/usrmgt-server
 
888
 
 
889
# Exit if the daemon does not exist 
 
890
test -f $DAEMON || exit 0
 
891
 
 
892
# Load the VERBOSE setting and other rcS variables
 
893
[ -f /etc/default/rcS ] && . /etc/default/rcS
 
894
 
 
895
# Define LSB log_* functions.
 
896
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
 
897
. /lib/lsb/init-functions
 
898
 
 
899
#
 
900
# Function that starts the daemon/service
 
901
#
 
902
do_start()
 
903
{
 
904
        # Return
 
905
        #   0 if daemon has been started
 
906
        #   1 if daemon was already running
 
907
        #   2 if daemon could not be started
 
908
        start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
 
909
                || return 1
 
910
        start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
 
911
                $DAEMON_ARGS \
 
912
                || return 2
 
913
        # Add code here, if necessary, that waits for the process to be ready
 
914
        # to handle requests from services started subsequently which depend
 
915
        # on this one.  As a last resort, sleep for some time.
 
916
}
 
917
 
 
918
#
 
919
# Function that stops the daemon/service
 
920
#
 
921
do_stop()
 
922
{
 
923
        # Return
 
924
        #   0 if daemon has been stopped
 
925
        #   1 if daemon was already stopped
 
926
        #   2 if daemon could not be stopped
 
927
        #   other if a failure occurred
 
928
        start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
 
929
        RETVAL="$?"
 
930
        [ "$RETVAL" = 2 ] && return 2
 
931
        # Wait for children to finish too if this is a daemon that forks
 
932
        # and if the daemon is only ever run from this initscript.
 
933
        # If the above conditions are not satisfied then add some other code
 
934
        # that waits for the process to drop all resources that could be
 
935
        # needed by services started subsequently.  A last resort is to
 
936
        # sleep for some time.
 
937
        start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
 
938
        [ "$?" = 2 ] && return 2
 
939
        # Many daemons don't delete their pidfiles when they exit.
 
940
        rm -f $PIDFILE
 
941
        return "$RETVAL"
 
942
}
 
943
 
 
944
#
 
945
# Function that sends a SIGHUP to the daemon/service
 
946
#
 
947
do_reload() {
 
948
        #
 
949
        # If the daemon can reload its configuration without
 
950
        # restarting (for example, when it is sent a SIGHUP),
 
951
        # then implement that here.
 
952
        #
 
953
        start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
 
954
        return 0
 
955
}
 
956
 
 
957
case "$1" in
 
958
  start)
 
959
    [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
 
960
        do_start
 
961
        case "$?" in
 
962
                0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
 
963
                2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
 
964
        esac
 
965
        ;;
 
966
  stop)
 
967
        [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
 
968
        do_stop
 
969
        case "$?" in
 
970
                0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
 
971
                2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
 
972
        esac
 
973
        ;;
 
974
  #reload|force-reload)
 
975
        #
 
976
        # If do_reload() is not implemented then leave this commented out
 
977
        # and leave 'force-reload' as an alias for 'restart'.
 
978
        #
 
979
        #log_daemon_msg "Reloading $DESC" "$NAME"
 
980
        #do_reload
 
981
        #log_end_msg $?
 
982
        #;;
 
983
  restart|force-reload)
 
984
        #
 
985
        # If the "reload" option is implemented then remove the
 
986
        # 'force-reload' alias
 
987
        #
 
988
        log_daemon_msg "Restarting $DESC" "$NAME"
 
989
        do_stop
 
990
        case "$?" in
 
991
          0|1)
 
992
                do_start
 
993
                case "$?" in
 
994
                        0) log_end_msg 0 ;;
 
995
                        1) log_end_msg 1 ;; # Old process is still running
 
996
                        *) log_end_msg 1 ;; # Failed to start
 
997
                esac
 
998
                ;;
 
999
          *)
 
1000
                # Failed to stop
 
1001
                log_end_msg 1
 
1002
                ;;
 
1003
        esac
 
1004
        ;;
 
1005
  *)
 
1006
        #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
 
1007
        echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
 
1008
        exit 3
 
1009
        ;;
 
1010
esac
 
1011
 
 
1012
:
 
1013
''')
 
1014
        
 
1015
        conf.close()
 
1016
    except IOError, (errno, strerror):
 
1017
        print "IO error(%s): %s" % (errno, strerror)
 
1018
        sys.exit(1)
 
1019
 
 
1020
    # fix permissions as the file contains the database password
 
1021
    try:
 
1022
        os.chmod('doc/setup/usrmgt-server.init', 0600)
 
1023
    except OSError, (errno, strerror):
 
1024
        print "WARNING: Couldn't chmod doc/setup/usrmgt-server.init:"
 
1025
        print "OS error(%s): %s" % (errno, strerror)
 
1026
 
 
1027
    print "Successfully wrote lib/conf/usrmgt-server.init"
 
1028
 
695
1029
    print
696
1030
    print "You may modify the configuration at any time by editing"
697
1031
    print conffile
698
1032
    print jailconffile
699
1033
    print conf_hfile
 
1034
    print phpBBconffile
 
1035
    print usrmgtserver_initdfile
700
1036
    print
701
1037
    return 0
702
1038
 
708
1044
 
709
1045
    if dry:
710
1046
        print "Dry run (no actions will be executed\n"
 
1047
    
 
1048
    # Find out the revison number
 
1049
    revnum = get_svn_revision()
 
1050
    print "Building Revision %s"%str(revnum)
 
1051
    if not dry:
 
1052
        vfile = open('BUILD-VERSION','w')
 
1053
        vfile.write(str(revnum) + '\n')
 
1054
        vfile.close()
711
1055
 
712
1056
    # Compile the trampoline
713
1057
    curdir = os.getcwd()
721
1065
    action_mkdir('jail/home', dry)
722
1066
    action_mkdir('jail/tmp', dry)
723
1067
 
 
1068
    # Chmod the tmp directory to world writable
 
1069
    action_chmod_w('jail/tmp', dry)
 
1070
 
724
1071
    # Copy all console and operating system files into the jail
725
1072
    action_copylist(install_list.list_scripts, 'jail/opt/ivle', dry)
726
1073
    copy_os_files_jail(dry)
727
1074
    # Chmod the python console
728
1075
    action_chmod_x('jail/opt/ivle/scripts/python-console', dry)
729
1076
    action_chmod_x('jail/opt/ivle/scripts/fileservice', dry)
 
1077
    action_chmod_x('jail/opt/ivle/scripts/serveservice', dry)
730
1078
    
731
1079
    # Also copy the IVLE lib directory into the jail
732
1080
    # This is necessary for running certain scripts
799
1147
    # chown trampoline to root and set setuid bit
800
1148
    action_chown_setuid(tramppath, dry)
801
1149
 
 
1150
    # Create a scripts directory to put the usrmgt-server in.
 
1151
    action_mkdir(os.path.join(ivle_install_dir, 'scripts'), dry)
 
1152
    usrmgtpath = os.path.join(ivle_install_dir, 'scripts/usrmgt-server')
 
1153
    action_copyfile('scripts/usrmgt-server', usrmgtpath, dry)
 
1154
    action_chmod_x(usrmgtpath, dry)
 
1155
 
802
1156
    # Copy the www and lib directories using the list
803
1157
    action_copylist(install_list.list_www, ivle_install_dir, dry)
804
1158
    action_copylist(install_list.list_lib, ivle_install_dir, dry)
 
1159
    
 
1160
    # Copy the php directory
 
1161
    forum_dir = "www/php/phpBB3"
 
1162
    forum_path = os.path.join(ivle_install_dir, forum_dir)
 
1163
    action_copytree(forum_dir, forum_path, dry)
 
1164
    print "chown -R www-data:www-data %s" % forum_path
 
1165
    if not dry:
 
1166
        os.system("chown -R www-data:www-data %s" % forum_path)
805
1167
 
806
1168
    if not nojail:
807
1169
        # Copy the local jail directory built by the build action
809
1171
        # for all the students' jails).
810
1172
        action_copytree('jail', os.path.join(jail_base, 'template'), dry)
811
1173
    if not nosubjects:
812
 
        # Copy the subjects and problems directories across
 
1174
        # Copy the subjects and exercises directories across
813
1175
        action_copylist(install_list.list_subjects, subjects_base, dry,
814
1176
            srcdir="./subjects")
815
 
        action_copylist(install_list.list_problems, problems_base, dry,
816
 
            srcdir="./problems")
 
1177
        action_copylist(install_list.list_exercises, exercises_base, dry,
 
1178
            srcdir="./exercises")
817
1179
 
818
1180
    # Append IVLE path to ivle.pth in python site packages
819
1181
    # (Unless it's already there)
943
1305
    directories as necessary.
944
1306
 
945
1307
    See shutil.copytree."""
 
1308
    # Allow copying over itself
 
1309
    if (os.path.normpath(os.path.join(os.getcwd(),src)) ==
 
1310
        os.path.normpath(os.path.join(os.getcwd(),dst))):
 
1311
        return
946
1312
    action_remove(dst, dry)
947
1313
    print "cp -r", src, dst
948
1314
    if dry: return
1033
1399
        os.chmod(file, stat.S_IXUSR | stat.S_IRUSR | stat.S_IWUSR
1034
1400
            | stat.S_IXGRP | stat.S_IRGRP | stat.S_IXOTH | stat.S_IROTH)
1035
1401
 
 
1402
 
 
1403
def action_chmod_w(file, dry):
 
1404
    """Chmod 777 a file (sets permissions to rwxrwxrwx)."""
 
1405
    print "chmod 777", file
 
1406
    if not dry:
 
1407
        os.chmod(file, stat.S_IXUSR | stat.S_IRUSR | stat.S_IWUSR
 
1408
            | stat.S_IXGRP | stat.S_IWGRP | stat.S_IRGRP | stat.S_IXOTH
 
1409
            | stat.S_IWOTH | stat.S_IROTH)
 
1410
 
1036
1411
def query_user(default, prompt):
1037
1412
    """Prompts the user for a string, which is read from a line of stdin.
1038
1413
    Exits silently if EOF is encountered. Returns the string, with spaces
1065
1440
            del list[i]
1066
1441
        i -= 1
1067
1442
 
 
1443
def get_svn_revision():
 
1444
    """Returns either the current SVN revision of this build, or None"""
 
1445
    try:
 
1446
        svn = pysvn.Client()
 
1447
        entry = svn.info('.')
 
1448
        revnum = entry.revision.number
 
1449
    except pysvn.ClientError, e:
 
1450
        revnum = None
 
1451
    return revnum
 
1452
 
1068
1453
if __name__ == "__main__":
1069
1454
    sys.exit(main())
 
1455