diff --git a/bin/main b/bin/main index f1eaaad..99da9fb 100755 --- a/bin/main +++ b/bin/main @@ -1,4 +1,4 @@ #!/usr/bin/env python3 -from tutor.cli import main +from tutor.commands.cli import main main() diff --git a/setup.py b/setup.py index faa93fe..c2c7c23 100644 --- a/setup.py +++ b/setup.py @@ -39,7 +39,7 @@ setup( ], entry_points={ 'console_scripts': [ - 'tutor=tutor.cli:main', + 'tutor=tutor.commands.cli:main', ], }, classifiers=[ diff --git a/tests/test_scripts.py b/tests/test_scripts.py index 6cf0954..32cf647 100644 --- a/tests/test_scripts.py +++ b/tests/test_scripts.py @@ -1,7 +1,7 @@ import unittest import unittest.mock -from tutor.config import load_defaults +from tutor.commands.config import load_defaults from tutor import env from tutor import scripts @@ -9,8 +9,8 @@ from tutor import scripts class ScriptsTests(unittest.TestCase): def test_run_script(self): config = {} - load_defaults({}) - rendered_script = env.render_file("scripts", "create_databases.sh") + load_defaults(config) + rendered_script = env.render_file(config, "scripts", "create_databases.sh") with unittest.mock.Mock() as run_func: scripts.run_script( "/tmp", config, "someservice", "create_databases.sh", run_func diff --git a/tutor/commands/__init__.py b/tutor/commands/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tutor/android.py b/tutor/commands/android.py similarity index 94% rename from tutor/android.py rename to tutor/commands/android.py index b14ac22..ebe5279 100644 --- a/tutor/android.py +++ b/tutor/commands/android.py @@ -1,10 +1,10 @@ import click from . import config as tutor_config -from . import env as tutor_env -from . import fmt -from . import opts -from . import utils +from .. import env as tutor_env +from .. import fmt +from .. import opts +from .. import utils @click.group(help="Build an Android app for your Open edX platform [BETA FEATURE]") diff --git a/tutor/cli.py b/tutor/commands/cli.py similarity index 93% rename from tutor/cli.py rename to tutor/commands/cli.py index cdec097..8eb52ff 100755 --- a/tutor/cli.py +++ b/tutor/commands/cli.py @@ -4,7 +4,6 @@ import sys import click import click_repl -from .__about__ import __version__ from .android import android from .config import config_command from .dev import dev @@ -13,8 +12,9 @@ from .k8s import k8s from .local import local from .ui import ui from .webui import webui -from . import exceptions -from . import fmt +from ..__about__ import __version__ +from .. import exceptions +from .. import fmt def main(): diff --git a/tutor/config.py b/tutor/commands/config.py similarity index 98% rename from tutor/config.py rename to tutor/commands/config.py index 6b52a6e..15694b2 100644 --- a/tutor/config.py +++ b/tutor/commands/config.py @@ -4,13 +4,13 @@ import sys import click -from . import exceptions -from . import env -from . import fmt -from . import opts -from . import serialize -from . import utils -from .__about__ import __version__ +from .. import exceptions +from .. import env +from .. import fmt +from .. import opts +from .. import serialize +from .. import utils +from ..__about__ import __version__ @click.group( diff --git a/tutor/dev.py b/tutor/commands/dev.py similarity index 97% rename from tutor/dev.py rename to tutor/commands/dev.py index b2609f8..46e4315 100644 --- a/tutor/dev.py +++ b/tutor/commands/dev.py @@ -2,9 +2,9 @@ import subprocess import click -from . import env as tutor_env -from . import opts -from . import utils +from .. import env as tutor_env +from .. import opts +from .. import utils @click.group(help="Run Open edX platform with development settings") diff --git a/tutor/images.py b/tutor/commands/images.py similarity index 97% rename from tutor/images.py rename to tutor/commands/images.py index 4c2c511..43a91ba 100644 --- a/tutor/images.py +++ b/tutor/commands/images.py @@ -1,10 +1,10 @@ import click from . import config as tutor_config -from . import env as tutor_env -from . import fmt -from . import opts -from . import utils +from .. import env as tutor_env +from .. import fmt +from .. import opts +from .. import utils @click.group(short_help="Manage docker images") diff --git a/tutor/k8s.py b/tutor/commands/k8s.py similarity index 96% rename from tutor/k8s.py rename to tutor/commands/k8s.py index 6ed7826..870f015 100644 --- a/tutor/k8s.py +++ b/tutor/commands/k8s.py @@ -1,12 +1,12 @@ import click from . import config as tutor_config -from . import env as tutor_env -from . import exceptions -from . import fmt -from . import opts -from . import scripts -from . import utils +from .. import env as tutor_env +from .. import exceptions +from .. import fmt +from .. import opts +from .. import scripts +from .. import utils @click.group(help="Run Open edX on Kubernetes [BETA FEATURE]") @@ -99,7 +99,8 @@ def delete(yes): @click.command(help="Create databases and run database migrations") @opts.root def databases(root): - scripts.migrate(root, run_sh) + config = tutor_config.load(root) + scripts.migrate(root, config, run_sh) @click.command(help="Create an Open edX user and interactively set their password") diff --git a/tutor/local.py b/tutor/commands/local.py similarity index 97% rename from tutor/local.py rename to tutor/commands/local.py index a2fe485..e04bea1 100644 --- a/tutor/local.py +++ b/tutor/commands/local.py @@ -3,12 +3,12 @@ from textwrap import indent import click from . import config as tutor_config -from . import env as tutor_env -from . import exceptions -from . import fmt -from . import opts -from . import scripts -from . import utils +from .. import env as tutor_env +from .. import exceptions +from .. import fmt +from .. import opts +from .. import scripts +from .. import utils @click.group( @@ -145,7 +145,8 @@ def execute(root, service, command, args): @click.command(help="Create databases and run database migrations") @opts.root def databases(root): - scripts.migrate(root, run_sh) + config = tutor_config.load(root) + scripts.migrate(root, config, run_sh) @click.group(help="Manage https certificates") diff --git a/tutor/ui.py b/tutor/commands/ui.py similarity index 100% rename from tutor/ui.py rename to tutor/commands/ui.py diff --git a/tutor/webui.py b/tutor/commands/webui.py similarity index 97% rename from tutor/webui.py rename to tutor/commands/webui.py index 288b884..fc78010 100644 --- a/tutor/webui.py +++ b/tutor/commands/webui.py @@ -10,10 +10,10 @@ import click # Note: it is important that this module does not depend on config, such that # the web ui can be launched even where there is no configuration. -from . import fmt -from . import opts -from . import env as tutor_env -from . import serialize +from .. import fmt +from .. import opts +from .. import env as tutor_env +from .. import serialize @click.group( diff --git a/tutor/env.py b/tutor/env.py index 7b862b2..006e084 100644 --- a/tutor/env.py +++ b/tutor/env.py @@ -72,11 +72,12 @@ def ensure_file_directory_exists(path): os.makedirs(directory) -def render_file(config, path): +def render_file(config, *path): """ Return the rendered contents of a template. + TODO refactor this and move it to Renderer """ - with codecs.open(path, encoding="utf-8") as fi: + with codecs.open(template_path(*path), encoding="utf-8") as fi: try: return render_str(config, fi.read()) except jinja2.exceptions.UndefinedError: diff --git a/tutor/scripts.py b/tutor/scripts.py index 0a79a6c..f2c3b05 100644 --- a/tutor/scripts.py +++ b/tutor/scripts.py @@ -1,13 +1,10 @@ import click -from . import config as tutor_config from . import env from . import fmt -def migrate(root, run_func): - config = tutor_config.load(root) - +def migrate(root, config, run_func): click.echo(fmt.info("Creating all databases...")) run_script(root, config, "mysql-client", "create_databases.sh", run_func) @@ -50,6 +47,10 @@ def index_courses(root, run_func): def run_script(root, config, service, template, run_func): - command = env.render_file(config, "script", template).strip() + command = render_template(config, template) if command: run_func(root, service, command) + + +def render_template(config, template): + return env.render_file(config, "scripts", template).strip()