weblate/weblate/runner.py
Michal Čihař e41f5c71d3 chore: move management helpers out of __init__.py
It is better to collect these in a standalone module.
2026-01-09 20:46:54 +01:00

30 lines
804 B
Python

# Copyright © Michal Čihař <michal@weblate.org>
#
# SPDX-License-Identifier: GPL-3.0-or-later
import os
import sys
from contextlib import suppress
def main(argv=None, developer_mode: bool = False) -> None:
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "weblate.settings")
from weblate.utils.management.utility import WeblateManagementUtility
if argv is None:
argv = sys.argv
try:
# This is essentially Django's execute_from_command_line
utility = WeblateManagementUtility(argv=argv, developer_mode=developer_mode)
utility.execute()
except Exception:
with suppress(ImportError):
from weblate.utils.errors import report_error
report_error("Command failed")
raise
if __name__ == "__main__":
main()