Skip to content

Commit

Permalink
feat: add do sqlshell command
Browse files Browse the repository at this point in the history
An optional `--db=openedx` argument can be passed to the job command.

This should close
openedx-unsupported/wg-developer-experience#51
  • Loading branch information
regisb committed Apr 26, 2023
1 parent 6257c1c commit 19016b8
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 20 deletions.
1 change: 1 addition & 0 deletions changelog.d/20230326_102311_regis_moar_tasks.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
- [Feature] Make it possible to import the demo course from a different git repository or version. (by @regisb)
- [Feature] Add a convenient `do print-edx-platform-setting` command to print the value of an edx-platform setting. (by @regisb)
- [Improvement] Improve edx-platform logging by silencing a couple deprecation warnings. (by @regisb)
- [Feature] Add a convenient `do sqlshell` command to enter a SQL shell as root. (by @regisb)
54 changes: 35 additions & 19 deletions tutor/commands/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from typing_extensions import ParamSpec

from tutor import config as tutor_config
from tutor import env, fmt, hooks
from tutor import env, fmt, hooks, utils
from tutor.hooks import priorities


Expand Down Expand Up @@ -165,6 +165,26 @@ def importdemocourse(
yield ("cms", template)


@click.command(
name="print-edx-platform-setting",
help="Print the value of an edx-platform Django setting.",
)
@click.argument("setting")
@click.option(
"-s",
"--service",
type=click.Choice(["lms", "cms"]),
default="lms",
show_default=True,
help="Service to fetch the setting from",
)
def print_edx_platform_setting(
setting: str, service: str
) -> t.Iterable[tuple[str, str]]:
command = f"./manage.py {service} shell -c 'from django.conf import settings; print(settings.{setting})'"
yield (service, command)


@click.command()
@click.option(
"-d",
Expand Down Expand Up @@ -222,24 +242,19 @@ def assign_theme(name, domain):
return f'./manage.py lms shell -c "{python_command}"'


@click.command(
name="print-edx-platform-setting",
help="Print the value of an edx-platform Django setting.",
)
@click.argument("setting")
@click.option(
"-s",
"--service",
type=click.Choice(["lms", "cms"]),
default="lms",
show_default=True,
help="Service to fetch the setting from",
)
def print_edx_platform_setting(
setting: str, service: str
) -> t.Iterable[tuple[str, str]]:
command = f"./manage.py {service} shell -c 'from django.conf import settings; print(settings.{setting})'"
yield (service, command)
@click.command(context_settings={"ignore_unknown_options": True})
@click.argument("args", nargs=-1)
def sqlshell(args: list[str]) -> t.Iterable[tuple[str, str]]:
"""
Open an SQL shell as root
Extra arguments will be passed to the `mysql` command verbatim. For instance, to
show tables from the "openedx" database, run `do sqlshell openedx -e 'show tables'`.
"""
command = "mysql --user={{ MYSQL_ROOT_USERNAME }} --password={{ MYSQL_ROOT_PASSWORD }} --host={{ MYSQL_HOST }} --port={{ MYSQL_PORT }}"
if args:
command += " " + utils._shlex_join(*args) # pylint: disable=protected-access
yield ("lms", command)


def add_job_commands(do_command_group: click.Group) -> None:
Expand Down Expand Up @@ -322,5 +337,6 @@ def do_callback(service_commands: t.Iterable[tuple[str, str]]) -> None:
initialise,
print_edx_platform_setting,
settheme,
sqlshell,
]
)
2 changes: 1 addition & 1 deletion tutor/templates/build/openedx/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ FROM minimal as production

# Install system requirements
RUN apt update && \
apt install -y gettext gfortran graphviz graphviz-dev libffi-dev libfreetype6-dev libgeos-dev libjpeg8-dev liblapack-dev libmysqlclient-dev libpng-dev libsqlite3-dev libxmlsec1-dev lynx ntp pkg-config rdfind && \
apt install -y gettext gfortran graphviz graphviz-dev libffi-dev libfreetype6-dev libgeos-dev libjpeg8-dev liblapack-dev libmysqlclient-dev libpng-dev libsqlite3-dev libxmlsec1-dev lynx mysql-client ntp pkg-config rdfind && \
rm -rf /var/lib/apt/lists/*

# From then on, run as unprivileged "app" user
Expand Down

0 comments on commit 19016b8

Please sign in to comment.