forked from trampgeek/moodle-qtype_coderunner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdevinstall
executable file
·54 lines (47 loc) · 2.36 KB
/
devinstall
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
54
#!/usr/bin/env python
# This "installer" is not a true installer. It simply sets up symbolic links
# to the 2 subdirectories, i.e. for the question/type and question/behaviour
# directories. It is intended for use by developers because
# it results in changes to the source code being immediately "live", because
# the live code is symbolically linked to the developer code.
# It needs to be run only on the initial cloning of the repository.
from __future__ import print_function
import os
import shutil
import subprocess
def printFailMessage():
print("This script failed to set up the necessary symbolic links.")
print("You will need to manually make the following symbolic links to ")
print("directories in this module:")
print("<moodlehome>/question/type/coderunner -> coderunner")
print("<moodlehome>/question/behaviour/adaptive_adapted_for_coderunner -> adaptive_adapted_for_coderunner")
def main():
cwd = os.getcwd()
if "moodle/local/CodeRunner" not in cwd:
print("WARNING: CodeRunner appears not to have been cloned into moodle/local")
print ("as recommended.")
printFailMessage()
else:
try:
searchString = "/moodle/local/CodeRunner"
pos = cwd.index(searchString)
basedir = cwd[0:pos]
installdir = cwd[0:pos + len(searchString)]
dirs = [("type/coderunner", "moodle/question/type/coderunner"),
("behaviour/adaptive_adapted_for_coderunner", "moodle/question/behaviour/adaptive_adapted_for_coderunner")]
for (src,dest) in dirs:
newdir = "{0}/{1}".format(basedir, dest)
if os.path.islink(newdir): # Symbolic link?
print("Deleting symbolic link {}".format(newdir))
os.unlink(newdir)
elif os.path.isdir(newdir):
print("Removing existing directory {}".format(newdir))
shutil.rmtree(newdir)
print("Creating new symbolic link {}".format(newdir))
if subprocess.call("ln -s {0}/{1} {2}".format(installdir, src, newdir), shell=True) != 0:
raise OSError("Failed to create symbolic link")
print("Install complete.")
except Exception as e:
print("Exception when making symbolic links: " + str(e))
printFailMessage()
main()