-
Notifications
You must be signed in to change notification settings - Fork 7
/
manage.py
executable file
·52 lines (43 loc) · 1.75 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
#!/usr/bin/env python
# -*- coding: utf-8; indent-tabs-mode: nil; python-indent: 2 -*-
#
# Copyright (C) 2013-2019 Thibauld Nion
#
# This file is part of WaterOnMars (https://github.com/tibonihoo/wateronmars)
#
# WaterOnMars is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# WaterOnMars is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with WaterOnMars. If not, see <http://www.gnu.org/licenses/>.
#
import os
import sys
def quickloaddata(dumpfile):
"""Shortcut to init the django apps even when not everything is
working yet and load data from a json dump.
"""
import django
django.setup()
print(f"Starting loaddata from {dumpfile}")
from django.db import transaction
from django.core.management import call_command
with transaction.atomic():
call_command('loaddata', dumpfile, exclude=["contenttypes", "auth.permission"])
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "wateronmars.settings")
if "test" in sys.argv[1:]:
# Make sure we're not in demo mode for the tests
from django.conf import settings
settings.DEMO=False
elif "quickloaddata" in sys.argv[1:]:
quickloaddata(sys.argv[2])
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)