-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmanage.py
More file actions
executable file
·50 lines (42 loc) · 1.84 KB
/
Copy pathmanage.py
File metadata and controls
executable file
·50 lines (42 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys
from pathlib import Path
from dotenv import load_dotenv
from helpers.logging import redirect_std_to_logger
def main():
"""Run administrative tasks."""
# if we have .env.local file we are very likely on a development machine, therefore load it
# to have the correct environment when using manage.py commands.
env_file = '.env.local'
if Path(env_file).is_file():
print(f'WARNING: Load {env_file} environment')
load_dotenv(env_file, override=True, verbose=True)
# use separate settings.py for tests
if 'test' in sys.argv:
os.environ.setdefault('LOGGING_CFG', 'app/config/logging-cfg-unittest.yml')
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings_test')
elif 'runserver' not in sys.argv:
# uses another logging configuration for management command (except for runserver)
os.environ.setdefault('LOGGING_CFG', 'app/config/logging-cfg-management.yml')
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')
else:
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')
try:
from django.core.management import \
execute_from_command_line # pylint: disable=import-outside-toplevel
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
if __name__ == '__main__':
if '--redirect-std-to-logger' in sys.argv:
sys.argv.remove('--redirect-std-to-logger')
with redirect_std_to_logger(__name__):
main()
else:
main()