Coverage for app/venv/lib/python3.14/site-packages/weblate/utils/management/__init__.py: 71%
19 statements
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-07 07:15 +0000
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-07 07:15 +0000
1# Copyright © Michal Čihař <michal@weblate.org>
2#
3# SPDX-License-Identifier: GPL-3.0-or-later
5import sys
7from django.core.management import ManagementUtility
9RESTRICTED_COMMANDS = {"squashmigrations", "makemigrations"}
12class WeblateManagementUtility(ManagementUtility):
13 def __init__(self, argv=None, developer_mode: bool = False) -> None:
14 super().__init__(argv)
15 self.developer_mode = developer_mode
17 def fetch_command(self, subcommand):
18 # Block usage of some commands
19 if not self.developer_mode and subcommand in RESTRICTED_COMMANDS: 19 ↛ 20line 19 didn't jump to line 20 because the condition on line 19 was never true
20 sys.stderr.write(f"Blocked command: {subcommand!r}\n")
21 sys.stderr.write("This command is restricted for developers only.\n")
22 sys.stderr.write(
23 "In case you really want to do this, please execute "
24 "using manage.py from the Weblate source code.\n"
25 )
26 sys.exit(1)
28 # Fetch command class
29 command = super().fetch_command(subcommand)
31 # Monkey patch it's output
32 original_notice = command.style.NOTICE
34 def patched_notice(txt):
35 return original_notice(
36 txt.replace("python manage.py migrate", "weblate migrate")
37 )
39 command.style.NOTICE = patched_notice # type: ignore[method-assign]
41 return command