Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@
import sys
from argparse import ArgumentParser

from openedx_filters import OpenEdxPublicFilter


class ManagementCommandExecutionRequested(OpenEdxPublicFilter):
"""Filter triggered before a management command is executed."""

FILTER_TYPE = 'org.openedx.platform.management.command.execute.requested.v1'


def parse_args():
"""Parse edx specific arguments to manage.py"""
Expand Down Expand Up @@ -96,4 +104,22 @@ def parse_args():
django_args.append('--help')

from django.core.management import execute_from_command_line
execute_from_command_line([sys.argv[0]] + django_args)

def command_runner():
return execute_from_command_line([sys.argv[0]] + django_args)

command_name = 'help'
if django_args and not django_args[0].startswith('-'):
command_name = django_args[0]

try:
pipeline_output = ManagementCommandExecutionRequested.run_filter(
command_name=command_name,
service_variant=os.environ.get("SERVICE_VARIANT", edx_args.service_variant),
command_runner=command_runner,
)
runner = pipeline_output.get('command_runner', command_runner)
except Exception: # pylint: disable=broad-except
runner = command_runner

runner()
Loading