Sith/core/management/commands/setup.py

47 lines
1.3 KiB
Python
Raw Normal View History

# -*- coding:utf-8 -*
#
# Copyright 2023 © AE UTBM
# ae@utbm.fr / ae.info@utbm.fr
#
# This file is part of the website of the UTBM Student Association (AE UTBM),
# https://ae.utbm.fr.
#
# You can find the source code of the website at https://github.com/ae-utbm/sith3
#
# LICENSED UNDER THE GNU GENERAL PUBLIC LICENSE VERSION 3 (GPLv3)
# SEE : https://raw.githubusercontent.com/ae-utbm/sith3/master/LICENSE
# OR WITHIN THE LOCAL FILE "LICENSE"
#
#
2015-12-04 15:13:20 +00:00
import os
2017-06-12 07:42:03 +00:00
from django.core.management.base import BaseCommand
2015-12-03 17:00:08 +00:00
from django.core.management import call_command
2016-01-28 15:53:37 +00:00
2015-12-03 17:00:08 +00:00
class Command(BaseCommand):
help = "Set up a new instance of the Sith AE"
2015-12-04 15:13:20 +00:00
def add_arguments(self, parser):
2018-10-04 19:29:19 +00:00
parser.add_argument("--prod", action="store_true")
2015-12-04 15:13:20 +00:00
2015-12-03 17:00:08 +00:00
def handle(self, *args, **options):
2018-10-04 19:29:19 +00:00
root_path = os.path.dirname(
os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
)
2015-12-03 17:00:08 +00:00
try:
2018-10-04 19:29:19 +00:00
os.mkdir(os.path.join(root_path) + "/data")
print("Data dir created")
2016-01-28 15:53:37 +00:00
except Exception as e:
repr(e)
try:
2018-10-04 19:29:19 +00:00
os.remove(os.path.join(root_path, "db.sqlite3"))
print("db.sqlite3 deleted")
except Exception as e:
repr(e)
2018-10-04 19:29:19 +00:00
call_command("migrate")
if options["prod"]:
call_command("populate", "--prod")
2016-03-22 08:01:24 +00:00
else:
2018-10-04 19:29:19 +00:00
call_command("populate")