2021-11-12 16:49:35 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
"""Django's command-line utility for administrative tasks."""
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
2022-04-22 17:07:32 +00:00
|
|
|
|
2021-11-12 16:49:35 +00:00
|
|
|
def activate_venv(base):
|
|
|
|
if os.path.exists(base):
|
|
|
|
old_os_path = os.environ.get('PATH', '')
|
|
|
|
os.environ['PATH'] = os.path.join(base, 'bin') + os.pathsep + old_os_path
|
2022-04-22 17:07:32 +00:00
|
|
|
version = '%s.%s' % (sys.version_info.major, sys.version_info.minor)
|
|
|
|
site_packages = os.path.join(base, 'lib', 'python%s' % version, 'site-packages')
|
2021-11-12 16:49:35 +00:00
|
|
|
prev_sys_path = list(sys.path)
|
|
|
|
import site
|
|
|
|
site.addsitedir(site_packages)
|
|
|
|
sys.real_prefix = sys.prefix
|
|
|
|
sys.prefix = base
|
|
|
|
# Move the added items to the front of the path:
|
|
|
|
new_sys_path = []
|
|
|
|
for item in list(sys.path):
|
|
|
|
if item not in prev_sys_path:
|
|
|
|
new_sys_path.append(item)
|
|
|
|
sys.path.remove(item)
|
|
|
|
sys.path[:0] = new_sys_path
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
"""Run administrative tasks."""
|
|
|
|
root_dir = os.path.normpath(os.path.abspath(os.path.dirname(__file__)))
|
|
|
|
activate_venv(os.path.normpath(os.path.join(root_dir, 'venv')))
|
|
|
|
|
|
|
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'app.settings')
|
|
|
|
try:
|
|
|
|
from django.core.management import execute_from_command_line
|
|
|
|
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__':
|
|
|
|
main()
|