Skip to content

Commit

Permalink
Introduce logged_call_command
Browse files Browse the repository at this point in the history
  • Loading branch information
hansegucker committed Nov 27, 2023
1 parent 26b9bba commit 8838e81
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 26 deletions.
5 changes: 3 additions & 2 deletions evap/development/management/commands/dump_testdata.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import os

from django.conf import settings
from django.core.management import call_command
from django.core.management.base import BaseCommand

from evap.evaluation.management.commands.tools import logged_call_command


class Command(BaseCommand):
args = ""
Expand All @@ -12,7 +13,7 @@ class Command(BaseCommand):

def handle(self, *args, **options):
outfile_name = os.path.join(settings.BASE_DIR, "development", "fixtures", "test_data.json")
call_command(
logged_call_command(
"dumpdata",
"auth.group",
"evaluation",
Expand Down
21 changes: 7 additions & 14 deletions evap/development/management/commands/reload_testdata.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from django.core.management import call_command
from django.core.management.base import BaseCommand

from evap.evaluation.management.commands.tools import confirm_harmful_operation
from evap.evaluation.management.commands.tools import confirm_harmful_operation, logged_call_command


class Command(BaseCommand):
Expand All @@ -14,24 +13,18 @@ def handle(self, *args, **options):
if not confirm_harmful_operation(self.stdout):
return

self.stdout.write('Executing "python manage.py reset_db"')
call_command("reset_db", interactive=False)
logged_call_command(self.stdout, "reset_db", interactive=False)

self.stdout.write('Executing "python manage.py migrate"')
call_command("migrate")
logged_call_command(self.stdout, "migrate")

# clear any data the migrations created.
# their pks might differ from the ones in the dump, which results in errors on loaddata
self.stdout.write('Executing "python manage.py flush"')
call_command("flush", interactive=False)
logged_call_command(self.stdout, "flush", interactive=False)

self.stdout.write('Executing "python manage.py loaddata test_data"')
call_command("loaddata", "test_data")
logged_call_command(self.stdout, "loaddata", "test_data")

self.stdout.write('Executing "python manage.py clear_cache --all -v=1"')
call_command("clear_cache", "--all", "-v=1")
logged_call_command(self.stdout, "clear_cache", "--all", "-v=1")

self.stdout.write('Executing "python manage.py refresh_results_cache"')
call_command("refresh_results_cache")
logged_call_command(self.stdout, "refresh_results_cache")

self.stdout.write("Done.")
13 changes: 5 additions & 8 deletions evap/development/management/commands/translate.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
from django.core.management import call_command
from django.core.management.base import BaseCommand

from evap.evaluation.management.commands.tools import logged_call_command


class Command(BaseCommand):
args = ""
help = 'Execute "makemessages --locale=de --ignore=node_modules/*"'

def handle(self, *args, **options):
self.stdout.write('Executing "manage.py makemessages --locale=de --ignore=node_modules/*"')
call_command("makemessages", "--locale=de", "--ignore=node_modules/*")
self.stdout.write(
'Executing ""makemessages --domain=djangojs --extension=js,ts "'
'"--locale=de --ignore=node_modules/* --ignore=evap/static/js/*.min.js",'
)
call_command(
logged_call_command(self.stdout, "makemessages", "--locale=de", "--ignore=node_modules/*")
logged_call_command(
self.stdout,
"makemessages",
"--domain=djangojs",
"--extension=js,ts",
Expand Down
7 changes: 7 additions & 0 deletions evap/evaluation/management/commands/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import sys

from django.conf import settings
from django.core.management import call_command

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -40,3 +41,9 @@ def handle(self, *args, **options):
raise

return NewClass


def logged_call_command(stdout, *args, **kwargs):
"""Log execution of management command with all args."""
stdout.write("Executing python manage.py " + " ".join(list(args) + [f"{a}={b}" for a, b in kwargs.items()]))
call_command(*args, **kwargs)
2 changes: 0 additions & 2 deletions evap/static/js/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# ignore the typescript output, but still track the libraries
*.js
!*.min.js
!sortable_form.js
!moment_de.js

0 comments on commit 8838e81

Please sign in to comment.