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

« back to all changes in this revision

Viewing changes to setup.py

  • Committer: dcoles
  • Date: 2008-07-03 04:20:54 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:803
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should 
allow us to get in there and tidy up each module much easier. Also removed 
updatejails since this functionality seems to be duplicated with remakeuser.py 
and remakealluser.py scripts.

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
69
69
import getopt
70
70
import hashlib
71
71
import uuid
 
72
import pysvn
72
73
 
73
74
# Import modules from the website is tricky since they're in the www
74
75
# directory.
81
82
# Just get the first 3 characters of sys.version.
82
83
PYTHON_VERSION = sys.version[0:3]
83
84
 
84
 
# Operating system files to copy over into the jail.
85
 
# These will be copied from the given place on the OS file system into the
86
 
# same place within the jail.
87
 
JAIL_FILES = [
88
 
    '/lib/ld-linux.so.2',
89
 
    '/lib/tls/i686/cmov/libc.so.6',
90
 
    '/lib/tls/i686/cmov/libdl.so.2',
91
 
    '/lib/tls/i686/cmov/libm.so.6',
92
 
    '/lib/tls/i686/cmov/libpthread.so.0',
93
 
    '/lib/tls/i686/cmov/libutil.so.1',
94
 
    '/etc/ld.so.conf',
95
 
    '/etc/ld.so.cache',
96
 
    # These 2 files do not exist in Ubuntu
97
 
    #'/etc/ld.so.preload',
98
 
    #'/etc/ld.so.nohwcap',
99
 
    # UNIX commands
100
 
    '/usr/bin/strace',
101
 
    '/bin/ls',
102
 
    '/bin/echo',
103
 
    # Needed by python
104
 
    '/usr/bin/python%s' % PYTHON_VERSION,
105
 
    # Needed by fileservice
106
 
    '/lib/libcom_err.so.2',
107
 
    '/lib/libcrypt.so.1',
108
 
    '/lib/libkeyutils.so.1',
109
 
    '/lib/libresolv.so.2',
110
 
    '/lib/librt.so.1',
111
 
    '/lib/libuuid.so.1',
112
 
    '/usr/lib/libapr-1.so.0',
113
 
    '/usr/lib/libaprutil-1.so.0',
114
 
    '/usr/lib/libdb-4.4.so',
115
 
    '/usr/lib/libexpat.so.1',
116
 
    '/usr/lib/libgcrypt.so.11',
117
 
    '/usr/lib/libgnutls.so.13',
118
 
    '/usr/lib/libgpg-error.so.0',
119
 
    '/usr/lib/libgssapi_krb5.so.2',
120
 
    '/usr/lib/libk5crypto.so.3',
121
 
    '/usr/lib/libkrb5.so.3',
122
 
    '/usr/lib/libkrb5support.so.0',
123
 
    '/usr/lib/liblber.so.2',
124
 
    '/usr/lib/libldap_r.so.2',
125
 
    '/usr/lib/libneon.so.26',
126
 
    '/usr/lib/libpq.so.5',
127
 
    '/usr/lib/libsasl2.so.2',
128
 
    '/usr/lib/libsqlite3.so.0',
129
 
    '/usr/lib/libsvn_client-1.so.1',
130
 
    '/usr/lib/libsvn_delta-1.so.1',
131
 
    '/usr/lib/libsvn_diff-1.so.1',
132
 
    '/usr/lib/libsvn_fs-1.so.1',
133
 
    '/usr/lib/libsvn_fs_base-1.so.1',
134
 
    '/usr/lib/libsvn_fs_fs-1.so.1',
135
 
    '/usr/lib/libsvn_ra-1.so.1',
136
 
    '/usr/lib/libsvn_ra_dav-1.so.1',
137
 
    '/usr/lib/libsvn_ra_local-1.so.1',
138
 
    '/usr/lib/libsvn_ra_svn-1.so.1',
139
 
    '/usr/lib/libsvn_repos-1.so.1',
140
 
    '/usr/lib/libsvn_subr-1.so.1',
141
 
    '/usr/lib/libsvn_wc-1.so.1',
142
 
    '/usr/lib/libtasn1.so.3',
143
 
    '/usr/lib/libxml2.so.2',
144
 
    # Needed by matplotlib
145
 
    '/usr/lib/i686/cmov/libssl.so.0.9.8',
146
 
    '/usr/lib/i686/cmov/libcrypto.so.0.9.8',
147
 
    '/lib/tls/i686/cmov/libnsl.so.1',
148
 
    '/usr/lib/libz.so.1',
149
 
    '/usr/lib/atlas/liblapack.so.3',
150
 
    '/usr/lib/atlas/libblas.so.3',
151
 
    '/usr/lib/libg2c.so.0',
152
 
    '/usr/lib/libstdc++.so.6',
153
 
    '/usr/lib/libfreetype.so.6',
154
 
    '/usr/lib/libpng12.so.0',
155
 
    '/usr/lib/libBLT.2.4.so.8.4',
156
 
    '/usr/lib/libtk8.4.so.0',
157
 
    '/usr/lib/libtcl8.4.so.0',
158
 
    '/usr/lib/tcl8.4/init.tcl',
159
 
    '/usr/lib/libX11.so.6',
160
 
    '/usr/lib/libXau.so.6',
161
 
    '/usr/lib/libXdmcp.so.6',
162
 
    '/lib/libgcc_s.so.1',
163
 
    '/etc/matplotlibrc',
164
 
    # Needed for resolv
165
 
    '/lib/libnss_dns.so.2',
166
 
    '/lib/libnss_mdns4_minimal.so.2',
167
 
    '/etc/hosts',
168
 
    '/etc/resolv.conf',
169
 
    #'/etc/hosts.conf',
170
 
    #'/etc/hostname',
171
 
    '/etc/nsswitch.conf',
172
 
    '/lib/libnss_files.so.2',
173
 
]
174
 
