forked from trampgeek/moodle-qtype_coderunner
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall
More file actions
executable file
·53 lines (42 loc) · 2.01 KB
/
install
File metadata and controls
executable file
·53 lines (42 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env python
# This is the "normal" install for code cloned from github. It copies all
# the question type and behaviour files into the appropriate subdirectory of
# either /www/html/moodle or /www/moodle, whichever is found first.
from __future__ import print_function
import os
import shutil
def printFailMessage():
print("Install failed. Either fix the cause of the failure (preferred) or manually copy")
print("the question type and behaviour subdirectories (recursively) as follows:")
print(" '../behaviour/adaptive_adapted_for_coderunner/' should be copied to '<moodlehome>/question/behaviour'")
print(" '../type/coderunner/' should be copied to '<moodlehome>/question/type'")
def main():
cwd = os.getcwd()
if os.path.exists('/var/www/html/moodle/question'):
target = '/var/www/html/moodle/question'
elif os.path.exists('/var/www/moodle/question'):
target = '/var/www/moodle/question'
else:
raise Exception('<moodlehome> not found in either of the expected places')
try:
if os.path.exists('.gitignore'):
ignores = [os.path.join(cwd, f.strip()) for f in open('.gitignore').readlines()]
else:
ignores = []
def ignore_fun(dir, names):
return [name for name in names if os.path.join(dir, name) in ignores]
for dir in ['behaviour/adaptive_adapted_for_coderunner', 'type/coderunner']:
srctree = os.path.join(cwd, dir)
destree = os.path.join(target, dir)
if os.path.islink(destree): # Symbolic link?
print("Deleting symbolic link {}".format(destree))
os.unlink(destree)
elif os.path.isdir(destree):
print("Removing existing directory {}".format(destree))
shutil.rmtree(destree, True)
shutil.copytree(srctree, destree, ignore=ignore_fun)
print("Install complete.")
except Exception as e:
print("Install exception: " + str(e))
printFailMessage()
main()