-
Notifications
You must be signed in to change notification settings - Fork 46
/
manage.py
executable file
·55 lines (42 loc) · 1.49 KB
/
manage.py
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
51
52
53
54
55
#!/usr/bin/env python3
# Copyright (C) 2016-2018 Linaro Limited
#
# Author: Neil Williams <[email protected]>
# Remi Duraffort <[email protected]>
#
# SPDX-License-Identifier: GPL-2.0-or-later
import argparse
import os
import sys
from django.core.management import execute_from_command_line
def find_sources():
base_path = os.path.dirname(os.path.abspath(__file__))
if os.path.exists(os.path.join(base_path, "lava_server")):
sys.path.insert(0, base_path)
def main():
# Is the script called from an installed packages or from a source install?
installed = not sys.argv[0].endswith("manage.py")
# Create the command line parser
parser = argparse.ArgumentParser()
manage = parser
if installed:
subparser = parser.add_subparsers(dest="subcommand", help="Manage LAVA")
subparser.required = True
manage = subparser.add_parser("manage")
manage.add_argument(
"command", nargs="...", help="Invoke this Django management command"
)
# Parse the command line
options = parser.parse_args()
# Choose the right Django settings
if installed:
settings = "lava_server.settings.prod"
else:
# Add the root dir to the python path
find_sources()
settings = "lava_server.settings.dev"
os.environ["DJANGO_SETTINGS_MODULE"] = settings
# Create and run the Django command line
execute_from_command_line([sys.argv[0]] + options.command)
if __name__ == "__main__":
main()