~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
1092.1.43 by Matt Giuca
setup.install: Now takes --prefix and --python-site-packages as arguments. NO
29
PYTHON_VERSION = sys.version[:3]
30
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
31
def install(args):
32
    usage = """usage: %prog install [options]
33
(Requires root)
34
Create target install directory ($target).
35
Create $target/bin.
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
36
Copy bin/trampoline/trampoline to $target/bin.
37
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
38
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
39
chown and chmod the installed trampoline.
40
Copy www/ to $target.
41
"""
42
43
    # Parse arguments
44
    parser = optparse.OptionParser(usage)
45
    parser.add_option("-n", "--dry",
46
        action="store_true", dest="dry",
47
        help="Print out the actions but don't do anything.")
1092.1.1 by William Grant
[Uber-commit of holiday work because I lacked a local copy of the branch.]
48
    parser.add_option("-R", "--nosvnrevno",
49
        action="store_true", dest="nosvnrevno",
50
        help="Don't write out the Subversion revision to the share directory.")
51
    parser.add_option("--root",
52
        action="store", dest="rootdir",
53
        help="Install into a different root directory.",
54
        default='/')
1092.1.43 by Matt Giuca
setup.install: Now takes --prefix and --python-site-packages as arguments. NO
55
    parser.add_option("--prefix",
56
        action="store", dest="prefix",
57
        help="Base prefix to install IVLE into (default: /usr/local).",
58
        default='/usr/local')
59
    parser.add_option("--python-site-packages",
60
        action="store", dest="python_site_packages",
61
        help="Path to Python site packages directory.",
1092.1.47 by William Grant
Install to /usr/local/lib/python2.5/site-packages, not
62
        default='/usr/local/lib/python%s/site-packages' % PYTHON_VERSION)
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
63
    (options, args) = parser.parse_args(args)
64
65
    # Call the real function
1092.1.43 by Matt Giuca
setup.install: Now takes --prefix and --python-site-packages as arguments. NO
66
    return __install(prefix=options.prefix,
67
                     python_site_packages=options.python_site_packages,
68
                     dry=options.dry, rootdir=options.rootdir,
1092.1.42 by Matt Giuca
setup.install: Removed a lot of install steps, which created directories and
69
                     nosvnrevno=options.nosvnrevno)
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
70
1092.1.43 by Matt Giuca
setup.install: Now takes --prefix and --python-site-packages as arguments. NO
71
def __install(prefix, python_site_packages, dry=False, rootdir=None,
72
              nosvnrevno=False):
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
73
    install_list = util.InstallList()
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
74
1092.1.1 by William Grant
[Uber-commit of holiday work because I lacked a local copy of the branch.]
75
    # We need to apply make_install_path with the rootdir to an awful lot of
76
    # config variables, so make it easy:
77
    mip = functools.partial(util.make_install_path, rootdir)
78
1092.1.43 by Matt Giuca
setup.install: Now takes --prefix and --python-site-packages as arguments. NO
79
    # Compute the lib_path, share_path and bin_path (copied from
80
    # ivle/conf/conf.py).
81
    lib_path = mip(os.path.join(prefix, 'lib/ivle'))
82
    share_path = mip(os.path.join(prefix, 'share/ivle'))
83
    bin_path = mip(os.path.join(prefix, 'bin'))
84
    python_site_packages = mip(python_site_packages)
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
85
86
    # Must be run as root or a dry run  
87
    if dry:
88
        print "Dry run (no actions will be executed)\n"
89
    
90
    if not dry and os.geteuid() != 0:
1092.1.8 by Matt Giuca
setup/install.py: Fixed non-root message (said it was build).
91
        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
92
        return 1
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
93
94
    # Create lib and copy the compiled files there
95
    util.action_mkdir(lib_path, dry)
96
97
    tramppath = os.path.join(lib_path, 'trampoline')
98
    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
99
    # chown trampoline to root and set setuid bit
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
100
    util.action_chown_setuid(tramppath, dry)
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
101
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
102
    timountpath = os.path.join(lib_path, 'timount')
103
    util.action_copyfile('bin/timount/timount', timountpath, dry)
813 by William Grant
Merge jails-redux branch. We now use aufs rather than hardlinking tens
104
1092.1.1 by William Grant
[Uber-commit of holiday work because I lacked a local copy of the branch.]
105
    # Copy in the services (only usrmgt-server is needed on the host, but
106
    # the jail build requires the rest).
107
    util.action_copylist(install_list.list_services, share_path, dry)
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
108
    usrmgtpath = os.path.join(share_path, 'services/usrmgt-server')
109
    util.action_chmod_x(usrmgtpath, dry)
110
111
    # Copy the user-executable binaries using the list.
112
    util.action_copylist(install_list.list_user_binaries, bin_path, dry,
113
                         onlybasename=True)
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
114
1092.1.1 by William Grant
[Uber-commit of holiday work because I lacked a local copy of the branch.]
115
    # Copy the www directory (using the list)
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
116
    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.]
117
118
    # Set appropriate permissions on the php directory
119
    forum_dir = "www/php/phpBB3"
120
    forum_path = os.path.join(share_path, forum_dir)
121
    print "chown -R www-data:www-data %s" % forum_path
122
    if not dry:
123
        os.system("chown -R www-data:www-data %s" % forum_path)
124
125
    # Copy the lib directory (using the list)
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
126
    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.]
127
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
128
    # XXX We shouldn't have ivle.pth at all any more.
129
    # We may still need the www packages to be importable.
130
    # Anything from www that is needed from the outside should go to lib.
131
    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
132
    try:
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
133
        file = open(ivle_pth, 'w')
134
        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
135
        file.close()
136
    except (IOError, OSError):
137
        pass
138
1092.1.1 by William Grant
[Uber-commit of holiday work because I lacked a local copy of the branch.]
139
    if not nosvnrevno:
140
        # Create the ivle working revision record file
141
        ivle_revision_file = os.path.join(share_path, 'revision.txt')
142
        if not dry:
143
            try:
144
                conf = open(ivle_revision_file, "w")
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
145
1092.1.1 by William Grant
[Uber-commit of holiday work because I lacked a local copy of the branch.]
146
                conf.write("""# SVN revision r%s
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
147
# Source tree location: %s
148
# Modified files:
149
""" % (util.get_svn_revision(), os.getcwd()))
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
150
1092.1.1 by William Grant
[Uber-commit of holiday work because I lacked a local copy of the branch.]
151
                conf.close()
152
            except IOError, (errno, strerror):
153
                print "IO error(%s): %s" % (errno, strerror)
154
                sys.exit(1)
155
156
            os.system("svn status . >> %s" % ivle_revision_file)
157
158
        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
159
160
    return 0
161