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

« back to all changes in this revision

Viewing changes to setup/install.py

  • Committer: William Grant
  • Date: 2009-02-24 13:29:44 UTC
  • Revision ID: grantw@unimelb.edu.au-20090224132944-lm29zd1li1rjg77p
Privileges (apart from admin) are now offering-local, not global.

Offering privileges are granted by Enrolment.role, and global admin
by User.admin. ivle.caps is dead.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
 
27
27
from setup import util
28
28
 
 
29
PYTHON_VERSION = sys.version[:3]
 
30
 
29
31
def install(args):
30
32
    usage = """usage: %prog install [options]
31
33
(Requires root)
34
36
Copy bin/trampoline/trampoline to $target/bin.
35
37
Copy bin/timount/timount to $target/bin.
36
38
chown and chmod the installed trampoline.
37
 
Copy www/ to $target.
38
 
Copy subjects/ to subjects directory (unless --nosubjects specified).
39
39
"""
40
40
 
41
41
    # Parse arguments
43
43
    parser.add_option("-n", "--dry",
44
44
        action="store_true", dest="dry",
45
45
        help="Print out the actions but don't do anything.")
46
 
    parser.add_option("-S", "--nosubjects",
47
 
        action="store_true", dest="nosubjects",
48
 
        help="Don't copy subject/ to subjects directory.")
49
46
    parser.add_option("-R", "--nosvnrevno",
50
47
        action="store_true", dest="nosvnrevno",
51
48
        help="Don't write out the Subversion revision to the share directory.")
53
50
        action="store", dest="rootdir",
54
51
        help="Install into a different root directory.",
55
52
        default='/')
 
53
    parser.add_option("--prefix",
 
54
        action="store", dest="prefix",
 
55
        help="Base prefix to install IVLE into (default: /usr/local).",
 
56
        default='/usr/local')
 
57
    parser.add_option("--python-site-packages",
 
58
        action="store", dest="python_site_packages",
 
59
        help="Path to Python site packages directory.",
 
60
        default='/usr/local/lib/python%s/site-packages' % PYTHON_VERSION)
56
61
    (options, args) = parser.parse_args(args)
57
62
 
58
63
    # Call the real function
59
 
    return __install(options.dry, options.nosubjects, options.rootdir,
60
 
                     options.nosvnrevno)
 
64
    return __install(prefix=options.prefix,
 
65
                     python_site_packages=options.python_site_packages,
 
66
                     dry=options.dry, rootdir=options.rootdir,
 
67
                     nosvnrevno=options.nosvnrevno)
61
68
 
62
 
def __install(dry=False, nosubjects=False, rootdir=None, nosvnrevno=False):
63
 
    # We need to import the one in the working copy, not in the system path.
64
 
    confmodule = __import__("ivle/conf/conf")
 
69
def __install(prefix, python_site_packages, dry=False, rootdir=None,
 
70
              nosvnrevno=False):
65
71
    install_list = util.InstallList()
66
72
 
67
73
    # We need to apply make_install_path with the rootdir to an awful lot of
68
74
    # config variables, so make it easy:
69
75
    mip = functools.partial(util.make_install_path, rootdir)
70
76
 
71
 
    # Pull the required varibles out of the config
72
 
    lib_path = mip(confmodule.lib_path)
73
 
    share_path = mip(confmodule.share_path)
74
 
    bin_path = mip(confmodule.bin_path)
75
 
    python_site_packages = mip(confmodule.python_site_packages)
76
 
    jail_base = mip(confmodule.jail_base)
77
 
    jail_system = mip(confmodule.jail_system)
78
 
    subjects_base = mip(confmodule.subjects_base)
79
 
    exercises_base = mip(confmodule.exercises_base)
 
77
    # Compute the lib_path, share_path and bin_path (copied from
 
78
    # ivle/conf/conf.py).
 
79
    lib_path = mip(os.path.join(prefix, 'lib/ivle'))
 
80
    share_path = mip(os.path.join(prefix, 'share/ivle'))
 
81
    bin_path = mip(os.path.join(prefix, 'bin'))
 
82
    python_site_packages = mip(python_site_packages)
80
83
 
81
84
    # Must be run as root or a dry run  
82
85
    if dry:
83
86
        print "Dry run (no actions will be executed)\n"
84
87
    
85
88
    if not dry and os.geteuid() != 0:
86
 
        print >>sys.stderr, "Must be root to run build"
87
 
        print >>sys.stderr, "(I need to chown)."
 
89
        print >>sys.stderr, "Must be root to run install"
88
90
        return 1
89
91
 
90
 
    # Make some directories for data.
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)
102
 
 
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'),
109
 
                      util.wwwuid, util.wwwuid, dry)
 
92
    # Create the config directory.
 
93
    util.action_mkdir(mip('/etc/ivle/plugins.d'), dry)
110
94
 
111
95
    # Create lib and copy the compiled files there
112
96
    util.action_mkdir(lib_path, dry)
129
113
    util.action_copylist(install_list.list_user_binaries, bin_path, dry,
130
114
                         onlybasename=True)
131
115
 
132
 
    # Copy the www directory (using the list)
133
 
    util.action_copylist(install_list.list_www, share_path, dry)
134
 
 
135
 
    # Set appropriate permissions on the php directory
136
 
    forum_dir = "www/php/phpBB3"
137
 
    forum_path = os.path.join(share_path, forum_dir)
138
 
    print "chown -R www-data:www-data %s" % forum_path
139
 
    if not dry:
140
 
        os.system("chown -R www-data:www-data %s" % forum_path)
141
 
 
142
116
    # Copy the lib directory (using the list)
143
117
    util.action_copylist(install_list.list_ivle_lib, python_site_packages, dry)
144
118
 
145
 
    # Make the config file private
146
 
    configpath = os.path.join(python_site_packages, 'ivle/conf/conf.py')
147
 
    util.action_make_private(configpath, dry)
148
 
 
149
 
    if not nosubjects:
150
 
        # Copy the subjects and exercises directories across
151
 
        util.action_mkdir(subjects_base, dry)
152
 
        util.action_copylist(install_list.list_subjects, subjects_base, dry,
153
 
            srcdir="./subjects")
154
 
        util.action_mkdir(exercises_base, dry)
155
 
        util.action_copylist(install_list.list_exercises, exercises_base, dry,
156
 
            srcdir="./exercises")
157
 
 
158
 
    # XXX We shouldn't have ivle.pth at all any more.
159
 
    # We may still need the www packages to be importable.
160
 
    # Anything from www that is needed from the outside should go to lib.
161
 
    ivle_pth = os.path.join(python_site_packages, "ivle.pth")
162
 
    try:
163
 
        file = open(ivle_pth, 'w')
164
 
        file.write(os.path.join(share_path, "www"))
165
 
        file.close()
166
 
    except (IOError, OSError):
167
 
        pass
168
 
 
169
119
    if not nosvnrevno:
170
120
        # Create the ivle working revision record file
171
121
        ivle_revision_file = os.path.join(share_path, 'revision.txt')