2019-03-22 17:50:16 +00:00
|
|
|
from . import env
|
2019-05-21 09:56:49 +00:00
|
|
|
from . import exceptions
|
2019-03-22 17:50:16 +00:00
|
|
|
from . import fmt
|
2019-05-29 09:14:06 +00:00
|
|
|
from . import plugins
|
2019-01-22 20:25:04 +00:00
|
|
|
|
2019-05-05 09:45:24 +00:00
|
|
|
|
2019-05-21 09:56:49 +00:00
|
|
|
class BaseRunner:
|
|
|
|
def __init__(self, root, config):
|
|
|
|
self.root = root
|
|
|
|
self.config = config
|
|
|
|
|
2019-06-05 13:43:51 +00:00
|
|
|
def run(self, service, *path):
|
|
|
|
command = env.render_file(self.config, *path).strip()
|
2019-05-21 09:56:49 +00:00
|
|
|
self.exec(service, command)
|
|
|
|
|
|
|
|
def exec(self, service, command):
|
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
def check_service_is_activated(self, service):
|
|
|
|
if not self.is_activated(service):
|
|
|
|
raise exceptions.TutorError(
|
|
|
|
"This command may only be executed on the server where the {} is running".format(
|
|
|
|
service
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
def is_activated(self, service):
|
|
|
|
return self.config["ACTIVATE_" + service.upper()]
|
|
|
|
|
2019-06-05 13:43:51 +00:00
|
|
|
def iter_plugin_scripts(self, script):
|
|
|
|
yield from plugins.iter_scripts(self.config, script)
|
|
|
|
|
2019-05-21 09:56:49 +00:00
|
|
|
|
|
|
|
def migrate(runner):
|
2019-05-11 22:10:14 +00:00
|
|
|
fmt.echo_info("Creating all databases...")
|
2019-06-05 13:43:51 +00:00
|
|
|
runner.run("mysql-client", "scripts", "mysql-client", "init")
|
2019-05-29 09:14:06 +00:00
|
|
|
for service in ["lms", "cms", "forum", "notes", "xqueue"]:
|
|
|
|
if runner.is_activated(service):
|
|
|
|
fmt.echo_info("Running {} migrations...".format(service))
|
2019-06-05 13:43:51 +00:00
|
|
|
runner.run(service, "scripts", service, "init")
|
|
|
|
for plugin_name, service in runner.iter_plugin_scripts("init"):
|
2019-05-29 09:14:06 +00:00
|
|
|
fmt.echo_info(
|
|
|
|
"Plugin {}: running init for service {}...".format(plugin_name, service)
|
|
|
|
)
|
2019-06-05 13:43:51 +00:00
|
|
|
runner.run(service, plugin_name, "scripts", service, "init")
|
2019-05-11 22:10:14 +00:00
|
|
|
fmt.echo_info("Databases ready.")
|
2019-01-22 20:25:04 +00:00
|
|
|
|
2019-05-05 09:45:24 +00:00
|
|
|
|
2019-06-05 13:43:51 +00:00
|
|
|
def create_user(runner, superuser, staff, username, email):
|
2019-05-21 09:56:49 +00:00
|
|
|
runner.check_service_is_activated("lms")
|
2019-06-05 13:43:51 +00:00
|
|
|
opts = ""
|
2019-03-22 17:50:16 +00:00
|
|
|
if superuser:
|
2019-06-05 13:43:51 +00:00
|
|
|
opts += " --superuser"
|
2019-03-22 17:50:16 +00:00
|
|
|
if staff:
|
2019-06-05 13:43:51 +00:00
|
|
|
opts += " --staff"
|
|
|
|
command = (
|
|
|
|
"./manage.py lms --settings=tutor.production manage_user {opts} {username} {email}\n"
|
|
|
|
"./manage.py lms --settings=tutor.production changepassword {username}"
|
|
|
|
).format(opts=opts, username=username, email=email)
|
|
|
|
runner.exec("lms", command)
|
2019-01-22 20:25:04 +00:00
|
|
|
|
2019-05-05 09:45:24 +00:00
|
|
|
|
2019-05-21 09:56:49 +00:00
|
|
|
def import_demo_course(runner):
|
|
|
|
runner.check_service_is_activated("cms")
|
2019-05-29 09:14:06 +00:00
|
|
|
runner.run("cms", "importdemocourse")
|
2019-05-11 19:20:09 +00:00
|
|
|
|
|
|
|
|
2019-05-21 09:56:49 +00:00
|
|
|
def index_courses(runner):
|
|
|
|
runner.check_service_is_activated("cms")
|
2019-05-29 09:14:06 +00:00
|
|
|
runner.run("cms", "indexcourses")
|