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
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
from tutor.cli import main
|
from tutor.commands.cli import main
|
||||||
main()
|
main()
|
||||||
|
2
setup.py
2
setup.py
@ -39,7 +39,7 @@ setup(
|
|||||||
],
|
],
|
||||||
entry_points={
|
entry_points={
|
||||||
'console_scripts': [
|
'console_scripts': [
|
||||||
'tutor=tutor.cli:main',
|
'tutor=tutor.commands.cli:main',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
classifiers=[
|
classifiers=[
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import unittest
|
import unittest
|
||||||
import unittest.mock
|
import unittest.mock
|
||||||
|
|
||||||
from tutor.config import load_defaults
|
from tutor.commands.config import load_defaults
|
||||||
from tutor import env
|
from tutor import env
|
||||||
from tutor import scripts
|
from tutor import scripts
|
||||||
|
|
||||||
@ -9,8 +9,8 @@ from tutor import scripts
|
|||||||
class ScriptsTests(unittest.TestCase):
|
class ScriptsTests(unittest.TestCase):
|
||||||
def test_run_script(self):
|
def test_run_script(self):
|
||||||
config = {}
|
config = {}
|
||||||
load_defaults({})
|
load_defaults(config)
|
||||||
rendered_script = env.render_file("scripts", "create_databases.sh")
|
rendered_script = env.render_file(config, "scripts", "create_databases.sh")
|
||||||
with unittest.mock.Mock() as run_func:
|
with unittest.mock.Mock() as run_func:
|
||||||
scripts.run_script(
|
scripts.run_script(
|
||||||
"/tmp", config, "someservice", "create_databases.sh", run_func
|
"/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
|
import click
|
||||||
|
|
||||||
from . import config as tutor_config
|
from . import config as tutor_config
|
||||||
from . import env as tutor_env
|
from .. import env as tutor_env
|
||||||
from . import fmt
|
from .. import fmt
|
||||||
from . import opts
|
from .. import opts
|
||||||
from . import utils
|
from .. import utils
|
||||||
|
|
||||||
|
|
||||||
@click.group(help="Build an Android app for your Open edX platform [BETA FEATURE]")
|
@click.group(help="Build an Android app for your Open edX platform [BETA FEATURE]")
|
@ -4,7 +4,6 @@ import sys
|
|||||||
import click
|
import click
|
||||||
import click_repl
|
import click_repl
|
||||||
|
|
||||||
from .__about__ import __version__
|
|
||||||
from .android import android
|
from .android import android
|
||||||
from .config import config_command
|
from .config import config_command
|
||||||
from .dev import dev
|
from .dev import dev
|
||||||
@ -13,8 +12,9 @@ from .k8s import k8s
|
|||||||
from .local import local
|
from .local import local
|
||||||
from .ui import ui
|
from .ui import ui
|
||||||
from .webui import webui
|
from .webui import webui
|
||||||
from . import exceptions
|
from ..__about__ import __version__
|
||||||
from . import fmt
|
from .. import exceptions
|
||||||
|
from .. import fmt
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
@ -4,13 +4,13 @@ import sys
|
|||||||
|
|
||||||
import click
|
import click
|
||||||
|
|
||||||
from . import exceptions
|
from .. import exceptions
|
||||||
from . import env
|
from .. import env
|
||||||
from . import fmt
|
from .. import fmt
|
||||||
from . import opts
|
from .. import opts
|
||||||
from . import serialize
|
from .. import serialize
|
||||||
from . import utils
|
from .. import utils
|
||||||
from .__about__ import __version__
|
from ..__about__ import __version__
|
||||||
|
|
||||||
|
|
||||||
@click.group(
|
@click.group(
|
@ -2,9 +2,9 @@ import subprocess
|
|||||||
|
|
||||||
import click
|
import click
|
||||||
|
|
||||||
from . import env as tutor_env
|
from .. import env as tutor_env
|
||||||
from . import opts
|
from .. import opts
|
||||||
from . import utils
|
from .. import utils
|
||||||
|
|
||||||
|
|
||||||
@click.group(help="Run Open edX platform with development settings")
|
@click.group(help="Run Open edX platform with development settings")
|
@ -1,10 +1,10 @@
|
|||||||
import click
|
import click
|
||||||
|
|
||||||
from . import config as tutor_config
|
from . import config as tutor_config
|
||||||
from . import env as tutor_env
|
from .. import env as tutor_env
|
||||||
from . import fmt
|
from .. import fmt
|
||||||
from . import opts
|
from .. import opts
|
||||||
from . import utils
|
from .. import utils
|
||||||
|
|
||||||
|
|
||||||
@click.group(short_help="Manage docker images")
|
@click.group(short_help="Manage docker images")
|
@ -1,12 +1,12 @@
|
|||||||
import click
|
import click
|
||||||
|
|
||||||
from . import config as tutor_config
|
from . import config as tutor_config
|
||||||
from . import env as tutor_env
|
from .. import env as tutor_env
|
||||||
from . import exceptions
|
from .. import exceptions
|
||||||
from . import fmt
|
from .. import fmt
|
||||||
from . import opts
|
from .. import opts
|
||||||
from . import scripts
|
from .. import scripts
|
||||||
from . import utils
|
from .. import utils
|
||||||
|
|
||||||
|
|
||||||
@click.group(help="Run Open edX on Kubernetes [BETA FEATURE]")
|
@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")
|
@click.command(help="Create databases and run database migrations")
|
||||||
@opts.root
|
@opts.root
|
||||||
def databases(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")
|
@click.command(help="Create an Open edX user and interactively set their password")
|
@ -3,12 +3,12 @@ from textwrap import indent
|
|||||||
import click
|
import click
|
||||||
|
|
||||||
from . import config as tutor_config
|
from . import config as tutor_config
|
||||||
from . import env as tutor_env
|
from .. import env as tutor_env
|
||||||
from . import exceptions
|
from .. import exceptions
|
||||||
from . import fmt
|
from .. import fmt
|
||||||
from . import opts
|
from .. import opts
|
||||||
from . import scripts
|
from .. import scripts
|
||||||
from . import utils
|
from .. import utils
|
||||||
|
|
||||||
|
|
||||||
@click.group(
|
@click.group(
|
||||||
@ -145,7 +145,8 @@ def execute(root, service, command, args):
|
|||||||
@click.command(help="Create databases and run database migrations")
|
@click.command(help="Create databases and run database migrations")
|
||||||
@opts.root
|
@opts.root
|
||||||
def databases(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")
|
@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
|
# 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.
|
# the web ui can be launched even where there is no configuration.
|
||||||
from . import fmt
|
from .. import fmt
|
||||||
from . import opts
|
from .. import opts
|
||||||
from . import env as tutor_env
|
from .. import env as tutor_env
|
||||||
from . import serialize
|
from .. import serialize
|
||||||
|
|
||||||
|
|
||||||
@click.group(
|
@click.group(
|
@ -72,11 +72,12 @@ def ensure_file_directory_exists(path):
|
|||||||
os.makedirs(directory)
|
os.makedirs(directory)
|
||||||
|
|
||||||
|
|
||||||
def render_file(config, path):
|
def render_file(config, *path):
|
||||||
"""
|
"""
|
||||||
Return the rendered contents of a template.
|
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:
|
try:
|
||||||
return render_str(config, fi.read())
|
return render_str(config, fi.read())
|
||||||
except jinja2.exceptions.UndefinedError:
|
except jinja2.exceptions.UndefinedError:
|
||||||
|
@ -1,13 +1,10 @@
|
|||||||
import click
|
import click
|
||||||
|
|
||||||
from . import config as tutor_config
|
|
||||||
from . import env
|
from . import env
|
||||||
from . import fmt
|
from . import fmt
|
||||||
|
|
||||||
|
|
||||||
def migrate(root, run_func):
|
def migrate(root, config, run_func):
|
||||||
config = tutor_config.load(root)
|
|
||||||
|
|
||||||
click.echo(fmt.info("Creating all databases..."))
|
click.echo(fmt.info("Creating all databases..."))
|
||||||
run_script(root, config, "mysql-client", "create_databases.sh", run_func)
|
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):
|
def run_script(root, config, service, template, run_func):
|
||||||
command = env.render_file(config, "script", template).strip()
|
command = render_template(config, template)
|
||||||
if command:
|
if command:
|
||||||
run_func(root, service, 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