42
43
parser.add_option("-n", "--dry",
43
44
action="store_true", dest="dry",
44
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.")
45
49
parser.add_option("-R", "--nosvnrevno",
46
50
action="store_true", dest="nosvnrevno",
47
51
help="Don't write out the Subversion revision to the share directory.")
49
53
action="store", dest="rootdir",
50
54
help="Install into a different root directory.",
52
parser.add_option("--prefix",
53
action="store", dest="prefix",
54
help="Base prefix to install IVLE into (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.",
60
56
(options, args) = parser.parse_args(args)
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
if options.prefix[:1] not in (os.path.sep, os.path.altsep):
66
print >>sys.stderr, """prefix must be an absolute path.
67
(This will be interpreted relative to root, so provide --root=. if you
68
want a path relative to the working directory)."""
71
# Calculate python_site_packages using the supplied prefix
72
if options.python_site_packages is None:
73
options.python_site_packages = distutils.sysconfig.get_python_lib(
74
prefix=options.prefix)
76
58
# Call the real function
77
return __install(prefix=options.prefix,
78
python_site_packages=options.python_site_packages,
79
dry=options.dry, rootdir=options.rootdir,
80
nosvnrevno=options.nosvnrevno)
59
return __install(options.dry, options.nosubjects, options.rootdir,
82
def __install(prefix, python_site_packages, dry=False, rootdir=None,
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")
84
65
install_list = util.InstallList()
86
67
# We need to apply make_install_path with the rootdir to an awful lot of
87
68
# config variables, so make it easy:
88
69
mip = functools.partial(util.make_install_path, rootdir)
90
# Compute the lib_path, share_path and bin_path (copied from
92
lib_path = mip(os.path.join(prefix, 'lib/ivle'))
93
share_path = mip(os.path.join(prefix, 'share/ivle'))
94
bin_path = mip(os.path.join(prefix, 'bin'))
95
python_site_packages = mip(python_site_packages)
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)
97
81
# Must be run as root or a dry run
102
86
print >>sys.stderr, "Must be root to run install"
105
# Create the config directory.
106
util.action_mkdir(mip('/etc/ivle/plugins.d'), dry)
89
# Make some directories for data.
90
util.action_mkdir(mip(confmodule.log_path), dry)
91
util.action_mkdir(mip(confmodule.data_path), dry)
92
util.action_mkdir(mip(confmodule.jail_base), dry)
93
util.action_mkdir(mip(confmodule.jail_src_base), dry)
94
util.action_mkdir(mip(confmodule.content_path), dry)
95
util.action_mkdir(mip(confmodule.notices_path), dry)
96
util.action_mkdir(os.path.join(mip(confmodule.data_path), 'sessions'), dry)
97
util.action_mkdir(mip(confmodule.svn_path), dry)
98
util.action_mkdir(mip(confmodule.svn_repo_path), dry)
99
util.action_mkdir(os.path.join(mip(confmodule.svn_repo_path), 'users'),dry)
100
util.action_mkdir(os.path.join(mip(confmodule.svn_repo_path),'groups'),dry)
102
util.action_chown(mip(confmodule.log_path), util.wwwuid, util.wwwuid, dry)
103
util.action_chown(os.path.join(mip(confmodule.data_path), 'sessions'),
104
util.wwwuid, util.wwwuid, dry)
105
util.action_chown(os.path.join(mip(confmodule.svn_repo_path), 'users'),
106
util.wwwuid, util.wwwuid, dry)
107
util.action_chown(os.path.join(mip(confmodule.svn_repo_path), 'groups'),
108
util.wwwuid, util.wwwuid, dry)
108
110
# Create lib and copy the compiled files there
109
111
util.action_mkdir(lib_path, dry)
126
128
util.action_copylist(install_list.list_user_binaries, bin_path, dry,
127
129
onlybasename=True)
131
# Copy the www directory (using the list)
132
util.action_copylist(install_list.list_www, share_path, dry)
134
# Set appropriate permissions on the php directory
135
forum_dir = "www/php/phpBB3"
136
forum_path = os.path.join(share_path, forum_dir)
137
print "chown -R www-data:www-data %s" % forum_path
139
os.system("chown -R www-data:www-data %s" % forum_path)
129
141
# Copy the lib directory (using the list)
130
142
util.action_copylist(install_list.list_ivle_lib, python_site_packages, dry)
144
# Make the config file private
145
configpath = os.path.join(python_site_packages, 'ivle/conf/conf.py')
146
util.action_make_private(configpath, dry)
149
# Copy the subjects and exercises directories across
150
util.action_mkdir(subjects_base, dry)
151
util.action_copylist(install_list.list_subjects, subjects_base, dry,
153
util.action_mkdir(exercises_base, dry)
154
util.action_copylist(install_list.list_exercises, exercises_base, dry,
155
srcdir="./exercises")
157
# XXX We shouldn't have ivle.pth at all any more.
158
# We may still need the www packages to be importable.
159
# Anything from www that is needed from the outside should go to lib.
160
ivle_pth = os.path.join(python_site_packages, "ivle.pth")
162
file = open(ivle_pth, 'w')
163
file.write(os.path.join(share_path, "www"))
165
except (IOError, OSError):
132
168
if not nosvnrevno:
133
169
# Create the ivle working revision record file
134
170
ivle_revision_file = os.path.join(share_path, 'revision.txt')