mirror of
https://github.com/ChristianLight/tutor.git
synced 2024-12-13 06:37:46 +00:00
Move command modules to dedicated directory
This commit is contained in:
parent
09d7b49628
commit
754da2f06f
2
bin/main
2
bin/main
@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
from tutor.cli import main
|
||||
from tutor.commands.cli import main
|
||||
main()
|
||||
|
2
setup.py
2
setup.py
@ -39,7 +39,7 @@ setup(
|
||||
],
|
||||
entry_points={
|
||||
'console_scripts': [
|
||||
'tutor=tutor.cli:main',
|
||||
'tutor=tutor.commands.cli:main',
|
||||
],
|
||||
},
|
||||
classifiers=[
|
||||
|
@ -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
|
||||
|
0
tutor/commands/__init__.py
Normal file
0
tutor/commands/__init__.py
Normal file
@ -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]")
|
@ -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():
|
@ -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(
|
@ -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")
|
@ -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")
|
@ -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")
|
@ -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")
|
@ -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(
|
@ -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:
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user