# Symlinks to make within the jail. Src mapped to dst.
175
 
JAIL_LINKS = {
176
 
    'python%s' % PYTHON_VERSION: 'jail/usr/bin/python',
177
 
}
178
 
# Trees to copy. Src mapped to dst (these will be passed to action_copytree).
179
 
JAIL_COPYTREES = {
180
 
    '/usr/lib/python%s' % PYTHON_VERSION:
181
 
        'jail/usr/lib/python%s' % PYTHON_VERSION,
182
 
    '/usr/share/matplotlib': 'jail/usr/share/matplotlib',
183
 
    '/etc/ld.so.conf.d': 'jail/etc/ld.so.conf.d',
184
 
    '/usr/share/nltk': 'jail/usr/share/nltk',
185
 
}
186
 
 
187
85
class ConfigOption:
188
86
    """A configuration option; one of the things written to conf.py."""
189
87
    def __init__(self, option_name, default, prompt, comment):
246
144
    file system):""",
247
145
    """
248
146
# In the local file system, where is the Terms of Service document located."""))
 
147
config_options.append(ConfigOption("motd_path",
 
148
    "/home/informatics/motd.html",
 
149
    """Location where the Message of the Day document is stored (on the local
 
150
    file system):""",
 
151
    """
 
152
# In the local file system, where is the Message of the Day document
 
153
# located. This is an HTML file (just the body fragment), which will
 
154
# be displayed on the login page. It is optional."""))
249
155
config_options.append(ConfigOption("public_host", "public.localhost",
250
156
    """Hostname which will cause the server to go into "public mode",
251
157
providing login-free access to student's published work:""",
419
325
        return 1
420
326
 
421
327
    # Disallow run as root unless installing
422
 
    if (operation != 'install' and operation != 'updatejails'
 
328
    if (operation != 'install' and operation != 'updatejails' and operation != 
 
329
    'build'
423
330
        and os.geteuid() == 0):
424
331
        print >>sys.stderr, "I do not want to run this stage as root."
425
332
        print >>sys.stderr, "Please run as a normal user."
510
417
Copy trampoline/trampoline to $target/bin.
511
418
chown and chmod the installed trampoline.
512
419
Copy www/ to $target.
513
 
Copy jail/ to jails template directory (unless --nojail specified).
 
420
Copy jail/ to jails __staging__ directory (unless --nojail specified).
514
421
Copy subjects/ to subjects directory (unless --nosubjects specified).
515
422
 
516
423
--nojail        Do not copy the jail.
1024
931
 
1025
932
    if dry:
1026
933
        print "Dry run (no actions will be executed\n"
 
934
    
 
935
    if not dry and os.geteuid() != 0:
 
936
        print >>sys.stderr, "Must be root to run build"
 
937
        print >>sys.stderr, "(I need to chroot)."
 
938
        return 1
 
939
    
 
940
    # Find out the revison number
 
941
    revnum = get_svn_revision()
 
942
    print "Building Revision %s"%str(revnum)
 
943
    if not dry:
 
944
        vfile = open('BUILD-VERSION','w')
 
945
        vfile.write(str(revnum) + '\n')
 
946
        vfile.close()
1027
947
 
1028
948
    # Compile the trampoline
1029
949
    curdir = os.getcwd()
1033
953
 
1034
954
    # Create the jail and its subdirectories
1035
955
    # Note: Other subdirs will be made by copying files
1036
 
    action_mkdir('jail', dry)
1037
 
    action_mkdir('jail/home', dry)
1038
 
    action_mkdir('jail/tmp', dry)
1039
 
 
1040
 
    # Chmod the tmp directory to world writable
1041
 
    action_chmod_w('jail/tmp', dry)
 
956
    action_runprog('./buildjail.sh', [], dry)
1042
957
 
1043
958
    # Copy all console and operating system files into the jail
1044
959
    action_copylist(install_list.list_scripts, 'jail/opt/ivle', dry)
1045
 
    copy_os_files_jail(dry)
1046
960
    # Chmod the python console
1047
961
    action_chmod_x('jail/opt/ivle/scripts/python-console', dry)
1048
962
    action_chmod_x('jail/opt/ivle/scripts/fileservice', dry)
1075
989
 
1076
990
    return 0
1077
991
 
1078
 
def copy_os_files_jail(dry):
1079
 
    """Copies necessary Operating System files from their usual locations
1080
 
    into the jail/ directory of the cwd."""
1081
 
    # Currently source paths are configured for Ubuntu.
1082
 
    for filename in JAIL_FILES:
1083
 
        copy_file_to_jail(filename, dry)
1084
 
    for src, dst in JAIL_LINKS.items():
1085
 
        action_symlink(src, dst, dry)
1086
 
    for src, dst in JAIL_COPYTREES.items():
1087
 
        action_copytree(src, dst, dry)
1088
 
 
1089
992
def copy_file_to_jail(src, dry):
1090
993
    """Copies a single file from an absolute location into the same location
1091
994
    within the jail. src must begin with a '/'. The jail will be located
1139
1042
 
1140
1043
    if not nojail:
1141
1044
        # Copy the local jail directory built by the build action
1142
 
        # to the jails template directory (it will be used as a template
1143
 
        # for all the students' jails).
1144
 
        action_copytree('jail', os.path.join(jail_base, 'template'), dry)
 
1045
        # to the jails __staging__ directory (it will be used to help build
 
1046
        # all the students' jails).
 
1047
        action_copytree('jail', os.path.join(jail_base, '__staging__'), dry)
1145
1048
    if not nosubjects:
1146
1049
        # Copy the subjects and exercises directories across
1147
1050
        action_copylist(install_list.list_subjects, subjects_base, dry,
1172
1075
    if write_ivle_lib_pth:
1173
1076
        action_append(ivle_pth, ivle_lib)
1174
1077
 
 
1078
 
 
1079
    # Create the ivle working revision record file
 
1080
    action_mkdir(os.path.join(ivle_install_dir, 'version'), dry)
 
1081
    ivle_revision_record_file = os.path.join(ivle_install_dir, 'version/ivle-revision.txt')
 
1082
    if not dry:
 
1083
        try:
 
1084
            conf = open(ivle_revision_record_file, "w")
 
1085
 
 
1086
            conf.write( "# IVLE code revision listing generated by running 'svn status -v ..' from " + os.getcwd() + "\n#\n\n")
 
1087
 
 
1088
            conf.close()
 
1089
        except IOError, (errno, strerror):
 
1090
            print "IO error(%s): %s" % (errno, strerror)
 
1091
            sys.exit(1)
 
1092
 
 
1093
        os.system("svn status -v .. >> %s" % ivle_revision_record_file)
 
1094
 
 
1095
    print "Wrote IVLE code revision status to %s" % ivle_revision_record_file
 
1096
 
1175
1097
    return 0
1176
1098
 
1177
1099
def updatejails(args):
1188
1110
        print >>sys.stderr, "(I need to chown some files)."
1189
1111
        return 1
1190
1112
 
1191
 
    # Update the template jail directory in case it hasn't been installed
 
1113
    # Update the staging jail directory in case it hasn't been installed
1192
1114
    # recently.
1193
 
    action_copytree('jail', os.path.join(jail_base, 'template'), dry)
 
1115
    action_copytree('jail', os.path.join(jail_base, '__staging__'), dry)
1194
1116
 
1195
1117
    # Re-link all the files in all students jails.
1196
1118
    for dir in os.listdir(jail_base):
1197
 
        if dir == 'template': continue
 
1119
        if dir == '__staging__': continue
1198
1120
        # First back up the student's home directory
1199
1121
        temp_home = os.tmpnam()
1200
1122
        action_rename(os.path.join(jail_base, dir, 'home'), temp_home, dry)
1201
1123
        # Delete the student's jail and relink the jail files
1202
 
        action_linktree(os.path.join(jail_base, 'template'),
 
1124
        action_linktree(os.path.join(jail_base, '__staging__'),
1203
1125
            os.path.join(jail_base, dir), dry)
1204
1126
        # Restore the student's home directory
1205
1127
        action_rename(temp_home, os.path.join(jail_base, dir, 'home'), dry)
1371
1293
        os.chmod(file, stat.S_IXUSR | stat.S_IRUSR | stat.S_IWUSR
1372
1294
            | stat.S_IXGRP | stat.S_IRGRP | stat.S_IXOTH | stat.S_IROTH)
1373
1295
 
1374
 
 
1375
 
def action_chmod_w(file, dry):
1376
 
    """Chmod 777 a file (sets permissions to rwxrwxrwx)."""
1377
 
    print "chmod 777", file
1378
 
    if not dry:
1379
 
        os.chmod(file, stat.S_IXUSR | stat.S_IRUSR | stat.S_IWUSR
1380
 
            | stat.S_IXGRP | stat.S_IWGRP | stat.S_IRGRP | stat.S_IXOTH
1381
 
            | stat.S_IWOTH | stat.S_IROTH)
1382
 
 
1383
1296
def query_user(default, prompt):
1384
1297
    """Prompts the user for a string, which is read from a line of stdin.
1385
1298
    Exits silently if EOF is encountered. Returns the string, with spaces
1412
1325
            del list[i]
1413
1326
        i -= 1
1414
1327
 
 
1328
def get_svn_revision():
 
1329
    """Returns either the current SVN revision of this build, or None"""
 
1330
    try:
 
1331
        svn = pysvn.Client()
 
1332
        entry = svn.info('.')
 
1333
        revnum = entry.revision.number
 
1334
    except pysvn.ClientError, e:
 
1335
        revnum = None
 
1336
    return revnum
 
1337
 
1415
1338
if __name__ == "__main__":
1416
1339
    sys.exit(main())
 
1340