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

« back to all changes in this revision

Viewing changes to setup/install.py

  • Committer: mattgiuca
  • Date: 2008-01-25 01:05:22 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:300
conf/apps: Added TutorialService as a registered app.
tutorialservice: Started writing app. Currently reads some arguments, and if
    action=test and code is provided, echoes the code back in JSON.

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