2019-03-22 17:50:16 +00:00
|
|
|
import click
|
2019-01-22 20:25:04 +00:00
|
|
|
|
2019-03-22 17:50:16 +00:00
|
|
|
from . import config as tutor_config
|
|
|
|
from . import env
|
|
|
|
from . import fmt
|
2019-01-22 20:25:04 +00:00
|
|
|
|
2019-03-22 17:50:16 +00:00
|
|
|
def migrate(root, run_func):
|
|
|
|
config = tutor_config.load(root)
|
2019-03-22 19:15:50 +00:00
|
|
|
|
|
|
|
click.echo(fmt.info("Creating all databases..."))
|
2019-04-28 06:26:45 +00:00
|
|
|
# Note: run this only when lms is activated?
|
|
|
|
run_template(root, config, "lms", "create_databases.sh", run_func)
|
2019-03-22 19:15:50 +00:00
|
|
|
|
|
|
|
if config["ACTIVATE_LMS"]:
|
|
|
|
click.echo(fmt.info("Running lms migrations..."))
|
|
|
|
run_template(root, config, "lms", "migrate_lms.sh", run_func)
|
|
|
|
if config["ACTIVATE_CMS"]:
|
|
|
|
click.echo(fmt.info("Running cms migrations..."))
|
|
|
|
run_template(root, config, "cms", "migrate_cms.sh", run_func)
|
|
|
|
if config["ACTIVATE_FORUM"]:
|
|
|
|
click.echo(fmt.info("Running forum migrations..."))
|
|
|
|
run_template(root, config, "forum", "migrate_forum.sh", run_func)
|
2019-03-22 17:50:16 +00:00
|
|
|
if config["ACTIVATE_NOTES"]:
|
|
|
|
click.echo(fmt.info("Running notes migrations..."))
|
|
|
|
run_template(root, config, "notes", "migrate_django.sh", run_func)
|
|
|
|
if config["ACTIVATE_XQUEUE"]:
|
|
|
|
click.echo(fmt.info("Running xqueue migrations..."))
|
|
|
|
run_template(root, config, "xqueue", "migrate_django.sh", run_func)
|
2019-03-22 19:15:50 +00:00
|
|
|
if config["ACTIVATE_LMS"]:
|
|
|
|
click.echo(fmt.info("Creating oauth2 users..."))
|
|
|
|
run_template(root, config, "lms", "oauth2.sh", run_func)
|
2019-03-22 17:50:16 +00:00
|
|
|
click.echo(fmt.info("Databases ready."))
|
2019-01-22 20:25:04 +00:00
|
|
|
|
2019-03-22 17:50:16 +00:00
|
|
|
def create_user(root, run_func, superuser, staff, name, email):
|
|
|
|
config = {
|
|
|
|
"OPTS": "",
|
|
|
|
"USERNAME": name,
|
|
|
|
"EMAIL": email,
|
|
|
|
}
|
|
|
|
if superuser:
|
|
|
|
config["OPTS"] += " --superuser"
|
|
|
|
if staff:
|
|
|
|
config["OPTS"] += " --staff"
|
|
|
|
run_template(root, config, "lms", "create_user.sh", run_func)
|
2019-01-22 20:25:04 +00:00
|
|
|
|
2019-03-22 17:50:16 +00:00
|
|
|
def import_demo_course(root, run_func):
|
|
|
|
run_template(root, {}, "cms", "import_demo_course.sh", run_func)
|
2019-02-20 15:07:18 +00:00
|
|
|
|
2019-03-22 17:50:16 +00:00
|
|
|
def index_courses(root, run_func):
|
|
|
|
run_template(root, {}, "cms", "index_courses.sh", run_func)
|
2019-01-22 20:25:04 +00:00
|
|
|
|
2019-03-22 17:50:16 +00:00
|
|
|
def run_template(root, config, service, template, run_func):
|
|
|
|
command = render_template(config, template)
|
|
|
|
if command:
|
|
|
|
run_func(root, service, command)
|
2019-01-22 20:25:04 +00:00
|
|
|
|
2019-03-22 17:50:16 +00:00
|
|
|
def render_template(config, template):
|
|
|
|
path = env.template_path("scripts", template)
|
|
|
|
return env.render_file(config, path).strip()
|