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

803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
1
# IVLE - Informatics Virtual Learning Environment
2
# Copyright (C) 2007-2008 The University of Melbourne
3
#
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
8
#
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17
18
# Module: setup/install
19
# Author: Matt Giuca, Refactored by David Coles
20
# Date:   03/07/2008
21
22
import optparse
23
import os
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
24
import sys
1092.1.1 by William Grant
[Uber-commit of holiday work because I lacked a local copy of the branch.]
25
import functools
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
26
27
from setup import util
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
28
29
def install(args):
30
    usage = """usage: %prog install [options]
31
(Requires root)
32
Create target install directory ($target).
33
Create $target/bin.
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
34
Copy bin/trampoline/trampoline to $target/bin.
35
Copy bin/timount/timount to $target/bin.
1092.1.11 by Matt Giuca
Replaced Python config files (conf.py) with new config files system, using
36
Copy etc/ivle.conf to /etc/ivle/ivle.conf.
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
37
chown and chmod the installed trampoline.
38
Copy www/ to $target.
39
Copy subjects/ to subjects directory (unless --nosubjects specified).
40
"""
41
42
    # Parse arguments
43
    parser = optparse.OptionParser(usage)
44
    parser.add_option("-n", "--dry",
45
        action="store_true", dest="dry",
46
        help="Print out the actions but don't do anything.")
47
    parser.add_option("-S", "--nosubjects",
48
        action="store_true", dest="nosubjects",
49
        help="Don't copy subject/ to subjects directory.")
1092.1.1 by William Grant
[Uber-commit of holiday work because I lacked a local copy of the branch.]
50
    parser.add_option("-R", "--nosvnrevno",
51
        action="store_true", dest="nosvnrevno",
52
        help="Don't write out the Subversion revision to the share directory.")
53
    parser.add_option("--root",
54
        action="store", dest="rootdir",
55
        help="Install into a different root directory.",
56
        default='/')
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
57
    (options, args) = parser.parse_args(args)
58
59
    # Call the real function
1092.1.1 by William Grant
[Uber-commit of holiday work because I lacked a local copy of the branch.]
60
    return __install(options.dry, options.nosubjects, options.rootdir,
61
                     options.nosvnrevno)
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
62
1092.1.1 by William Grant
[Uber-commit of holiday work because I lacked a local copy of the branch.]
63
def __install(dry=False, nosubjects=False, rootdir=None, nosvnrevno=False):
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
64
    # We need to import the one in the working copy, not in the system path.
65
    confmodule = __import__("ivle/conf/conf")
66
    install_list = util.InstallList()
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
67
1092.1.1 by William Grant
[Uber-commit of holiday work because I lacked a local copy of the branch.]
68
    # We need to apply make_install_path with the rootdir to an awful lot of
69
    # config variables, so make it easy:
70
    mip = functools.partial(util.make_install_path, rootdir)
71
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
72
    # Pull the required varibles out of the config
1092.1.1 by William Grant
[Uber-commit of holiday work because I lacked a local copy of the branch.]
73
    lib_path = mip(confmodule.lib_path)
74
    share_path = mip(confmodule.share_path)
75
    bin_path = mip(confmodule.bin_path)
76
    python_site_packages = mip(confmodule.python_site_packages)
77
    jail_base = mip(confmodule.jail_base)
78
    jail_system = mip(confmodule.jail_system)
79
    subjects_base = mip(confmodule.subjects_base)
80
    exercises_base = mip(confmodule.exercises_base)
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
81
82
    # Must be run as root or a dry run  
83
    if dry:
84
        print "Dry run (no actions will be executed)\n"
85
    
86
    if not dry and os.geteuid() != 0:
1092.1.8 by Matt Giuca
setup/install.py: Fixed non-root message (said it was build).
87
        print >>sys.stderr, "Must be root to run install"
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
88
        return 1
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
89
90
    # Make some directories for data.
1092.1.1 by William Grant
[Uber-commit of holiday work because I lacked a local copy of the branch.]
91
    util.action_mkdir(mip(confmodule.log_path), dry)
92
    util.action_mkdir(mip(confmodule.data_path), dry)
93
    util.action_mkdir(mip(confmodule.jail_base), dry)
94
    util.action_mkdir(mip(confmodule.jail_src_base), dry)
95
    util.action_mkdir(mip(confmodule.content_path), dry)
96
    util.action_mkdir(mip(confmodule.notices_path), dry)
97
    util.action_mkdir(os.path.join(mip(confmodule.data_path), 'sessions'), dry)
98
    util.action_mkdir(mip(confmodule.svn_path), dry)
99
    util.action_mkdir(mip(confmodule.svn_repo_path), dry)
100
    util.action_mkdir(os.path.join(mip(confmodule.svn_repo_path), 'users'),dry)
101
    util.action_mkdir(os.path.join(mip(confmodule.svn_repo_path),'groups'),dry)
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
102
1092.1.1 by William Grant
[Uber-commit of holiday work because I lacked a local copy of the branch.]
103
    util.action_chown(mip(confmodule.log_path), util.wwwuid, util.wwwuid, dry)
