42
44
parser.add_option("-n", "--dry",
43
45
action="store_true", dest="dry",
44
46
help="Print out the actions but don't do anything.")
47
parser.add_option("-S", "--nosubjects",
48
action="store_true", dest="nosubjects",
49
help="Don't copy subject/ to subjects directory.")
50
parser.add_option("-R", "--nosvnrevno",
51
action="store_true", dest="nosvnrevno",
52
help="Don't write out the Subversion revision to the share directory.")
45
53
parser.add_option("--root",
46
54
action="store", dest="rootdir",
47
55
help="Install into a different root directory.",
49
parser.add_option("--prefix",
50
action="store", dest="prefix",
51
help="Base prefix to install IVLE into (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.",
57
57
(options, args) = parser.parse_args(args)
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)."""
68
# Calculate python_site_packages using the supplied prefix
69
if options.python_site_packages is None:
70
options.python_site_packages = distutils.sysconfig.get_python_lib(
71
prefix=options.prefix)
73
59
# Call the real function
74
return __install(prefix=options.prefix,
75
python_site_packages=options.python_site_packages,
76
dry=options.dry, rootdir=options.rootdir)
60
return __install(options.dry, options.nosubjects, options.rootdir,
78
def __install(prefix, python_site_packages, dry=False, rootdir=None):
63
def __install(dry=False, nosubjects=False, rootdir=None, nosvnrevno=False):
64
# We need to import the one in the working copy, not in the system path.
65
confmodule = __import__("ivle/conf/conf")
79
66
install_list = util.InstallList()
81
68
# We need to apply make_install_path with the rootdir to an awful lot of
82
69
# config variables, so make it easy:
83
70
mip = functools.partial(util.make_install_path, rootdir)
85
# Compute the lib_path, share_path and bin_path (copied from
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)
72
# Pull the required varibles out of the config
73
lib_path = mip(confmodule.lib_path)
74
share_path = mip(confmodule.share_path)
75
bin_path = mip(confmodule.bin_path)
76
python_site_packages = mip(confmodule.python_site_packages)
77
jail_base = mip(confmodule.jail_base)
78
jail_system = mip(confmodule.jail_system)
79
subjects_base = mip(confmodule.subjects_base)
80
exercises_base = mip(confmodule.exercises_base)
92
82
# Must be run as root or a dry run
97
87
print >>sys.stderr, "Must be root to run install"
100
# Create the config directory.
101
util.action_mkdir(mip('/etc/ivle/plugins.d'), dry)
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)
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)
103
111
# Create lib and copy the compiled files there
104
112
util.action_mkdir(lib_path, dry)
121
132
util.action_copylist(install_list.list_user_binaries, bin_path, dry,
122
133
onlybasename=True)
135
# Copy the www directory (using the list)
136
util.action_copylist(install_list.list_www, share_path, dry)
138
# Set appropriate permissions on the php directory
139
forum_dir = "www/php/phpBB3"
140
forum_path = os.path.join(share_path, forum_dir)
141
print "chown -R www-data:www-data %s" % forum_path
143
os.system("chown -R www-data:www-data %s" % forum_path)
124
145
# Copy the lib directory (using the list)
125
146
util.action_copylist(install_list.list_ivle_lib, python_site_packages, dry)
148
# Make the config file private
149
configpath = os.path.join(python_site_packages, 'ivle/conf/conf.py')
150
util.action_make_private(configpath, dry)
153
# Copy the subjects and exercises directories across
154
util.action_mkdir(subjects_base, dry)
155
util.action_copylist(install_list.list_subjects, subjects_base, dry,
157
util.action_mkdir(exercises_base, dry)
158
util.action_copylist(install_list.list_exercises, exercises_base, dry,
159
srcdir="./exercises")
161
# XXX We shouldn't have ivle.pth at all any more.
162
# We may still need the www packages to be importable.
163
# Anything from www that is needed from the outside should go to lib.
164
ivle_pth = os.path.join(python_site_packages, "ivle.pth")
166
file = open(ivle_pth, 'w')
167
file.write(os.path.join(share_path, "www"))
169
except (IOError, OSError):
173
# Create the ivle working revision record file
174
ivle_revision_file = os.path.join(share_path, 'revision.txt')
177
conf = open(ivle_revision_file, "w")
179
conf.write("""# SVN revision r%s
180
# Source tree location: %s
182
""" % (util.get_svn_revision(), os.getcwd()))
185
except IOError, (errno, strerror):
186
print "IO error(%s): %s" % (errno, strerror)
189
os.system("svn status . >> %s" % ivle_revision_file)
191
print "Wrote IVLE code revision status to %s" % ivle_revision_file