forked from mysociety/mzalendo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
manage.py
executable file
·70 lines (57 loc) · 2.52 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python
import os
import sys
import yaml
from django.core.management.base import (
BaseCommand, CommandParser, CommandError
)
from pombola.config import config
# This manage.py file is a bit more complex than you might expect, for
# two reasons:
#
# 1. There are different settings modules for each country, but it's
# a pain to have to specify the one to use all the time. We'd
# like to use the settings module that corresponds to the
# COUNTRY_APP in conf/general.yml by default.
#
# 2. It's nice if "./manage.py test" works out-of-the-box, so work
# out if "test" is the subcommand and the user hasn't specified a
# settings module manually with --settings. If so, use the
# settings module for non-country-specific tests that we know has
# the right INSTALLED_APPS and tests are expected to pass
# with. This won't help confusion if someone uses
# "django-admin.py test" instead, but it's some help... (Note
# that if someone's set the DJANGO_SETTINGS_MODULE environment
# variable, this default won't be used either.)
def get_country():
return config.get('COUNTRY_APP', 'no_country')
def run_default_tests(command_line_args):
# This reproduces the logic used by execute_from_command_line to
# extra whether the subcommand is "test" and whether a settings
# module has been manually specified.
try:
subcommand = command_line_args[1]
except IndexError:
return False
parser = CommandParser(None, usage="%(prog)s subcommand [options] [args]", add_help=False)
parser.add_argument('--settings')
parser.add_argument('--pythonpath')
parser.add_argument('args', nargs='*')
try:
options, args = parser.parse_known_args(command_line_args[2:])
except CommandError:
# Ignore any errors, we just wanted to extract any settings option
# that might have been specified.
options = {'settings': None}
return subcommand == 'test' and not options.settings
if __name__ == "__main__":
if run_default_tests(sys.argv):
settings_module = 'pombola.settings.tests'
print "Warning: we recommend running tests with ./run-tests instead"
else:
# Make the default settings file one that corresponds to the
# country specified in general.yml
settings_module = "pombola.settings." + get_country()
os.environ.setdefault("DJANGO_SETTINGS_MODULE", settings_module)
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)