104
    util.action_chown(os.path.join(mip(confmodule.data_path), 'sessions'),
105
                      util.wwwuid, util.wwwuid, dry)
106
    util.action_chown(os.path.join(mip(confmodule.svn_repo_path), 'users'),
107
                      util.wwwuid, util.wwwuid, dry)
108
    util.action_chown(os.path.join(mip(confmodule.svn_repo_path), 'groups'),
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
109
                      util.wwwuid, util.wwwuid, dry)
110
111
    # Create lib and copy the compiled files there
112
    util.action_mkdir(lib_path, dry)
113
114
    tramppath = os.path.join(lib_path, 'trampoline')
115
    util.action_copyfile('bin/trampoline/trampoline', tramppath, dry)
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
116
    # chown trampoline to root and set setuid bit
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
117
    util.action_chown_setuid(tramppath, dry)
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
118
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
119
    timountpath = os.path.join(lib_path, 'timount')
120
    util.action_copyfile('bin/timount/timount', timountpath, dry)
813 by William Grant
Merge jails-redux branch. We now use aufs rather than hardlinking tens
121
1092.1.11 by Matt Giuca
Replaced Python config files (conf.py) with new config files system, using
122
    ivleconfpath = mip('/etc/ivle/ivle.conf')
123
    util.action_copyfile('etc/ivle.conf', ivleconfpath, dry)
124
1092.1.1 by William Grant
[Uber-commit of holiday work because I lacked a local copy of the branch.]
125
    # Copy in the services (only usrmgt-server is needed on the host, but
126
    # the jail build requires the rest).
127
    util.action_copylist(install_list.list_services, share_path, dry)
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
128
    usrmgtpath = os.path.join(share_path, 'services/usrmgt-server')
129
    util.action_chmod_x(usrmgtpath, dry)
130
131
    # Copy the user-executable binaries using the list.
132
    util.action_copylist(install_list.list_user_binaries, bin_path, dry,
133
                         onlybasename=True)
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
134
1092.1.1 by William Grant
[Uber-commit of holiday work because I lacked a local copy of the branch.]
135
    # Copy the www directory (using the list)
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
136
    util.action_copylist(install_list.list_www, share_path, dry)
1092.1.1 by William Grant
[Uber-commit of holiday work because I lacked a local copy of the branch.]
137
138
    # Set appropriate permissions on the php directory
139
    forum_dir = "www/php/phpBB3"
140
    forum_path = os.path.join(share_path, forum_dir)
141
    print "chown -R www-data:www-data %s" % forum_path
142
    if not dry:
143
        os.system("chown -R www-data:www-data %s" % forum_path)
144
145
    # Copy the lib directory (using the list)
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
146
    util.action_copylist(install_list.list_ivle_lib, python_site_packages, dry)
1092.1.1 by William Grant
[Uber-commit of holiday work because I lacked a local copy of the branch.]
147
1013 by dcoles
Setup: Ensure that conf.py inside ivle install directory (usually /opt/ivle) is
148
    # Make the config file private
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
149
    configpath = os.path.join(python_site_packages, 'ivle/conf/conf.py')
150
    util.action_make_private(configpath, dry)
1013 by dcoles
Setup: Ensure that conf.py inside ivle install directory (usually /opt/ivle) is
151
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
152
    if not nosubjects:
153
        # Copy the subjects and exercises directories across
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
154
        util.action_mkdir(subjects_base, dry)
155
        util.action_copylist(install_list.list_subjects, subjects_base, dry,
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
156
            srcdir="./subjects")
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
157
        util.action_mkdir(exercises_base, dry)
158
        util.action_copylist(install_list.list_exercises, exercises_base, dry,
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
159
            srcdir="./exercises")
160
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
161
    # XXX We shouldn't have ivle.pth at all any more.
162
    # We may still need the www packages to be importable.
163
    # Anything from www that is needed from the outside should go to lib.
164
    ivle_pth = os.path.join(python_site_packages, "ivle.pth")
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
165
    try:
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
166
        file = open(ivle_pth, 'w')
167
        file.write(os.path.join(share_path, "www"))
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
168
        file.close()
169
    except (IOError, OSError):
170
        pass
171
1092.1.1 by William Grant
[Uber-commit of holiday work because I lacked a local copy of the branch.]
172
    if not nosvnrevno:
173
        # Create the ivle working revision record file
174
        ivle_revision_file = os.path.join(share_path, 'revision.txt')
175
        if not dry:
176
            try:
177
                conf = open(ivle_revision_file, "w")
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
178
1092.1.1 by William Grant
[Uber-commit of holiday work because I lacked a local copy of the branch.]
179
                conf.write("""# SVN revision r%s
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
180
# Source tree location: %s
181
# Modified files:
182
""" % (util.get_svn_revision(), os.getcwd()))
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
183
1092.1.1 by William Grant
[Uber-commit of holiday work because I lacked a local copy of the branch.]
184
                conf.close()
185
            except IOError, (errno, strerror):
186
                print "IO error(%s): %s" % (errno, strerror)
187
                sys.exit(1)
188
189
            os.system("svn status . >> %s" % ivle_revision_file)
190
191
        print "Wrote IVLE code revision status to %s" % ivle_revision_file
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
192
193
    return 0
194