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

« back to all changes in this revision

Viewing changes to setup/install.py

  • Committer: Matt Giuca
  • Date: 2009-04-22 04:56:58 UTC
  • Revision ID: matt.giuca@gmail.com-20090422045658-nnfepg0902n3mwtq
ivle.makeuser: Fixed odd code which would create the home directory, then
    immediately clobber it by restoring the backup.
    This broke in Python 2.6 because the behaviour of shutil.move changed.
    (Commented).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
24
import sys
 
25
import functools
 
26
import distutils.sysconfig
 
27
 
 
28
from setup import util
 
29
 
 
30
def install(args):
 
31
    usage = """usage: %prog install [options]
 
32
(Requires root)
 
33
Create target install directory ($target).
 
34
Create $target/bin.
 
35
Copy bin/trampoline/trampoline to $target/bin.
 
36
Copy bin/timount/timount to $target/bin.
 
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.")
 
45
    parser.add_option("-R", "--nosvnrevno",
 
46
        action="store_true", dest="nosvnrevno",
 
47
        help="Don't write out the Subversion revision to the share directory.")
 
48
    parser.add_option("--root",
 
49
        action="store", dest="rootdir",
 
50
        help="Install into a different root directory.",
 
51
        default='/')
 
52
    parser.add_option("--prefix",
 
53
        action="store", dest="prefix",
 
54
        help="Base prefix to install IVLE into (default: /usr/local).",
 
55
        default='/usr/local')
 
56
    parser.add_option("--python-site-packages",
 
57
        action="store", dest="python_site_packages",
 
58
        help="Path to Python site packages directory.",
 
59
        default=None)
 
60
    (options, args) = parser.parse_args(args)
 
61
 
 
62
    # Prefix must be absolute (not really necessary, but since a relative
 
63
    # prefix will be taken relative to *root* not working directory, it is
 
64
    # confusing if we allow it).
 
65
    print options.prefix[:1]
 
66
    if options.prefix[:1] not in (os.path.sep, os.path.altsep):
 
67
        print >>sys.stderr, """prefix must be an absolute path.
 
68
    (This will be interpreted relative to root, so provide --root=. if you
 
69
    want a path relative to the working directory)."""
 
70
        return 1
 
71
 
 
72
    # Calculate python_site_packages using the supplied prefix
 
73
    if options.python_site_packages is None:
 
74
        options.python_site_packages = distutils.sysconfig.get_python_lib(
 
75
            prefix=options.prefix)
 
76
 
 
77
    # Call the real function
 
78
    return __install(prefix=options.prefix,
 
79
                     python_site_packages=options.python_site_packages,
 
80
                     dry=options.dry, rootdir=options.rootdir,
 
81
                     nosvnrevno=options.nosvnrevno)
 
82
 
 
83
def __install(prefix, python_site_packages, dry=False, rootdir=None,
 
84
              nosvnrevno=False):
 
85
    install_list = util.InstallList()
 
86
 
 
87
    # We need to apply make_install_path with the rootdir to an awful lot of
 
88
    # config variables, so make it easy:
 
89
    mip = functools.partial(util.make_install_path, rootdir)
 
90
 
 
91
    # Compute the lib_path, share_path and bin_path (copied from
 
92
    # ivle/conf/conf.py).
 
93
    lib_path = mip(os.path.join(prefix, 'lib/ivle'))
 
94
    share_path = mip(os.path.join(prefix, 'share/ivle'))
 
95
    bin_path = mip(os.path.join(prefix, 'bin'))
 
96
    python_site_packages = mip(python_site_packages)
 
97
 
 
98
    # Must be run as root or a dry run  
 
99
    if dry:
 
100
        print "Dry run (no actions will be executed)\n"
 
101
    
 
102
    if not dry and os.geteuid() != 0:
 
103
        print >>sys.stderr, "Must be root to run install"
 
104
        return 1
 
105
 
 
106
    # Create the config directory.
 
107
    util.action_mkdir(mip('/etc/ivle/plugins.d'), dry)
 
108
 
 
109
    # Create lib and copy the compiled files there
 
110
    util.action_mkdir(lib_path, dry)
 
111
 
 
112
    tramppath = os.path.join(lib_path, 'trampoline')
 
113
    util.action_copyfile('bin/trampoline/trampoline', tramppath, dry)
 
114
    # chown trampoline to root and set setuid bit
 
115
    util.action_chown_setuid(tramppath, dry)
 
116
 
 
117
    timountpath = os.path.join(lib_path, 'timount')
 
118
    util.action_copyfile('bin/timount/timount', timountpath, dry)
 
119
 
 
120
    # Copy in the services (only usrmgt-server is needed on the host, but
 
121
    # the jail build requires the rest).
 
122
    util.action_copylist(install_list.list_services, share_path, dry)
 
123
    usrmgtpath = os.path.join(share_path, 'services/usrmgt-server')
 
124
    util.action_chmod_x(usrmgtpath, dry)
 
125
 
 
126
    # Copy the user-executable binaries using the list.
 
127
    util.action_copylist(install_list.list_user_binaries, bin_path, dry,
 
128
                         onlybasename=True)
 
129
 
 
130
    # Copy the lib directory (using the list)
 
131
    util.action_copylist(install_list.list_ivle_lib, python_site_packages, dry)
 
132
 
 
133
    if not nosvnrevno:
 
134
        # Create the ivle working revision record file
 
135
        ivle_revision_file = os.path.join(share_path, 'revision.txt')
 
136
        if not dry:
 
137
            try:
 
138
                conf = open(ivle_revision_file, "w")
 
139
 
 
140
                conf.write("""# SVN revision r%s
 
141
# Source tree location: %s
 
142
# Modified files:
 
143
""" % (util.get_svn_revision(), os.getcwd()))
 
144
 
 
145
                conf.close()
 
146
            except IOError, (errno, strerror):
 
147
                print "IO error(%s): %s" % (errno, strerror)
 
148
                sys.exit(1)
 
149
 
 
150
            os.system("svn status . >> %s" % ivle_revision_file)
 
151
 
 
152
        print "Wrote IVLE code revision status to %s" % ivle_revision_file
 
153
 
 
154
    return 0
 
155