~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
1184 by Matt Giuca
setup/install.py: Now compute python site-packages path using
26
import distutils.sysconfig
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
27
28
from setup import util
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
29
30
def install(args):
31
    usage = """usage: %prog install [options]
32
(Requires root)
33
Create target install directory ($target).
34
Create $target/bin.
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
35
Copy bin/trampoline/trampoline to $target/bin.
36
Copy bin/timount/timount to $target/bin.
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
"""
39
40
    # Parse arguments
41
    parser = optparse.OptionParser(usage)
42
    parser.add_option("-n", "--dry",
43
        action="store_true", dest="dry",
44
        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.]
45
    parser.add_option("--root",
46
        action="store", dest="rootdir",
47
        help="Install into a different root directory.",
48
        default='/')
1092.1.43 by Matt Giuca
setup.install: Now takes --prefix and --python-site-packages as arguments. NO
49
    parser.add_option("--prefix",
50
        action="store", dest="prefix",
51
        help="Base prefix to install IVLE into (default: /usr/local).",
52
        default='/usr/local')
53
    parser.add_option("--python-site-packages",
54
        action="store", dest="python_site_packages",
55
        help="Path to Python site packages directory.",
1183 by Matt Giuca
setup/install.py: Now uses --prefix to compute the Python site packages path.
56
        default=None)
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
1182 by Matt Giuca
setup/install.py: Now forces --prefix to be an absolute path, to avoid
59
    # Prefix must be absolute (not really necessary, but since a relative
60
    # prefix will be taken relative to *root* not working directory, it is
61
    # confusing if we allow it).
62
    if options.prefix[:1] not in (os.path.sep, os.path.altsep):
63
        print >>sys.stderr, """prefix must be an absolute path.
64
    (This will be interpreted relative to root, so provide --root=. if you
65
    want a path relative to the working directory)."""
66
        return 1
67
1183 by Matt Giuca
setup/install.py: Now uses --prefix to compute the Python site packages path.
68
    # Calculate python_site_packages using the supplied prefix
69
    if options.python_site_packages is None:
1184 by Matt Giuca
setup/install.py: Now compute python site-packages path using
70
        options.python_site_packages = distutils.sysconfig.get_python_lib(
71
            prefix=options.prefix)
1183 by Matt Giuca
setup/install.py: Now uses --prefix to compute the Python site packages path.
72
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
73
    # Call the real function
1092.1.43 by Matt Giuca
setup.install: Now takes --prefix and --python-site-packages as arguments. NO
74
    return __install(prefix=options.prefix,
75
                     python_site_packages=options.python_site_packages,
1237 by William Grant
Kill --nosvnrevno from setup.install - we don't use Subversion now.
76
                     dry=options.dry, rootdir=options.rootdir)
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
77
1237 by William Grant
Kill --nosvnrevno from setup.install - we don't use Subversion now.
78
def __install(prefix, python_site_packages, dry=False, rootdir=None):
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
79
    install_list = util.InstallList()
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
80
1092.1.1 by William Grant
[Uber-commit of holiday work because I lacked a local copy of the branch.]
81
    # We need to apply make_install_path with the rootdir to an awful lot of
82
    # config variables, so make it easy:
83
    mip = functools.partial(util.make_install_path, rootdir)
84
1092.1.43 by Matt Giuca
setup.install: Now takes --prefix and --python-site-packages as arguments. NO
85
    # Compute the lib_path, share_path and bin_path (copied from
86
    # ivle/conf/conf.py).
87
    lib_path = mip(os.path.join(prefix, 'lib/ivle'))
88
    share_path = mip(os.path.join(prefix, 'share/ivle'))
89
    bin_path = mip(os.path.join(prefix, 'bin'))
90
    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
91
92
    # Must be run as root or a dry run  
93
    if dry:
94
        print "Dry run (no actions will be executed)\n"
95
    
96
    if not dry and os.geteuid() != 0:
1092.1.8 by Matt Giuca
setup/install.py: Fixed non-root message (said it was build).
97
        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
98
        return 1
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
99
1092.1.57 by William Grant
Installing will now create /etc/ivle.
100
    # Create the config directory.
1099.1.170 by William Grant
mip() the config dir when installing.
101
    util.action_mkdir(mip('/etc/ivle/plugins.d'), dry)
1092.1.57 by William Grant
Installing will now create /etc/ivle.
102
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
103
    # Create lib and copy the compiled files there
104
    util.action_mkdir(lib_path, dry)
105
106
    tramppath = os.path.join(lib_path, 'trampoline')
107
    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
108
    # chown trampoline to root and set setuid bit
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
109
    util.action_chown_setuid(tramppath, dry)
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
110
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
111
    timountpath = os.path.join(lib_path, 'timount')
112
    util.action_copyfile('bin/timount/timount', timountpath, dry)
813 by William Grant
Merge jails-redux branch. We now use aufs rather than hardlinking tens
113
1092.1.1 by William Grant
[Uber-commit of holiday work because I lacked a local copy of the branch.]
114
    # Copy in the services (only usrmgt-server is needed on the host, but
115
    # the jail build requires the rest).
116
    util.action_copylist(install_list.list_services, share_path, dry)
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
117
    usrmgtpath = os.path.join(share_path, 'services/usrmgt-server')
118
    util.action_chmod_x(usrmgtpath, dry)
119
120
    # Copy the user-executable binaries using the list.
121
    util.action_copylist(install_list.list_user_binaries, bin_path, dry,
122
                         onlybasename=True)
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
123
1092.1.1 by William Grant
[Uber-commit of holiday work because I lacked a local copy of the branch.]
124
    # Copy the lib directory (using the list)
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
125
    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.]
126
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
127
    return 0
128